66we need a mechanism to run each command in the transcript as
77a unit test, comparing the expected output to the actual output.
88
9- This file contains the classess necessary to make that work. These
10- classes are used in cmd2.py::run_transcript_tests()
9+ This file contains the class necessary to make that work. This
10+ class is used in cmd2.py::run_transcript_tests()
1111"""
1212import re
1313import unittest
@@ -27,27 +27,32 @@ class Cmd2TestCase(unittest.TestCase):
2727 """
2828 cmdapp = None
2929
30- def fetchTranscripts (self ):
31- self .transcripts = {}
32- for fname in self .cmdapp .testfiles :
33- tfile = open (fname )
34- self .transcripts [fname ] = iter (tfile .readlines ())
35- tfile .close ()
36-
3730 def setUp (self ):
3831 if self .cmdapp :
39- self .fetchTranscripts ()
32+ self ._fetchTranscripts ()
4033
4134 # Trap stdout
4235 self ._orig_stdout = self .cmdapp .stdout
4336 self .cmdapp .stdout = utils .StdSim (self .cmdapp .stdout )
4437
38+ def tearDown (self ):
39+ if self .cmdapp :
40+ # Restore stdout
41+ self .cmdapp .stdout = self ._orig_stdout
42+
4543 def runTest (self ): # was testall
4644 if self .cmdapp :
4745 its = sorted (self .transcripts .items ())
4846 for (fname , transcript ) in its :
4947 self ._test_transcript (fname , transcript )
5048
49+ def _fetchTranscripts (self ):
50+ self .transcripts = {}
51+ for fname in self .cmdapp .testfiles :
52+ tfile = open (fname )
53+ self .transcripts [fname ] = iter (tfile .readlines ())
54+ tfile .close ()
55+
5156 def _test_transcript (self , fname : str , transcript ):
5257 line_num = 0
5358 finished = False
@@ -205,8 +210,3 @@ def _escaped_find(regex: str, s: str, start: int, in_regex: bool) -> Tuple[str,
205210 # slash is not escaped, this is what we are looking for
206211 break
207212 return regex , pos , start
208-
209- def tearDown (self ):
210- if self .cmdapp :
211- # Restore stdout
212- self .cmdapp .stdout = self ._orig_stdout
0 commit comments