summaryrefslogtreecommitdiff
path: root/cmd2/transcript.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-06-09 18:57:13 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2018-06-09 18:57:13 -0400
commit6f06dd97b30ba2bed40d580f3dc966dc9be103fd (patch)
treed9ebaa6b5b91dee56b7e204807ad610a4e39d944 /cmd2/transcript.py
parentdd299bf5bf21b175ffdd2caae63cfa8bf1a85c34 (diff)
downloadcmd2-git-6f06dd97b30ba2bed40d580f3dc966dc9be103fd.tar.gz
Working on improving type hinting
Also: - Refactored perror() to remove a rarely used optional argument which was unecessary
Diffstat (limited to 'cmd2/transcript.py')
-rw-r--r--cmd2/transcript.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/cmd2/transcript.py b/cmd2/transcript.py
index 8a9837a6..5ba8d20d 100644
--- a/cmd2/transcript.py
+++ b/cmd2/transcript.py
@@ -12,9 +12,11 @@ classes are used in cmd2.py::run_transcript_tests()
import re
import glob
import unittest
+from typing import Tuple
from . import utils
+
class Cmd2TestCase(unittest.TestCase):
"""A unittest class used for transcript testing.
@@ -50,7 +52,7 @@ class Cmd2TestCase(unittest.TestCase):
for (fname, transcript) in its:
self._test_transcript(fname, transcript)
- def _test_transcript(self, fname, transcript):
+ def _test_transcript(self, fname: str, transcript):
line_num = 0
finished = False
line = utils.strip_ansi(next(transcript))
@@ -103,7 +105,7 @@ class Cmd2TestCase(unittest.TestCase):
fname, line_num, command, expected, result)
self.assertTrue(re.match(expected, result, re.MULTILINE | re.DOTALL), message)
- def _transform_transcript_expected(self, s):
+ def _transform_transcript_expected(self, s: str) -> str:
"""Parse the string with slashed regexes into a valid regex.
Given a string like:
@@ -151,7 +153,7 @@ class Cmd2TestCase(unittest.TestCase):
return regex
@staticmethod
- def _escaped_find(regex, s, start, in_regex):
+ def _escaped_find(regex: str, s: str, start: int, in_regex: bool) -> Tuple[str, int, int]:
"""Find the next slash in {s} after {start} that is not preceded by a backslash.
If we find an escaped slash, add everything up to and including it to regex,
@@ -162,7 +164,6 @@ class Cmd2TestCase(unittest.TestCase):
{in_regex} specifies whether we are currently searching in a regex, we behave
differently if we are or if we aren't.
"""
-
while True:
pos = s.find('/', start)
if pos == -1:
@@ -211,14 +212,11 @@ class OutputTrap(object):
def __init__(self):
self.contents = ''
- def write(self, txt):
- """Add text to the internal contents.
-
- :param txt: str
- """
+ def write(self, txt: str):
+ """Add text to the internal contents."""
self.contents += txt
- def read(self):
+ def read(self) -> str:
"""Read from the internal contents and then clear them out.
:return: str - text from the internal contents