summaryrefslogtreecommitdiff
path: root/tests/test_transcript.py
diff options
context:
space:
mode:
authorxNinjaKittyx <xNinjaKittyx@users.noreply.github.com>2020-12-15 17:21:33 -0800
committerxNinjaKittyx <xNinjaKittyx@users.noreply.github.com>2020-12-15 18:20:13 -0800
commit9aa54a5b27468d61337528cb1e1b5b9b11a80978 (patch)
tree567693115cc101efb9254a96d96d80e9f9ccd557 /tests/test_transcript.py
parent03c65c60b39e369958b056c5c844d36d515c8a63 (diff)
downloadcmd2-git-ci_improvements.tar.gz
Adds pre-commit config to run various lintersci_improvements
This ads black, isort, pyupgrade, and flake8 to pre-commit-config.yaml There are also some small changes to travis.yml and tasks.py to reduce some repeated configurations that should be consolidated into setup.cfg. Most other changes are automated by the linter scripts.
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()