diff options
author | xNinjaKittyx <xNinjaKittyx@users.noreply.github.com> | 2020-12-15 17:21:33 -0800 |
---|---|---|
committer | xNinjaKittyx <xNinjaKittyx@users.noreply.github.com> | 2020-12-15 18:20:13 -0800 |
commit | 9aa54a5b27468d61337528cb1e1b5b9b11a80978 (patch) | |
tree | 567693115cc101efb9254a96d96d80e9f9ccd557 /tests/test_run_pyscript.py | |
parent | 03c65c60b39e369958b056c5c844d36d515c8a63 (diff) | |
download | cmd2-git-ci_improvements.tar.gz |
Adds pre-commit config to run various lintersci_improvements
This ads black, isort, pyupgrade, and flake8 to pre-commit-config.yaml
There are also some small changes to travis.yml and tasks.py to reduce
some repeated configurations that should be consolidated into
setup.cfg. Most other changes are automated by the linter scripts.
Diffstat (limited to 'tests/test_run_pyscript.py')
-rw-r--r-- | tests/test_run_pyscript.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/tests/test_run_pyscript.py b/tests/test_run_pyscript.py index 8cfd8578..e0b2b3c5 100644 --- a/tests/test_run_pyscript.py +++ b/tests/test_run_pyscript.py @@ -20,11 +20,13 @@ except ImportError: HOOK_OUTPUT = "TEST_OUTPUT" + def cmdfinalization_hook(data: plugin.CommandFinalizationData) -> plugin.CommandFinalizationData: """A cmdfinalization_hook hook which requests application exit""" print(HOOK_OUTPUT) return data + def test_run_pyscript(base_app, request): test_dir = os.path.dirname(request.module.__file__) python_script = os.path.join(test_dir, 'script.py') @@ -33,6 +35,7 @@ def test_run_pyscript(base_app, request): 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, 'pyscript', 'recursive.py') @@ -41,11 +44,13 @@ def test_run_pyscript_recursive_not_allowed(base_app, request): 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 reading script file" in err[0] + def test_run_pyscript_with_non_python_file(base_app, request): m = mock.MagicMock(name='input', return_value='2') builtins.input = m @@ -55,6 +60,7 @@ def test_run_pyscript_with_non_python_file(base_app, request): out, err = run_cmd(base_app, 'run_pyscript {}'.format(filename)) assert "does not have a .py extension" in err[0] + @pytest.mark.parametrize('python_script', odd_file_names) def test_run_pyscript_with_odd_file_names(base_app, python_script): """ @@ -69,6 +75,7 @@ def test_run_pyscript_with_odd_file_names(base_app, python_script): err = ''.join(err) assert "Error reading script file '{}'".format(python_script) in err + def test_run_pyscript_with_exception(base_app, request): test_dir = os.path.dirname(request.module.__file__) python_script = os.path.join(test_dir, 'pyscript', 'raises_exception.py') @@ -76,10 +83,12 @@ def test_run_pyscript_with_exception(base_app, request): 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') @@ -87,6 +96,7 @@ 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') @@ -94,6 +104,7 @@ def test_run_pyscript_dir(base_app, request): out, err = run_cmd(base_app, 'run_pyscript {}'.format(python_script)) 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__) @@ -103,6 +114,7 @@ def test_run_pyscript_stdout_capture(base_app, request): assert out[0] == "PASSED" assert out[1] == "PASSED" + def test_run_pyscript_stop(base_app, request): # Verify onecmd_plus_hooks() returns True if any commands in a pyscript return True for stop test_dir = os.path.dirname(request.module.__file__) @@ -117,6 +129,7 @@ def test_run_pyscript_stop(base_app, request): stop = base_app.onecmd_plus_hooks('run_pyscript {}'.format(python_script)) assert stop + def test_run_pyscript_environment(base_app, request): test_dir = os.path.dirname(request.module.__file__) python_script = os.path.join(test_dir, 'pyscript', 'environment.py') @@ -124,7 +137,8 @@ def test_run_pyscript_environment(base_app, request): assert out[0] == "PASSED" -def test_run_pyscript_app_echo(base_app, request): + +def test_run_pyscript_app_echo(base_app, request): test_dir = os.path.dirname(request.module.__file__) python_script = os.path.join(test_dir, 'pyscript', 'echo.py') out, err = run_cmd(base_app, 'run_pyscript {}'.format(python_script)) |