6
6
we need a mechanism to run each command in the transcript as
7
7
a unit test, comparing the expected output to the actual output.
8
8
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()
11
11
"""
12
12
import re
13
13
import unittest
@@ -27,27 +27,32 @@ class Cmd2TestCase(unittest.TestCase):
27
27
"""
28
28
cmdapp = None
29
29
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
-
37
30
def setUp (self ):
38
31
if self .cmdapp :
39
- self .fetchTranscripts ()
32
+ self ._fetchTranscripts ()
40
33
41
34
# Trap stdout
42
35
self ._orig_stdout = self .cmdapp .stdout
43
36
self .cmdapp .stdout = utils .StdSim (self .cmdapp .stdout )
44
37
38
+ def tearDown (self ):
39
+ if self .cmdapp :
40
+ # Restore stdout
41
+ self .cmdapp .stdout = self ._orig_stdout
42
+
45
43
def runTest (self ): # was testall
46
44
if self .cmdapp :
47
45
its = sorted (self .transcripts .items ())
48
46
for (fname , transcript ) in its :
49
47
self ._test_transcript (fname , transcript )
50
48
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
+
51
56
def _test_transcript (self , fname : str , transcript ):
52
57
line_num = 0
53
58
finished = False
@@ -205,8 +210,3 @@ def _escaped_find(regex: str, s: str, start: int, in_regex: bool) -> Tuple[str,
205
210
# slash is not escaped, this is what we are looking for
206
211
break
207
212
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