diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-24 12:09:24 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-24 12:09:24 -0400 |
commit | 35e084f64f715f90e2bfba232a299301b9c5d850 (patch) | |
tree | 68d40fccd78b2aa63d4aed60ef124ba43a90b45d /tests/test_cmd2.py | |
parent | f3325cb39e9e20aa24d07107ebf048029059b44f (diff) | |
download | cmd2-git-35e084f64f715f90e2bfba232a299301b9c5d850.tar.gz |
Added unit tests
Diffstat (limited to 'tests/test_cmd2.py')
-rw-r--r-- | tests/test_cmd2.py | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 1bd81c50..d9c971b5 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -656,6 +656,36 @@ def test_edit_file(base_app, request, monkeypatch): # We think we have an editor, so should expect a Popen call m.assert_called_once() +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 + shell_mock = mock.MagicMock(name='do_shell') + 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)) + 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)) + 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)) + 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)) + shell_mock.assert_called_once_with('"\'fooedit\'" "\'is_single_quoted.py\'"') + shell_mock.reset_mock() + def test_edit_file_with_spaces(base_app, request, monkeypatch): # Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock base_app.editor = 'fooedit' @@ -986,7 +1016,7 @@ class SelectApp(cmd2.Cmd): def do_procrastinate(self, arg): """Waste time in your manner of choice.""" # Pass in a list of tuples for selections - leisure_activity = self.select([('Netflix and chill', 'Netflix'), ('Porn', 'WebSurfing')], + leisure_activity = self.select([('Netflix and chill', 'Netflix'), ('YouTube', 'WebSurfing')], 'How would you like to procrastinate? ') result = 'Have fun procrasinating with {}!\n'.format(leisure_activity) self.stdout.write(result) @@ -1098,7 +1128,7 @@ def test_select_list_of_tuples(select_app): 1. Netflix 2. WebSurfing Have fun procrasinating with {}! -""".format('Porn')) +""".format('YouTube')) # Make sure our mock was called with the expected arguments m.assert_called_once_with('How would you like to procrastinate? ') |