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