diff options
| author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-06-24 17:09:16 -0400 |
|---|---|---|
| committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-06-24 17:09:16 -0400 |
| commit | 97a4f49948db468a247f4dd9862440cddc5e3db2 (patch) | |
| tree | 7f5f4d4b7d9d62361538d10145dc8dbadd9af880 /tests | |
| parent | 11797774735febb1f6d5c7d4b8f3d798288dbd5e (diff) | |
| download | cmd2-git-97a4f49948db468a247f4dd9862440cddc5e3db2.tar.gz | |
Added pyscript unit test and attempt to fix a path completion test on Windows
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_cmd2.py | 12 | ||||
| -rw-r--r-- | tests/test_completion.py | 30 |
2 files changed, 41 insertions, 1 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 757ed418..c1d406f4 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -111,6 +111,18 @@ def test_base_run_python_script(base_app, capsys, request): assert out == expected +@pytest.mark.skipif(sys.platform == 'win32', + reason="Unit test doesn't work on win32, but feature does") +def test_base_run_pyscript(base_app, capsys, request): + test_dir = os.path.dirname(request.module.__file__) + python_script = os.path.join(test_dir, 'script.py') + expected = 'This is a python script running ...\n' + + run_cmd(base_app, "pyscript {}".format(python_script)) + out, err = capsys.readouterr() + assert out == expected + + def test_base_error(base_app): out = run_cmd(base_app, 'meow') assert out == ["*** Unknown syntax: meow"] diff --git a/tests/test_completion.py b/tests/test_completion.py index c5094bc4..74cc3d57 100644 --- a/tests/test_completion.py +++ b/tests/test_completion.py @@ -138,7 +138,7 @@ def test_path_completion_single_mid(cmd2_app, request): begidx = line.find(text) endidx = begidx + len(text) - assert cmd2_app.path_complete(text, line, begidx, endidx) == ['tests/'] + assert cmd2_app.path_complete(text, line, begidx, endidx) == ['tests' + os.path.sep] def test_path_completion_multiple(cmd2_app, request): test_dir = os.path.dirname(request.module.__file__) @@ -163,3 +163,31 @@ def test_path_completion_nomatch(cmd2_app, request): begidx = endidx - len(text) assert cmd2_app.path_complete(text, line, begidx, endidx) == [] + +def test_parseline_command_and_args(cmd2_app): + line = 'help history' + command, args, out_line = cmd2_app.parseline(line) + assert command == 'help' + assert args == 'history' + assert line == out_line + +def test_parseline_emptyline(cmd2_app): + line = '' + command, args, out_line = cmd2_app.parseline(line) + assert command == None + assert args == None + assert line == out_line + +def test_parseline_strips_line(cmd2_app): + line = ' help history ' + command, args, out_line = cmd2_app.parseline(line) + assert command == 'help' + assert args == 'history' + assert line.strip() == out_line + +def test_parseline_expands_shortcuts(cmd2_app): + line = '!cat foobar.txt' + command, args, out_line = cmd2_app.parseline(line) + assert command == 'shell' + assert args == 'cat foobar.txt' + assert line.replace('!', 'shell ') == out_line |
