diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-24 13:18:57 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-24 13:18:57 -0400 |
commit | b20bd6b3d14c20b5da669c919b5d19d728ba11ef (patch) | |
tree | 1c358741f4e2fa579e1a0df149798f09ee4a224c | |
parent | 3bc87c3e7de1891431e3a4463164816b96eb64b1 (diff) | |
download | cmd2-git-b20bd6b3d14c20b5da669c919b5d19d728ba11ef.tar.gz |
Updated unit tests
-rw-r--r-- | tests/test_cmd2.py | 13 | ||||
-rw-r--r-- | tests/test_run_pyscript.py | 12 |
2 files changed, 14 insertions, 11 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index f0ccbfe1..16c5eed4 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -429,31 +429,30 @@ def test_relative_run_script(base_app, request): def test_relative_run_script_with_odd_file_names(base_app, monkeypatch): """Test file names with various patterns""" - # Mock out the do_run_script call to see what args are passed + # Mock out the do_run_script call to see what args are passed to it run_script_mock = mock.MagicMock(name='do_run_script') monkeypatch.setattr("cmd2.Cmd.do_run_script", run_script_mock) file_name = utils.quote_string('nothingweird.txt') - out, err = run_cmd(base_app, "run_script {}".format(file_name)) + out, err = run_cmd(base_app, "_relative_run_script {}".format(file_name)) run_script_mock.assert_called_once_with('"nothingweird.txt"') run_script_mock.reset_mock() file_name = utils.quote_string('has spaces.txt') - out, err = run_cmd(base_app, "run_script {}".format(file_name)) + out, err = run_cmd(base_app, "_relative_run_script {}".format(file_name)) run_script_mock.assert_called_once_with('"has spaces.txt"') run_script_mock.reset_mock() file_name = utils.quote_string('"is_double_quoted.txt"') - out, err = run_cmd(base_app, "run_script {}".format(file_name)) + out, err = run_cmd(base_app, "_relative_run_script {}".format(file_name)) run_script_mock.assert_called_once_with('\'"is_double_quoted.txt"\'') run_script_mock.reset_mock() file_name = utils.quote_string("'is_single_quoted.txt'") - out, err = run_cmd(base_app, "run_script {}".format(file_name)) + out, err = run_cmd(base_app, "_relative_run_script {}".format(file_name)) run_script_mock.assert_called_once_with('"\'is_single_quoted.txt\'"') run_script_mock.reset_mock() - def test_relative_run_script_requires_an_argument(base_app): out, err = run_cmd(base_app, '_relative_run_script') assert 'Error: the following arguments' in err[1] @@ -685,7 +684,7 @@ def test_edit_file(base_app, request, monkeypatch): def test_edit_file_with_odd_file_names(base_app, monkeypatch): """Test editor and file names with various patterns""" - # Mock out the do_shell call to see what args are passed + # Mock out the do_shell call to see what args are passed to it shell_mock = mock.MagicMock(name='do_shell') monkeypatch.setattr("cmd2.Cmd.do_shell", shell_mock) diff --git a/tests/test_run_pyscript.py b/tests/test_run_pyscript.py index 60a6798e..4c30d888 100644 --- a/tests/test_run_pyscript.py +++ b/tests/test_run_pyscript.py @@ -59,19 +59,23 @@ def test_run_pyscript_with_odd_file_names(base_app): """ python_script = utils.quote_string('nothingweird.py') out, err = run_cmd(base_app, "run_pyscript {}".format(python_script)) - assert "'nothingweird.py'" in err[0] + assert "No such file or directory: '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 "'has spaces.py'" in err[0] + assert "No such file or directory: 'has spaces.py'" in err[0] + + # For remaining tests, 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 "'\"is_double_quoted.py\"'" in err[0] + assert "No such file or directory: '\"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 "''is_single_quoted.py''" in err[0] + assert 'No such file or directory: "\'is_single_quoted.py\'"' in err[1] def test_run_pyscript_with_exception(base_app, request): test_dir = os.path.dirname(request.module.__file__) |