summaryrefslogtreecommitdiff
path: root/cmd2/transcript.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-06-14 17:36:44 -0400
committerGitHub <noreply@github.com>2019-06-14 17:36:44 -0400
commitddd07f9cd6d72baca1232ae98856cf3b3d564706 (patch)
tree8e03d435730baf1cc16ccc016e594d0b64d8e04a /cmd2/transcript.py
parentf64f9d559caa08b5649b9bd356af2812acf103bd (diff)
parent756d8d38502e934ea180c4cfb8dea3efd124a3bf (diff)
downloadcmd2-git-ddd07f9cd6d72baca1232ae98856cf3b3d564706.tar.gz
Merge pull request #696 from python-cmd2/script_refactor
Script refactor
Diffstat (limited to 'cmd2/transcript.py')
-rw-r--r--cmd2/transcript.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/cmd2/transcript.py b/cmd2/transcript.py
index a635c1d3..5a115496 100644
--- a/cmd2/transcript.py
+++ b/cmd2/transcript.py
@@ -10,7 +10,6 @@ This file contains the classess necessary to make that work. These
classes are used in cmd2.py::run_transcript_tests()
"""
import re
-import glob
import unittest
from typing import Tuple
@@ -30,13 +29,10 @@ class Cmd2TestCase(unittest.TestCase):
def fetchTranscripts(self):
self.transcripts = {}
- for fileset in self.cmdapp.testfiles:
- for fname in glob.glob(fileset):
- tfile = open(fname)
- self.transcripts[fname] = iter(tfile.readlines())
- tfile.close()
- if not len(self.transcripts):
- raise Exception("No test files found - nothing to test.")
+ for fname in self.cmdapp.testfiles:
+ tfile = open(fname)
+ self.transcripts[fname] = iter(tfile.readlines())
+ tfile.close()
def setUp(self):
if self.cmdapp:
@@ -84,14 +80,16 @@ class Cmd2TestCase(unittest.TestCase):
line_num += 1
command = ''.join(command)
# Send the command into the application and capture the resulting output
- # TODO: Should we get the return value and act if stop == True?
- self.cmdapp.onecmd_plus_hooks(command)
+ stop = self.cmdapp.onecmd_plus_hooks(command)
result = self.cmdapp.stdout.read()
+ stop_msg = 'Command indicated application should quit, but more commands in transcript'
# Read the expected result from transcript
if utils.strip_ansi(line).startswith(self.cmdapp.visible_prompt):
message = '\nFile {}, line {}\nCommand was:\n{}\nExpected: (nothing)\nGot:\n{}\n'.format(
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)
continue
expected = []
while not utils.strip_ansi(line).startswith(self.cmdapp.visible_prompt):
@@ -102,9 +100,13 @@ class Cmd2TestCase(unittest.TestCase):
finished = True
break
line_num += 1
- expected = ''.join(expected)
+
+ if stop:
+ # This should only be hit if the command that set stop to True had output text
+ self.assertTrue(finished, stop_msg)
# transform the expected text into a valid regular expression
+ 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)