Skip to content

Commit b20bd6b

Browse files
committed
Updated unit tests
1 parent 3bc87c3 commit b20bd6b

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

tests/test_cmd2.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -429,31 +429,30 @@ def test_relative_run_script(base_app, request):
429429

430430
def test_relative_run_script_with_odd_file_names(base_app, monkeypatch):
431431
"""Test file names with various patterns"""
432-
# Mock out the do_run_script call to see what args are passed
432+
# Mock out the do_run_script call to see what args are passed to it
433433
run_script_mock = mock.MagicMock(name='do_run_script')
434434
monkeypatch.setattr("cmd2.Cmd.do_run_script", run_script_mock)
435435

436436
file_name = utils.quote_string('nothingweird.txt')
437-
out, err = run_cmd(base_app, "run_script {}".format(file_name))
437+
out, err = run_cmd(base_app, "_relative_run_script {}".format(file_name))
438438
run_script_mock.assert_called_once_with('"nothingweird.txt"')
439439
run_script_mock.reset_mock()
440440

441441
file_name = utils.quote_string('has spaces.txt')
442-
out, err = run_cmd(base_app, "run_script {}".format(file_name))
442+
out, err = run_cmd(base_app, "_relative_run_script {}".format(file_name))
443443
run_script_mock.assert_called_once_with('"has spaces.txt"')
444444
run_script_mock.reset_mock()
445445

446446
file_name = utils.quote_string('"is_double_quoted.txt"')
447-
out, err = run_cmd(base_app, "run_script {}".format(file_name))
447+
out, err = run_cmd(base_app, "_relative_run_script {}".format(file_name))
448448
run_script_mock.assert_called_once_with('\'"is_double_quoted.txt"\'')
449449
run_script_mock.reset_mock()
450450

451451
file_name = utils.quote_string("'is_single_quoted.txt'")
452-
out, err = run_cmd(base_app, "run_script {}".format(file_name))
452+
out, err = run_cmd(base_app, "_relative_run_script {}".format(file_name))
453453
run_script_mock.assert_called_once_with('"\'is_single_quoted.txt\'"')
454454
run_script_mock.reset_mock()
455455

456-
457456
def test_relative_run_script_requires_an_argument(base_app):
458457
out, err = run_cmd(base_app, '_relative_run_script')
459458
assert 'Error: the following arguments' in err[1]
@@ -685,7 +684,7 @@ def test_edit_file(base_app, request, monkeypatch):
685684

686685
def test_edit_file_with_odd_file_names(base_app, monkeypatch):
687686
"""Test editor and file names with various patterns"""
688-
# Mock out the do_shell call to see what args are passed
687+
# Mock out the do_shell call to see what args are passed to it
689688
shell_mock = mock.MagicMock(name='do_shell')
690689
monkeypatch.setattr("cmd2.Cmd.do_shell", shell_mock)
691690

tests/test_run_pyscript.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,23 @@ def test_run_pyscript_with_odd_file_names(base_app):
5959
"""
6060
python_script = utils.quote_string('nothingweird.py')
6161
out, err = run_cmd(base_app, "run_pyscript {}".format(python_script))
62-
assert "'nothingweird.py'" in err[0]
62+
assert "No such file or directory: 'nothingweird.py'" in err[0]
6363

6464
python_script = utils.quote_string('has spaces.py')
6565
out, err = run_cmd(base_app, "run_pyscript {}".format(python_script))
66-
assert "'has spaces.py'" in err[0]
66+
assert "No such file or directory: 'has spaces.py'" in err[0]
67+
68+
# For remaining tests, mock input to get us passed the warning about not ending in .py
69+
input_mock = mock.MagicMock(name='input', return_value='1')
70+
builtins.input = input_mock
6771

6872
python_script = utils.quote_string('"is_double_quoted.py"')
6973
out, err = run_cmd(base_app, "run_pyscript {}".format(python_script))
70-
assert "'\"is_double_quoted.py\"'" in err[0]
74+
assert "No such file or directory: '\"is_double_quoted.py\"'" in err[1]
7175

7276
python_script = utils.quote_string("'is_single_quoted.py'")
7377
out, err = run_cmd(base_app, "run_pyscript {}".format(python_script))
74-
assert "''is_single_quoted.py''" in err[0]
78+
assert 'No such file or directory: "\'is_single_quoted.py\'"' in err[1]
7579

7680
def test_run_pyscript_with_exception(base_app, request):
7781
test_dir = os.path.dirname(request.module.__file__)

0 commit comments

Comments
 (0)