summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-10-03 10:56:40 -0400
committerGitHub <noreply@github.com>2018-10-03 10:56:40 -0400
commitb99c0941f2738202b40c76ef89e6ab418ff45c8c (patch)
treecb003358da16c536bd2746a816f29b54d62f6648 /tests
parentfadb8d3d005f36d9945a4680f799bbdf730da67b (diff)
parent7e2497d1a97f8bfc3ac969e488b5f9263f26c878 (diff)
downloadcmd2-git-b99c0941f2738202b40c76ef89e6ab418ff45c8c.tar.gz
Merge pull request #560 from python-cmd2/py_enhancements
Py enhancements
Diffstat (limited to 'tests')
-rw-r--r--tests/test_cmd2.py32
-rw-r--r--tests/test_parsing.py32
2 files changed, 32 insertions, 32 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index ed281024..a64f21e4 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -1866,22 +1866,6 @@ def test_alias_create(base_app, capsys):
out = run_cmd(base_app, 'alias list fake')
assert out == normalize('alias create fake pyscript')
-def test_alias_quoted_name(base_app, capsys):
- """Demonstrate that names can be quoted in alias commands because they will be stripped"""
- # Create the alias
- out = run_cmd(base_app, 'alias create "fake" pyscript')
-
- # The quotes on names are stripped
- assert out == normalize("Alias 'fake' created")
-
- # Look up the new alias and quote the name
- out = run_cmd(base_app, 'alias list "fake"')
- assert out == normalize('alias create fake pyscript')
-
- # Delete the alias using quotes
- out = run_cmd(base_app, 'alias delete "fake"')
- assert out == normalize("Alias 'fake' deleted")
-
def test_alias_create_with_quoted_value(base_app, capsys):
"""Demonstrate that quotes in alias value will be preserved (except for redirectors)"""
@@ -1968,22 +1952,6 @@ def test_macro_create(base_app, capsys):
out = run_cmd(base_app, 'macro list fake')
assert out == normalize('macro create fake pyscript')
-def test_macro_create_quoted_name(base_app, capsys):
- """Demonstrate that names can be quoted in macro commands because they will be stripped"""
- # Create the macro
- out = run_cmd(base_app, 'macro create "fake" pyscript')
-
- # The quotes on names are stripped
- assert out == normalize("Macro 'fake' created")
-
- # Look up the new macro and quote the name
- out = run_cmd(base_app, 'macro list "fake"')
- assert out == normalize('macro create fake pyscript')
-
- # Delete the macro using quotes
- out = run_cmd(base_app, 'macro delete "fake"')
- assert out == normalize("Macro 'fake' deleted")
-
def test_macro_create_with_quoted_value(base_app, capsys):
"""Demonstrate that quotes in macro value will be preserved (except for redirectors)"""
# Create the macro
diff --git a/tests/test_parsing.py b/tests/test_parsing.py
index 1fa460a5..ba72edd6 100644
--- a/tests/test_parsing.py
+++ b/tests/test_parsing.py
@@ -756,6 +756,38 @@ def test_statement_is_immutable():
statement.raw = 'baz'
+def test_is_valid_command_invalid(parser):
+ # Empty command
+ valid, errmsg = parser.is_valid_command('')
+ assert not valid and 'cannot be an empty string' in errmsg
+
+ # Starts with shortcut
+ valid, errmsg = parser.is_valid_command('!ls')
+ assert not valid and 'cannot start with a shortcut' in errmsg
+
+ # Contains whitespace
+ valid, errmsg = parser.is_valid_command('shell ls')
+ assert not valid and 'cannot contain: whitespace, quotes,' in errmsg
+
+ # Contains a quote
+ valid, errmsg = parser.is_valid_command('"shell"')
+ assert not valid and 'cannot contain: whitespace, quotes,' in errmsg
+
+ # Contains a redirector
+ valid, errmsg = parser.is_valid_command('>shell')
+ assert not valid and 'cannot contain: whitespace, quotes,' in errmsg
+
+ # Contains a terminator
+ valid, errmsg = parser.is_valid_command(';shell')
+ assert not valid and 'cannot contain: whitespace, quotes,' in errmsg
+
+def test_is_valid_command_valid(parser):
+ # Empty command
+ valid, errmsg = parser.is_valid_command('shell')
+ assert valid
+ assert not errmsg
+
+
def test_macro_normal_arg_pattern():
# This pattern matches digits surrounded by exactly 1 brace on a side and 1 or more braces on the opposite side
from cmd2.parsing import MacroArg