@@ -14,29 +14,32 @@ class TestPathfixFunctional(unittest.TestCase):
14
14
script = os .path .join (scriptsdir , 'pathfix.py' )
15
15
16
16
def setUp (self ):
17
- self .temp_file = support .TESTFN
18
17
self .addCleanup (support .unlink , support .TESTFN )
19
18
20
19
def pathfix (self , shebang , pathfix_flags , exitcode = 0 , stdout = '' , stderr = '' ,
21
- filename = '' ):
22
- if filename == '' :
23
- filename = self .temp_file
24
-
25
- with open (self .temp_file , 'w' , encoding = 'utf8' ) as f :
20
+ directory = '' ):
21
+ if directory :
22
+ filename = os .path .join (directory , 'script-A_1.py' )
23
+ pathfix_arg = directory
24
+ else :
25
+ filename = support .TESTFN
26
+ pathfix_arg = filename
27
+
28
+ with open (filename , 'w' , encoding = 'utf8' ) as f :
26
29
f .write (f'{ shebang } \n ' + 'print("Hello world")\n ' )
27
30
28
31
proc = subprocess .run (
29
32
[sys .executable , self .script ,
30
- * pathfix_flags , '-n' , filename ],
33
+ * pathfix_flags , '-n' , pathfix_arg ],
31
34
capture_output = True , text = 1 )
32
35
33
36
if stdout == '' and proc .returncode == 0 :
34
- stdout = f'{ self . temp_file } : updating\n '
37
+ stdout = f'{ filename } : updating\n '
35
38
self .assertEqual (proc .returncode , exitcode , proc )
36
39
self .assertEqual (proc .stdout , stdout , proc )
37
40
self .assertEqual (proc .stderr , stderr , proc )
38
41
39
- with open (self . temp_file , 'r' , encoding = 'utf8' ) as f :
42
+ with open (filename , 'r' , encoding = 'utf8' ) as f :
40
43
output = f .read ()
41
44
42
45
lines = output .split ('\n ' )
@@ -49,18 +52,15 @@ def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr='',
49
52
return new_shebang
50
53
51
54
def test_recursive (self ):
52
- self .temp_directory = support .TESTFN + '.d'
53
- self .addCleanup (support .rmtree , self .temp_directory )
54
- os .mkdir (self .temp_directory )
55
- self .temp_file = self .temp_directory + os .sep + \
56
- os .path .basename (support .TESTFN ) + '-t.py'
57
- temp_directory_basename = os .path .basename (self .temp_directory )
58
- expected_stderr = f'recursedown(\' { temp_directory_basename } \' )\n '
55
+ tmpdir = support .TESTFN + '.d'
56
+ self .addCleanup (support .rmtree , tmpdir )
57
+ os .mkdir (tmpdir )
58
+ expected_stderr = f'recursedown(\' { os .path .basename (tmpdir )} \' )\n '
59
59
self .assertEqual (
60
60
self .pathfix (
61
61
'#! /usr/bin/env python' ,
62
62
['-i' , '/usr/bin/python3' ],
63
- filename = self . temp_directory ,
63
+ directory = tmpdir ,
64
64
stderr = expected_stderr ),
65
65
'#! /usr/bin/python3' )
66
66
0 commit comments