@@ -14,16 +14,24 @@ 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
- self .addCleanup (support .unlink , support .TESTFN )
17
+ self .temp_directory = support .TESTFN + '.d'
18
+ self .addCleanup (support .rmtree , self .temp_directory )
19
+ os .mkdir (self .temp_directory )
20
+ self .temp_file = self .temp_directory + '/' + \
21
+ os .path .basename (support .TESTFN ) + '-t.py'
22
+ self .addCleanup (support .unlink , self .temp_file )
23
+
24
+ def pathfix (self , shebang , pathfix_flags , exitcode = 0 , stdout = '' , stderr = '' ,
25
+ target_file = '' ):
26
+ if target_file == '' :
27
+ target_file = self .temp_file
19
28
20
- def pathfix (self , shebang , pathfix_flags , exitcode = 0 , stdout = '' , stderr = '' ):
21
29
with open (self .temp_file , 'w' , encoding = 'utf8' ) as f :
22
30
f .write (f'{ shebang } \n ' + 'print("Hello world")\n ' )
23
31
24
32
proc = subprocess .run (
25
33
[sys .executable , self .script ,
26
- * pathfix_flags , '-n' , self . temp_file ],
34
+ * pathfix_flags , '-n' , target_file ],
27
35
capture_output = True , text = 1 )
28
36
29
37
if stdout == '' and proc .returncode == 0 :
@@ -44,55 +52,66 @@ def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr=''):
44
52
45
53
return new_shebang
46
54
47
- def test_pathfix (self ):
55
+ def test_recursive (self ):
56
+ temp_directory_basename = os .path .basename (self .temp_directory )
57
+ expected_stderr = f'recursedown(\' { temp_directory_basename } \' )\n '
58
+ for method_name in dir (self ):
59
+ method = getattr (self , method_name )
60
+ if method_name .startswith ('test_' ) and \
61
+ method_name != 'test_recursive' and \
62
+ method_name != 'test_pathfix_adding_errors' and \
63
+ callable (method ):
64
+ method (target_file = self .temp_directory , stderr = expected_stderr )
65
+
66
+ def test_pathfix (self , ** kwargs ):
48
67
self .assertEqual (
49
68
self .pathfix (
50
69
'#! /usr/bin/env python' ,
51
- ['-i' , '/usr/bin/python3' ]),
70
+ ['-i' , '/usr/bin/python3' ], ** kwargs ),
52
71
'#! /usr/bin/python3' )
53
72
self .assertEqual (
54
73
self .pathfix (
55
74
'#! /usr/bin/env python -R' ,
56
- ['-i' , '/usr/bin/python3' ]),
75
+ ['-i' , '/usr/bin/python3' ], ** kwargs ),
57
76
'#! /usr/bin/python3' )
58
77
59
- def test_pathfix_keeping_flags (self ):
78
+ def test_pathfix_keeping_flags (self , ** kwargs ):
60
79
self .assertEqual (
61
80
self .pathfix (
62
81
'#! /usr/bin/env python -R' ,
63
- ['-i' , '/usr/bin/python3' , '-k' ]),
82
+ ['-i' , '/usr/bin/python3' , '-k' ], ** kwargs ),
64
83
'#! /usr/bin/python3 -R' )
65
84
self .assertEqual (
66
85
self .pathfix (
67
86
'#! /usr/bin/env python' ,
68
- ['-i' , '/usr/bin/python3' , '-k' ]),
87
+ ['-i' , '/usr/bin/python3' , '-k' ], ** kwargs ),
69
88
'#! /usr/bin/python3' )
70
89
71
- def test_pathfix_adding_flag (self ):
90
+ def test_pathfix_adding_flag (self , ** kwargs ):
72
91
self .assertEqual (
73
92
self .pathfix (
74
93
'#! /usr/bin/env python' ,
75
- ['-i' , '/usr/bin/python3' , '-a' , 's' ]),
94
+ ['-i' , '/usr/bin/python3' , '-a' , 's' ], ** kwargs ),
76
95
'#! /usr/bin/python3 -s' )
77
96
self .assertEqual (
78
97
self .pathfix (
79
98
'#! /usr/bin/env python -S' ,
80
- ['-i' , '/usr/bin/python3' , '-a' , 's' ]),
99
+ ['-i' , '/usr/bin/python3' , '-a' , 's' ], ** kwargs ),
81
100
'#! /usr/bin/python3 -s' )
82
101
self .assertEqual (
83
102
self .pathfix (
84
103
'#! /usr/bin/env python -V' ,
85
- ['-i' , '/usr/bin/python3' , '-a' , 'v' , '-k' ]),
104
+ ['-i' , '/usr/bin/python3' , '-a' , 'v' , '-k' ], ** kwargs ),
86
105
'#! /usr/bin/python3 -vV' )
87
106
self .assertEqual (
88
107
self .pathfix (
89
108
'#! /usr/bin/env python' ,
90
- ['-i' , '/usr/bin/python3' , '-a' , 'Rs' ]),
109
+ ['-i' , '/usr/bin/python3' , '-a' , 'Rs' ], ** kwargs ),
91
110
'#! /usr/bin/python3 -Rs' )
92
111
self .assertEqual (
93
112
self .pathfix (
94
113
'#! /usr/bin/env python -W default' ,
95
- ['-i' , '/usr/bin/python3' , '-a' , 's' , '-k' ]),
114
+ ['-i' , '/usr/bin/python3' , '-a' , 's' , '-k' ], ** kwargs ),
96
115
'#! /usr/bin/python3 -sW default' )
97
116
98
117
def test_pathfix_adding_errors (self ):
0 commit comments