summaryrefslogtreecommitdiff
path: root/cmd2/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 /cmd2/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 'cmd2/transcript.py')
-rw-r--r--cmd2/transcript.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/cmd2/transcript.py b/cmd2/transcript.py
index 940c97db..563756ed 100644
--- a/cmd2/transcript.py
+++ b/cmd2/transcript.py
@@ -25,6 +25,7 @@ class Cmd2TestCase(unittest.TestCase):
See example.py
"""
+
cmdapp = None
def setUp(self):
@@ -67,7 +68,7 @@ class Cmd2TestCase(unittest.TestCase):
finished = True
break
line_num += 1
- command = [line[len(self.cmdapp.visible_prompt):]]
+ command = [line[len(self.cmdapp.visible_prompt) :]]
try:
line = next(transcript)
except StopIteration:
@@ -75,12 +76,13 @@ class Cmd2TestCase(unittest.TestCase):
line_num += 1
# Read the entirety of a multi-line command
while line.startswith(self.cmdapp.continuation_prompt):
- command.append(line[len(self.cmdapp.continuation_prompt):])
+ command.append(line[len(self.cmdapp.continuation_prompt) :])
try:
line = next(transcript)
except StopIteration as exc:
- msg = 'Transcript broke off while reading command beginning at line {} with\n{}'.format(line_num,
- command[0])
+ msg = 'Transcript broke off while reading command beginning at line {} with\n{}'.format(
+ line_num, command[0]
+ )
raise StopIteration(msg) from exc
line_num += 1
command = ''.join(command)
@@ -91,7 +93,8 @@ class Cmd2TestCase(unittest.TestCase):
# Read the expected result from transcript
if ansi.strip_style(line).startswith(self.cmdapp.visible_prompt):
message = '\nFile {}, line {}\nCommand was:\n{}\nExpected: (nothing)\nGot:\n{}\n'.format(
- fname, line_num, command, result)
+ fname, line_num, command, result
+ )
self.assertTrue(not (result.strip()), message)
# If the command signaled the application to quit there should be no more commands
self.assertFalse(stop, stop_msg)
@@ -114,7 +117,8 @@ class Cmd2TestCase(unittest.TestCase):
expected = ''.join(expected)
expected = self._transform_transcript_expected(expected)
message = '\nFile {}, line {}\nCommand was:\n{}\nExpected:\n{}\nGot:\n{}\n'.format(
- fname, line_num, command, expected, result)
+ fname, line_num, command, expected, result
+ )
self.assertTrue(re.match(expected, result, re.MULTILINE | re.DOTALL), message)
def _transform_transcript_expected(self, s: str) -> str:
@@ -160,7 +164,7 @@ class Cmd2TestCase(unittest.TestCase):
else:
# No closing slash, we have to add the first slash,
# and the rest of the text
- regex += re.escape(s[start - 1:])
+ regex += re.escape(s[start - 1 :])
break
return regex
@@ -187,18 +191,18 @@ class Cmd2TestCase(unittest.TestCase):
break
else:
# check if the slash is preceeded by a backslash
- if s[pos - 1:pos] == '\\':
+ if s[pos - 1 : pos] == '\\':
# it is.
if in_regex:
# add everything up to the backslash as a
# regular expression
- regex += s[start:pos - 1]
+ regex += s[start : pos - 1]
# skip the backslash, and add the slash
regex += s[pos]
else:
# add everything up to the backslash as escaped
# plain text
- regex += re.escape(s[start:pos - 1])
+ regex += re.escape(s[start : pos - 1])
# and then add the slash as escaped
# plain text
regex += re.escape(s[pos])