Skip to content

Commit 201cde6

Browse files
committed
parametrize transcript tests
1 parent 046210e commit 201cde6

1 file changed

Lines changed: 8 additions & 56 deletions

File tree

tests/test_transcript.py

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -232,74 +232,26 @@ def test_commands_at_invocation():
232232
out = app.stdout.buffer
233233
assert out == expected
234234

235-
236-
def test_transcript_from_cmdloop(request, capsys):
237-
# Create a cmd2.Cmd() instance and make sure basic settings are like we want for test
238-
app = CmdLineApp()
239-
app.feedback_to_output = True
240-
241-
# Get location of the transcript
242-
test_dir = os.path.dirname(request.module.__file__)
243-
transcript_file = os.path.join(test_dir, 'transcripts/from_cmdloop.txt')
244-
245-
# Need to patch sys.argv so cmd2 doesn't think it was called with arguments equal to the py.test args
246-
testargs = ['prog', '-t', transcript_file]
247-
with mock.patch.object(sys, 'argv', testargs):
248-
# Run the command loop
249-
app.cmdloop()
250-
251-
# Check for the unittest "OK" condition for the 1 test which ran
252-
expected_start = ".\n----------------------------------------------------------------------\nRan 1 test in"
253-
expected_end = "s\n\nOK\n"
254-
out, err = capsys.readouterr()
255-
if six.PY3:
256-
assert err.startswith(expected_start)
257-
assert err.endswith(expected_end)
258-
else:
259-
assert err == ''
260-
assert out == ''
261-
262-
263-
def test_multiline_command_transcript_with_comments_at_beginning(request, capsys):
264-
# Create a cmd2.Cmd() instance and make sure basic settings are like we want for test
265-
app = CmdLineApp()
266-
267-
# Get location of the transcript
268-
test_dir = os.path.dirname(request.module.__file__)
269-
transcript_file = os.path.join(test_dir, 'transcripts/multiline.txt')
270-
271-
# Need to patch sys.argv so cmd2 doesn't think it was called with arguments equal to the py.test args
272-
testargs = ['prog', '-t', transcript_file]
273-
with mock.patch.object(sys, 'argv', testargs):
274-
# Run the command loop
275-
app.cmdloop()
276-
277-
# Check for the unittest "OK" condition for the 1 test which ran
278-
expected_start = ".\n----------------------------------------------------------------------\nRan 1 test in"
279-
expected_end = "s\n\nOK\n"
280-
out, err = capsys.readouterr()
281-
if six.PY3:
282-
assert err.startswith(expected_start)
283-
assert err.endswith(expected_end)
284-
else:
285-
assert err == ''
286-
assert out == ''
287-
288-
289235
def test_invalid_syntax(_cmdline_app, capsys):
290236
run_cmd(_cmdline_app, 'speak "')
291237
out, err = capsys.readouterr()
292238
expected = normalize("""ERROR: Invalid syntax: No closing quotation""")
293239
assert normalize(str(err)) == expected
294240

295241

296-
def test_transcript_with_regex_set(request, capsys):
242+
@pytest.mark.parametrize('filename, feedback_to_output', [
243+
('regex_set.txt', False),
244+
('multiline.txt', False),
245+
('from_cmdloop.txt', True),
246+
])
247+
def test_transcript(request, capsys, filename, feedback_to_output):
297248
# Create a cmd2.Cmd() instance and make sure basic settings are like we want for test
298249
app = CmdLineApp()
250+
app.feedback_to_output = feedback_to_output
299251

300252
# Get location of the transcript
301253
test_dir = os.path.dirname(request.module.__file__)
302-
transcript_file = os.path.join(test_dir, 'transcripts/regex_set.txt')
254+
transcript_file = os.path.join(test_dir, 'transcripts', filename)
303255

304256
# Need to patch sys.argv so cmd2 doesn't think it was called with arguments equal to the py.test args
305257
testargs = ['prog', '-t', transcript_file]

0 commit comments

Comments
 (0)