1- from xdis import IS_PYPY
2- import difflib , os , re , sys , time
1+ import difflib
2+ import os
33import os .path as osp
4+ import re
5+ import sys
6+ import time
7+
8+ from xdis import IS_PYPY
9+
410srcdir = osp .abspath (osp .dirname (__file__ ))
511
612
7- def run_debugger (testname , python_file , dbgr_opts = '' , args = '' ,
8- outfile = None , right_template = None ):
9- datadir = osp .join (srcdir , '..' , 'data' )
10- progdir = osp .join (srcdir , '..' , 'example' )
11- dbgrdir = osp .join (srcdir , '..' , '..' , 'trepan' )
12- dbgr_short = "__main__.py"
13+ def run_debugger (
14+ testname , python_file , dbgr_opts = "" , args = "" , outfile = None , right_template = None
15+ ):
16+ datadir = osp .join (srcdir , ".." , "data" )
17+ progdir = osp .join (srcdir , ".." , "example" )
18+ dbgrdir = osp .join (srcdir , ".." , ".." , "trepan" )
19+ dbgr_short = "__main__.py"
1320 dbgr_path = osp .join (dbgrdir , dbgr_short )
1421
1522 if not right_template :
@@ -20,43 +27,53 @@ def run_debugger(testname, python_file, dbgr_opts='', args='',
2027
2128 rightfile = osp .join (datadir , right_template % testname )
2229
23- sys .path .insert (0 , osp .join (srcdir , '..' , '..' ))
24- os .environ [' PYTHONPATH' ] = os .pathsep .join (sys .path )
25- cmdfile = osp .join (datadir , "%s .cmd" % testname )
26- outfile = osp .join (srcdir , "%s .out" % testname )
30+ sys .path .insert (0 , osp .join (srcdir , ".." , ".." ))
31+ os .environ [" PYTHONPATH" ] = os .pathsep .join (sys .path )
32+ cmdfile = osp .join (datadir , f" { testname } .cmd" )
33+ outfile = osp .join (srcdir , f" { testname } .out" )
2734 if python_file :
2835 programfile = osp .join (progdir , python_file )
2936 else :
30- programfile = ''
37+ programfile = ""
3138 pass
3239
33- outfile_opt = ' --output=%s ' % outfile
40+ outfile_opt = f" --output={ outfile } "
3441
35- if osp .exists (outfile ): os .unlink (outfile )
42+ if osp .exists (outfile ):
43+ os .unlink (outfile )
3644
37- cmd = "%s --command %s %s %s %s %s" % \
38- (dbgr_path , cmdfile , outfile_opt , dbgr_opts , programfile , args )
45+ cmd = "%s --command %s %s %s %s %s" % (
46+ dbgr_path ,
47+ cmdfile ,
48+ outfile_opt ,
49+ dbgr_opts ,
50+ programfile ,
51+ args ,
52+ )
3953
4054 # print(cmd)
4155 os .system (cmd )
42- fromfile = rightfile
43- fromdate = time .ctime (os .stat (fromfile ).st_mtime )
44- tofile = outfile
45- todate = time .ctime (os .stat (tofile ).st_mtime )
46- with open (fromfile ) as f : fromlines = f .readlines ()
47- with open (tofile ) as f : tolines = f .readlines ()
56+ fromfile = rightfile
57+ fromdate = time .ctime (os .stat (fromfile ).st_mtime )
58+ tofile = outfile
59+ todate = time .ctime (os .stat (tofile ).st_mtime )
60+ with open (fromfile ) as f :
61+ fromlines = f .readlines ()
62+ with open (tofile ) as f :
63+ tolines = f .readlines ()
4864
4965 # Filter out last instruction. For example:
5066 # (gcd.py:11 @6): -> (gcd.py:11)
51- tolines = [re .sub (' @\d+\):' , '):' , line ) for line in tolines ]
67+ tolines = [re .sub (r" @\d+\):" , "):" , line ) for line in tolines ]
5268
53- diff = list (difflib .unified_diff (fromlines , tolines , fromfile ,
54- tofile , fromdate , todate ))
69+ diff = list (
70+ difflib .unified_diff (fromlines , tolines , fromfile , tofile , fromdate , todate )
71+ )
5572 if len (diff ) == 0 :
5673 os .unlink (outfile )
5774 pass
5875 else :
59- with open (tofile , 'w' ) as out :
76+ with open (tofile , "w" ) as out :
6077 out .writelines (tolines )
6178 pass
6279 pass
0 commit comments