summaryrefslogtreecommitdiff
path: root/tests/test_transcript.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_transcript.py')
-rw-r--r--tests/test_transcript.py95
1 files changed, 52 insertions, 43 deletions
diff --git a/tests/test_transcript.py b/tests/test_transcript.py
index 55d60e18..5b19e11e 100644
--- a/tests/test_transcript.py
+++ b/tests/test_transcript.py
@@ -46,7 +46,7 @@ class CmdLineApp(cmd2.Cmd):
"""Repeats what you tell me to."""
arg = ' '.join(arg)
if opts.piglatin:
- arg = '%s%say' % (arg[1:], arg[0])
+ arg = '{}{}ay'.format(arg[1:], arg[0])
if opts.shout:
arg = arg.upper()
repetitions = opts.repeat or 1
@@ -66,16 +66,16 @@ class CmdLineApp(cmd2.Cmd):
def do_mumble(self, opts, arg):
"""Mumbles what you tell me to."""
repetitions = opts.repeat or 1
- #arg = arg.split()
+ # arg = arg.split()
for _ in range(min(repetitions, self.maxrepeats)):
output = []
- if random.random() < .33:
+ if random.random() < 0.33:
output.append(random.choice(self.MUMBLE_FIRST))
for word in arg:
- if random.random() < .40:
+ if random.random() < 0.40:
output.append(random.choice(self.MUMBLES))
output.append(word)
- if random.random() < .25:
+ if random.random() < 0.25:
output.append(random.choice(self.MUMBLE_LAST))
self.poutput(' '.join(output))
@@ -98,23 +98,27 @@ def test_commands_at_invocation():
out = app.stdout.getvalue()
assert out == expected
-@pytest.mark.parametrize('filename,feedback_to_output', [
- ('bol_eol.txt', False),
- ('characterclass.txt', False),
- ('dotstar.txt', False),
- ('extension_notation.txt', False),
- ('from_cmdloop.txt', True),
- ('multiline_no_regex.txt', False),
- ('multiline_regex.txt', False),
- ('no_output.txt', False),
- ('no_output_last.txt', False),
- ('regex_set.txt', False),
- ('singleslash.txt', False),
- ('slashes_escaped.txt', False),
- ('slashslash.txt', False),
- ('spaces.txt', False),
- ('word_boundaries.txt', False),
- ])
+
+@pytest.mark.parametrize(
+ 'filename,feedback_to_output',
+ [
+ ('bol_eol.txt', False),
+ ('characterclass.txt', False),
+ ('dotstar.txt', False),
+ ('extension_notation.txt', False),
+ ('from_cmdloop.txt', True),
+ ('multiline_no_regex.txt', False),
+ ('multiline_regex.txt', False),
+ ('no_output.txt', False),
+ ('no_output_last.txt', False),
+ ('regex_set.txt', False),
+ ('singleslash.txt', False),
+ ('slashes_escaped.txt', False),
+ ('slashslash.txt', False),
+ ('spaces.txt', False),
+ ('word_boundaries.txt', False),
+ ],
+)
def test_transcript(request, capsys, filename, feedback_to_output):
# Get location of the transcript
test_dir = os.path.dirname(request.module.__file__)
@@ -141,6 +145,7 @@ def test_transcript(request, capsys, filename, feedback_to_output):
assert err.startswith(expected_start)
assert err.endswith(expected_end)
+
def test_history_transcript():
app = CmdLineApp()
app.stdout = StdSim(app.stdout)
@@ -168,6 +173,7 @@ this is a \/multiline\/ command
assert xscript == expected
+
def test_history_transcript_bad_filename():
app = CmdLineApp()
app.stdout = StdSim(app.stdout)
@@ -247,27 +253,30 @@ def test_generate_transcript_stop(capsys):
assert err.startswith("Interrupting this command\nCommand 2 triggered a stop")
-@pytest.mark.parametrize('expected, transformed', [
- # strings with zero or one slash or with escaped slashes means no regular
- # expression present, so the result should just be what re.escape returns.
- # we don't use static strings in these tests because re.escape behaves
- # differently in python 3.7 than in prior versions
- ( 'text with no slashes', re.escape('text with no slashes') ),
- ( 'specials .*', re.escape('specials .*') ),
- ( 'use 2/3 cup', re.escape('use 2/3 cup') ),
- ( '/tmp is nice', re.escape('/tmp is nice') ),
- ( 'slash at end/', re.escape('slash at end/') ),
- # escaped slashes
- ( r'not this slash\/ or this one\/', re.escape('not this slash/ or this one/' ) ),
- # regexes
- ( '/.*/', '.*' ),
- ( 'specials ^ and + /[0-9]+/', re.escape('specials ^ and + ') + '[0-9]+' ),
- ( r'/a{6}/ but not \/a{6} with /.*?/ more', 'a{6}' + re.escape(' but not /a{6} with ') + '.*?' + re.escape(' more') ),
- ( r'not \/, use /\|?/, not \/', re.escape('not /, use ') + r'\|?' + re.escape(', not /') ),
- # inception: slashes in our regex. backslashed on input, bare on output
- ( r'not \/, use /\/?/, not \/', re.escape('not /, use ') + '/?' + re.escape(', not /') ),
- ( r'lots /\/?/ more /.*/ stuff', re.escape('lots ') + '/?' + re.escape(' more ') + '.*' + re.escape(' stuff') ),
- ])
+@pytest.mark.parametrize(
+ 'expected, transformed',
+ [
+ # strings with zero or one slash or with escaped slashes means no regular
+ # expression present, so the result should just be what re.escape returns.
+ # we don't use static strings in these tests because re.escape behaves
+ # differently in python 3.7 than in prior versions
+ ('text with no slashes', re.escape('text with no slashes')),
+ ('specials .*', re.escape('specials .*')),
+ ('use 2/3 cup', re.escape('use 2/3 cup')),
+ ('/tmp is nice', re.escape('/tmp is nice')),
+ ('slash at end/', re.escape('slash at end/')),
+ # escaped slashes
+ (r'not this slash\/ or this one\/', re.escape('not this slash/ or this one/')),
+ # regexes
+ ('/.*/', '.*'),
+ ('specials ^ and + /[0-9]+/', re.escape('specials ^ and + ') + '[0-9]+'),
+ (r'/a{6}/ but not \/a{6} with /.*?/ more', 'a{6}' + re.escape(' but not /a{6} with ') + '.*?' + re.escape(' more')),
+ (r'not \/, use /\|?/, not \/', re.escape('not /, use ') + r'\|?' + re.escape(', not /')),
+ # inception: slashes in our regex. backslashed on input, bare on output
+ (r'not \/, use /\/?/, not \/', re.escape('not /, use ') + '/?' + re.escape(', not /')),
+ (r'lots /\/?/ more /.*/ stuff', re.escape('lots ') + '/?' + re.escape(' more ') + '.*' + re.escape(' stuff')),
+ ],
+)
def test_parse_transcript_expected(expected, transformed):
app = CmdLineApp()