summaryrefslogtreecommitdiff
path: root/tests/test_run_pyscript.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-12-17 22:51:55 -0500
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-12-17 22:51:55 -0500
commitd91943f4ddbfcc47b35f26883e1068d5693c0f03 (patch)
tree958a330c77958dd99775516ab95d5a8890f88353 /tests/test_run_pyscript.py
parent60d236fdd331304b9d516f080c9a36c08c4baa9e (diff)
downloadcmd2-git-d91943f4ddbfcc47b35f26883e1068d5693c0f03.tar.gz
Updating unit tests
Diffstat (limited to 'tests/test_run_pyscript.py')
-rw-r--r--tests/test_run_pyscript.py27
1 files changed, 9 insertions, 18 deletions
diff --git a/tests/test_run_pyscript.py b/tests/test_run_pyscript.py
index a4ff097f..d717758c 100644
--- a/tests/test_run_pyscript.py
+++ b/tests/test_run_pyscript.py
@@ -6,8 +6,10 @@ Unit/functional testing for run_pytest in cmd2
import builtins
import os
+import pytest
+
from cmd2 import plugin, utils
-from .conftest import run_cmd
+from .conftest import run_cmd, odd_file_names
# Python 3.5 had some regressions in the unitest.mock module, so use 3rd party mock if available
try:
@@ -52,30 +54,19 @@ 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]
-def test_run_pyscript_with_odd_file_names(base_app):
+@pytest.mark.parametrize('python_script', odd_file_names)
+def test_run_pyscript_with_odd_file_names(base_app, python_script):
"""
Pass in file names with various patterns. Since these files don't exist, we will rely
on the error text to make sure the file names were processed correctly.
"""
- python_script = utils.quote_string('nothingweird.py')
- out, err = run_cmd(base_app, "run_pyscript {}".format(python_script))
- assert "Error reading script file 'nothingweird.py'" in err[0]
-
- python_script = utils.quote_string('has spaces.py')
- out, err = run_cmd(base_app, "run_pyscript {}".format(python_script))
- assert "Error reading script file 'has spaces.py'" in err[0]
-
- # For remaining tests, mock input to get us passed the warning about not ending in .py
+ # Mock input to get us passed the warning about not ending in .py
input_mock = mock.MagicMock(name='input', return_value='1')
builtins.input = input_mock
- python_script = utils.quote_string('"is_double_quoted.py"')
- out, err = run_cmd(base_app, "run_pyscript {}".format(python_script))
- assert "Error reading script file '\"is_double_quoted.py\"'" in err[1]
-
- python_script = utils.quote_string("'is_single_quoted.py'")
- out, err = run_cmd(base_app, "run_pyscript {}".format(python_script))
- assert "Error reading script file ''is_single_quoted.py''" in err[1]
+ out, err = run_cmd(base_app, "run_pyscript {}".format(utils.quote_string(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__)