@@ -17,13 +17,17 @@ def setUp(self):
17
17
self .temp_file = support .TESTFN
18
18
self .addCleanup (support .unlink , support .TESTFN )
19
19
20
- def pathfix (self , shebang , pathfix_flags , exitcode = 0 , stdout = '' , stderr = '' ):
20
+ def pathfix (self , shebang , pathfix_flags , exitcode = 0 , stdout = '' , stderr = '' ,
21
+ filename = '' ):
22
+ if filename == '' :
23
+ filename = self .temp_file
24
+
21
25
with open (self .temp_file , 'w' , encoding = 'utf8' ) as f :
22
26
f .write (f'{ shebang } \n ' + 'print("Hello world")\n ' )
23
27
24
28
proc = subprocess .run (
25
29
[sys .executable , self .script ,
26
- * pathfix_flags , '-n' , self . temp_file ],
30
+ * pathfix_flags , '-n' , filename ],
27
31
capture_output = True , text = 1 )
28
32
29
33
if stdout == '' and proc .returncode == 0 :
@@ -44,6 +48,22 @@ def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr=''):
44
48
45
49
return new_shebang
46
50
51
+ 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 '
59
+ self .assertEqual (
60
+ self .pathfix (
61
+ '#! /usr/bin/env python' ,
62
+ ['-i' , '/usr/bin/python3' ],
63
+ filename = self .temp_directory ,
64
+ stderr = expected_stderr ),
65
+ '#! /usr/bin/python3' )
66
+
47
67
def test_pathfix (self ):
48
68
self .assertEqual (
49
69
self .pathfix (
0 commit comments