summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-06-15 01:16:39 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-06-15 01:16:39 -0400
commitb3df078bdb3d0472487cfce4185f922eb7f1843b (patch)
treea86a03b064838916c74bd479b4f3849d8d532838 /tests
parent451f449c7356df00c8d30750355a536b30997608 (diff)
downloadcmd2-git-b3df078bdb3d0472487cfce4185f922eb7f1843b.tar.gz
Updated unit tests
Diffstat (limited to 'tests')
-rw-r--r--tests/test_cmd2.py35
-rw-r--r--tests/test_run_pyscript.py44
2 files changed, 43 insertions, 36 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 174df200..acf9d610 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -244,7 +244,7 @@ def test_base_py(base_app):
@pytest.mark.skipif(sys.platform == 'win32',
reason="Unit test doesn't work on win32, but feature does")
-def test_base_run_python_script(base_app, request):
+def test_py_run_script(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 ...'
@@ -253,39 +253,6 @@ def test_base_run_python_script(base_app, request):
assert expected in out
-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 ...'
-
- out, err = run_cmd(base_app, "run_pyscript {}".format(python_script))
- assert expected in out
-
-def test_recursive_run_pyscript_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_base_error(base_app):
out, err = run_cmd(base_app, 'meow')
assert "is not a recognized command" in err[0]
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]
+