diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-06-15 01:16:39 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-06-15 01:16:39 -0400 |
commit | b3df078bdb3d0472487cfce4185f922eb7f1843b (patch) | |
tree | a86a03b064838916c74bd479b4f3849d8d532838 /tests/test_run_pyscript.py | |
parent | 451f449c7356df00c8d30750355a536b30997608 (diff) | |
download | cmd2-git-b3df078bdb3d0472487cfce4185f922eb7f1843b.tar.gz |
Updated unit tests
Diffstat (limited to 'tests/test_run_pyscript.py')
-rw-r--r-- | tests/test_run_pyscript.py | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/tests/test_run_pyscript.py b/tests/test_run_pyscript.py index bbe9e17d..088d9aab 100644 --- a/tests/test_run_pyscript.py +++ b/tests/test_run_pyscript.py @@ -15,6 +15,38 @@ def cmdfinalization_hook(data: plugin.CommandFinalizationData) -> plugin.Command print(HOOK_OUTPUT) return data +def test_run_pyscript_base(base_app, 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 ...' + + out, err = run_cmd(base_app, "run_pyscript {}".format(python_script)) + assert expected in out + +def test_run_pyscript_recursive_not_allowed(base_app, request): + test_dir = os.path.dirname(request.module.__file__) + python_script = os.path.join(test_dir, 'scripts', 'recursive.py') + expected = 'Recursively entering interactive Python consoles is not allowed.' + + out, err = run_cmd(base_app, "run_pyscript {}".format(python_script)) + assert err[0] == expected + +def test_run_pyscript_with_nonexist_file(base_app): + python_script = 'does_not_exist.py' + out, err = run_cmd(base_app, "run_pyscript {}".format(python_script)) + assert "Error opening script file" in err[0] + +def test_run_pyscript_with_exception(base_app, request): + test_dir = os.path.dirname(request.module.__file__) + python_script = os.path.join(test_dir, 'scripts', 'raises_exception.py') + out, err = run_cmd(base_app, "run_pyscript {}".format(python_script)) + assert err[0].startswith('Traceback') + assert "TypeError: unsupported operand type(s) for +: 'int' and 'str'" in err[-1] + +def test_run_pyscript_requires_an_argument(base_app): + out, err = run_cmd(base_app, "run_pyscript") + assert "the following arguments are required: script_path" in err[1] + def test_run_pyscript_help(base_app, request): test_dir = os.path.dirname(request.module.__file__) python_script = os.path.join(test_dir, 'pyscript', 'help.py') @@ -22,7 +54,6 @@ def test_run_pyscript_help(base_app, request): out2, err2 = run_cmd(base_app, 'run_pyscript {}'.format(python_script)) assert out1 and out1 == out2 - def test_run_pyscript_dir(base_app, request): test_dir = os.path.dirname(request.module.__file__) python_script = os.path.join(test_dir, 'pyscript', 'pyscript_dir.py') @@ -31,7 +62,6 @@ def test_run_pyscript_dir(base_app, request): assert out assert out[0] == "['cmd_echo']" - def test_run_pyscript_stdout_capture(base_app, request): base_app.register_cmdfinalization_hook(cmdfinalization_hook) test_dir = os.path.dirname(request.module.__file__) @@ -54,3 +84,13 @@ def test_run_pyscript_stop(base_app, request): python_script = os.path.join(test_dir, 'pyscript', 'stop.py') stop = base_app.onecmd_plus_hooks('run_pyscript {}'.format(python_script)) assert stop + +def test_pyscript_deprecated_but_works(base_app, 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 ...' + + out, err = run_cmd(base_app, "pyscript {}".format(python_script)) + assert expected in out + assert "pyscript has been renamed and will be removed" in err[0] + |