1+ """
2+ Helper module for functional testing.
3+ """
4+ import re
15import sys
26
3- import trepan .inout .stringarray
4- from trepan import debugger as Mdebugger
5- from trepan .inout import stringarray as Mstringarray
7+ from trepan .debugger import Trepan
8+ from trepan .inout .stringarray import StringArrayInput , StringArrayOutput
69
710
811def strarray_setup (debugger_cmds ):
9- ''' Common setup to create a debugger with stringio attached '''
10- stringin = Mstringarray .StringArrayInput (debugger_cmds )
11- stringout = Mstringarray .StringArrayOutput ()
12- d_opts = {'input' : stringin ,
13- 'output' : stringout }
14- d = Mdebugger .Trepan (d_opts )
15- d .settings ['basename' ] = True
16- d .settings ['different' ] = False
17- d .settings ['autoeval' ] = False
18- d .settings ['highlight' ] = 'plain'
12+ """Common setup to create a debugger with stringio attached"""
13+ stringin = StringArrayInput (debugger_cmds )
14+ stringout = StringArrayOutput ()
15+ d_opts = {"input" : stringin , "output" : stringout }
16+ d = Trepan (d_opts )
17+ d .settings ["basename" ] = True
18+ d .settings ["different" ] = False
19+ d .settings ["autoeval" ] = False
20+ d .settings ["highlight" ] = "plain"
1921 return d
2022
21- import re
22- trepan_prompt = re .compile (r' ^.. \d+.*\n\(trepan3k(:.+)?\) ' )
23- trepan_loc = re .compile (r' ^\(.+:\d+\): ' )
23+
24+ trepan_prompt = re .compile (r" ^.. \d+.*\n\(trepan3k(:.+)?\) " )
25+ trepan_loc = re .compile (r" ^\(.+:\d+\): " )
2426
2527
2628def filter_line_cmd (a ):
27- ''' Return output with source lines prompt and command removed'''
29+ """ Return output with source lines prompt and command removed"""
2830 # Remove extra leading spaces.
2931 # For example:
3032 # -- 42 y = 5
3133 # becomes
3234 # -- y = 5
33- a1 = [re .sub (r'^(..) \d+\s+' , r'\1 ' , s ) for s in a
34- if re .match (r'^.. \d+\s+' , s )]
35+ a1 = [re .sub (r"^(..) \d+\s+" , r"\1 " , s ) for s in a if re .match (r"^.. \d+\s+" , s )]
3536 # Remove debugger prompts
3637 # For example:
3738 # (trepan3k)
38- a2 = [re .sub (r' \n\(trepan3k\) .*' , '' , s ) for s in a1 ]
39+ a2 = [re .sub (r" \n\(trepan3k\) .*" , "" , s ) for s in a1 ]
3940
4041 # Remove locations (test-next.py:41): test_next_between_fn
41- a3 = [re .sub (r' \n\(.*:\d+\):.*' , '' , s ) for s in a2 ]
42+ a3 = [re .sub (r" \n\(.*:\d+\):.*" , "" , s ) for s in a2 ]
4243 return a3
4344
4445
@@ -48,7 +49,7 @@ def get_lineno():
4849 return caller .f_lineno
4950
5051
51- def compare_output (obj , right , d , debugger_cmds ):
52+ def compare_output (obj , right , d ):
5253 got = filter_line_cmd (d .intf [- 1 ].output .output )
5354 if got != right :
5455 for i in range (len (got )):
@@ -58,7 +59,7 @@ def compare_output(obj, right, d, debugger_cmds):
5859 print (" " , got [i ])
5960 pass
6061 pass
61- print ('-' * 10 )
62+ print ("-" * 10 )
6263 for i in range (len (right )):
6364 if i < len (got ) and got [i ] != right [i ]:
6465 print ("! " , right [i ])
@@ -70,7 +71,8 @@ def compare_output(obj, right, d, debugger_cmds):
7071 obj .assertEqual (right , got )
7172 return
7273
74+
7375# Demo it
74- if __name__ == ' __main__' :
76+ if __name__ == " __main__" :
7577 print (get_lineno ())
7678 pass
0 commit comments