diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-24 12:25:40 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-24 12:25:40 -0400 |
commit | 3bc87c3e7de1891431e3a4463164816b96eb64b1 (patch) | |
tree | f10195a0e24cb40c2a35849857dc65b87e0ac07f /tests | |
parent | 35e084f64f715f90e2bfba232a299301b9c5d850 (diff) | |
download | cmd2-git-3bc87c3e7de1891431e3a4463164816b96eb64b1.tar.gz |
Added unit tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_cmd2.py | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index d9c971b5..f0ccbfe1 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -427,6 +427,33 @@ def test_relative_run_script(base_app, request): assert script_out == manual_out assert script_err == manual_err +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 + 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)) + 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)) + 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)) + 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)) + 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] @@ -663,26 +690,26 @@ def test_edit_file_with_odd_file_names(base_app, monkeypatch): monkeypatch.setattr("cmd2.Cmd.do_shell", shell_mock) base_app.editor = 'fooedit' - python_script = utils.quote_string('nothingweird.py') - out, err = run_cmd(base_app, "edit {}".format(python_script)) + file_name = utils.quote_string('nothingweird.py') + out, err = run_cmd(base_app, "edit {}".format(file_name)) shell_mock.assert_called_once_with('"fooedit" "nothingweird.py"') shell_mock.reset_mock() base_app.editor = 'foo edit' - python_script = utils.quote_string('has spaces.py') - out, err = run_cmd(base_app, "edit {}".format(python_script)) + file_name = utils.quote_string('has spaces.py') + out, err = run_cmd(base_app, "edit {}".format(file_name)) shell_mock.assert_called_once_with('"foo edit" "has spaces.py"') shell_mock.reset_mock() base_app.editor = '"fooedit"' - python_script = utils.quote_string('"is_double_quoted.py"') - out, err = run_cmd(base_app, "edit {}".format(python_script)) + file_name = utils.quote_string('"is_double_quoted.py"') + out, err = run_cmd(base_app, "edit {}".format(file_name)) shell_mock.assert_called_once_with('\'"fooedit"\' \'"is_double_quoted.py"\'') shell_mock.reset_mock() base_app.editor = "'fooedit'" - python_script = utils.quote_string("'is_single_quoted.py'") - out, err = run_cmd(base_app, "edit {}".format(python_script)) + file_name = utils.quote_string("'is_single_quoted.py'") + out, err = run_cmd(base_app, "edit {}".format(file_name)) shell_mock.assert_called_once_with('"\'fooedit\'" "\'is_single_quoted.py\'"') shell_mock.reset_mock() |