summaryrefslogtreecommitdiff
path: root/tests/test_pyscript.py
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2018-05-23 20:59:26 -0600
committerkotfu <kotfu@kotfu.net>2018-05-23 20:59:26 -0600
commit1a70b90f375997751bc7df16b5e3f58c6194c71b (patch)
tree1abe43d088060e24bb889e3db19fc5a1a4a82562 /tests/test_pyscript.py
parentb1516f4b09518bb6d33abfeb14e1459ed03f34d8 (diff)
parent5d64ebee348aeffb02fc385f903c9af431e3721b (diff)
downloadcmd2-git-1a70b90f375997751bc7df16b5e3f58c6194c71b.tar.gz
Merge branch 'master' into speedup_import
# Conflicts: # cmd2/cmd2.py # tests/test_completion.py # tests/test_submenu.py
Diffstat (limited to 'tests/test_pyscript.py')
-rw-r--r--tests/test_pyscript.py36
1 files changed, 31 insertions, 5 deletions
diff --git a/tests/test_pyscript.py b/tests/test_pyscript.py
index 8d0cefd8..73c1a62a 100644
--- a/tests/test_pyscript.py
+++ b/tests/test_pyscript.py
@@ -101,7 +101,14 @@ class PyscriptExample(Cmd):
@with_argparser(bar_parser)
def do_bar(self, args):
- print('bar ' + str(args.__dict__))
+ out = 'bar '
+ arg_dict = args.__dict__
+ keys = list(arg_dict.keys())
+ keys.sort()
+ out += '{'
+ for key in keys:
+ out += "'{}':'{}'".format(key, arg_dict[key])
+ print(out)
@pytest.fixture
@@ -160,7 +167,7 @@ def test_pyscript_help(ps_app, capsys, request, command, pyscript_file):
('foo aaa bbb -ccc -t -n', 'foo1.py'),
('foo 11 22 33 44 -ccc -t -n', 'foo2.py'),
('foo 11 22 33 44 55 66 -ccc', 'foo3.py'),
- ('bar 11 22', 'bar1.py')
+ ('bar 11 22', 'bar1.py'),
])
def test_pyscript_out(ps_app, capsys, request, command, pyscript_file):
test_dir = os.path.dirname(request.module.__file__)
@@ -204,11 +211,30 @@ def test_pyscript_results(ps_app, capsys, request, pyscript_file, exp_out):
assert exp_out in expected
-def test_pyscript_custom_name(ps_echo, capsys):
+@pytest.mark.parametrize('expected, pyscript_file', [
+ ("['_relative_load', 'alias', 'bar', 'cmd_echo', 'edit', 'eof', 'eos', 'foo', 'help', 'history', 'load', 'media', 'py', 'pyscript', 'quit', 'set', 'shell', 'shortcuts', 'unalias']",
+ 'pyscript_dir1.py'),
+ ("['movies', 'shows']", 'pyscript_dir2.py')
+])
+def test_pyscript_dir(ps_app, capsys, request, expected, pyscript_file):
+ test_dir = os.path.dirname(request.module.__file__)
+ python_script = os.path.join(test_dir, 'pyscript', pyscript_file)
+
+ run_cmd(ps_app, 'pyscript {}'.format(python_script))
+ out, _ = capsys.readouterr()
+ out = out.strip()
+ assert len(out) > 0
+ assert out == expected
+
+
+def test_pyscript_custom_name(ps_echo, capsys, request):
message = 'blah!'
- run_cmd(ps_echo, 'py custom.echo("{}")'.format(message))
+
+ test_dir = os.path.dirname(request.module.__file__)
+ python_script = os.path.join(test_dir, 'pyscript', 'custom_echo.py')
+
+ run_cmd(ps_echo, 'pyscript {}'.format(python_script))
expected, _ = capsys.readouterr()
assert len(expected) > 0
expected = expected.splitlines()
assert message == expected[0]
-