@@ -14,25 +14,34 @@ class TestPathfixFunctional(unittest.TestCase):
1414 script = os .path .join (scriptsdir , 'pathfix.py' )
1515
1616 def setUp (self ):
17- self .temp_file = support .TESTFN
1817 self .addCleanup (support .unlink , support .TESTFN )
1918
20- def pathfix (self , shebang , pathfix_flags , exitcode = 0 , stdout = '' , stderr = '' ):
21- with open (self .temp_file , 'w' , encoding = 'utf8' ) as f :
19+ def pathfix (self , shebang , pathfix_flags , exitcode = 0 , stdout = '' , stderr = '' ,
20+ directory = '' ):
21+ if directory :
22+ # bpo-38347: Test filename should contain lowercase, uppercase,
23+ # "-", "_" and digits.
24+ filename = os .path .join (directory , 'script-A_1.py' )
25+ pathfix_arg = directory
26+ else :
27+ filename = support .TESTFN
28+ pathfix_arg = filename
29+
30+ with open (filename , 'w' , encoding = 'utf8' ) as f :
2231 f .write (f'{ shebang } \n ' + 'print("Hello world")\n ' )
2332
2433 proc = subprocess .run (
2534 [sys .executable , self .script ,
26- * pathfix_flags , '-n' , self . temp_file ],
35+ * pathfix_flags , '-n' , pathfix_arg ],
2736 capture_output = True , text = 1 )
2837
2938 if stdout == '' and proc .returncode == 0 :
30- stdout = f'{ self . temp_file } : updating\n '
39+ stdout = f'{ filename } : updating\n '
3140 self .assertEqual (proc .returncode , exitcode , proc )
3241 self .assertEqual (proc .stdout , stdout , proc )
3342 self .assertEqual (proc .stderr , stderr , proc )
3443
35- with open (self . temp_file , 'r' , encoding = 'utf8' ) as f :
44+ with open (filename , 'r' , encoding = 'utf8' ) as f :
3645 output = f .read ()
3746
3847 lines = output .split ('\n ' )
@@ -44,6 +53,19 @@ def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr=''):
4453
4554 return new_shebang
4655
56+ def test_recursive (self ):
57+ tmpdir = support .TESTFN + '.d'
58+ self .addCleanup (support .rmtree , tmpdir )
59+ os .mkdir (tmpdir )
60+ expected_stderr = f"recursedown('{ os .path .basename (tmpdir )} ')\n "
61+ self .assertEqual (
62+ self .pathfix (
63+ '#! /usr/bin/env python' ,
64+ ['-i' , '/usr/bin/python3' ],
65+ directory = tmpdir ,
66+ stderr = expected_stderr ),
67+ '#! /usr/bin/python3' )
68+
4769 def test_pathfix (self ):
4870 self .assertEqual (
4971 self .pathfix (
0 commit comments