@@ -14,25 +14,34 @@ 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
- 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 :
22
31
f .write (f'{ shebang } \n ' + 'print("Hello world")\n ' )
23
32
24
33
proc = subprocess .run (
25
34
[sys .executable , self .script ,
26
- * pathfix_flags , '-n' , self . temp_file ],
35
+ * pathfix_flags , '-n' , pathfix_arg ],
27
36
capture_output = True , text = 1 )
28
37
29
38
if stdout == '' and proc .returncode == 0 :
30
- stdout = f'{ self . temp_file } : updating\n '
39
+ stdout = f'{ filename } : updating\n '
31
40
self .assertEqual (proc .returncode , exitcode , proc )
32
41
self .assertEqual (proc .stdout , stdout , proc )
33
42
self .assertEqual (proc .stderr , stderr , proc )
34
43
35
- with open (self . temp_file , 'r' , encoding = 'utf8' ) as f :
44
+ with open (filename , 'r' , encoding = 'utf8' ) as f :
36
45
output = f .read ()
37
46
38
47
lines = output .split ('\n ' )
@@ -44,6 +53,19 @@ def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr=''):
44
53
45
54
return new_shebang
46
55
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
+
47
69
def test_pathfix (self ):
48
70
self .assertEqual (
49
71
self .pathfix (
0 commit comments