16
16
17
17
18
18
class NormalizeFilenameTestCase (unittest .TestCase ):
19
- COMMAND = os .path .normpath (os .path .join (os .getcwd (), ' normfn' ))
19
+ COMMAND = os .path .normpath (os .path .join (os .getcwd (), " normfn" ))
20
20
21
21
def setUp (self ):
22
22
self .workingDir = tempfile .mkdtemp ()
23
23
24
24
def getDatePrefix (self , postfixDash = True ):
25
- if ( postfixDash is True ) :
25
+ if postfixDash is True :
26
26
return datetime .now ().strftime ("%Y-%m-%d-" )
27
27
else :
28
28
return datetime .now ().strftime ("%Y-%m-%d" )
29
29
30
30
def directoryFileCount (self , directory ):
31
- return len ([item for item in os .listdir (directory ) if os .path .isfile (os .path .join (directory , item ))])
31
+ return len (
32
+ [
33
+ item
34
+ for item in os .listdir (directory )
35
+ if os .path .isfile (os .path .join (directory , item ))
36
+ ]
37
+ )
32
38
33
39
def directoryDirCount (self , directory ):
34
- return len ([item for item in os .listdir (directory ) if os .path .isdir (os .path .join (directory , item ))])
40
+ return len (
41
+ [
42
+ item
43
+ for item in os .listdir (directory )
44
+ if os .path .isdir (os .path .join (directory , item ))
45
+ ]
46
+ )
35
47
36
48
def getOriginalScriptPath (self ):
37
49
module_path = inspect .getfile (inspect .currentframe ())
38
- module_path = os .path .join (os .path .dirname (os .path .dirname (module_path )), 'normfn' )
50
+ module_path = os .path .join (
51
+ os .path .dirname (os .path .dirname (module_path )), "normfn"
52
+ )
39
53
40
54
return module_path
41
55
42
56
def invokeDirectly (self , inputFiles , extraParams = []):
43
57
import importlib .machinery
58
+
44
59
module_path = self .getOriginalScriptPath ()
45
- loader = importlib .machinery .SourceFileLoader (' normfn' , module_path )
60
+ loader = importlib .machinery .SourceFileLoader (" normfn" , module_path )
46
61
spec = spec_from_loader (os .path .basename (module_path ), loader )
47
62
normalize_filename = module_from_spec (spec )
48
63
spec .loader .exec_module (normalize_filename )
@@ -51,11 +66,11 @@ def invokeDirectly(self, inputFiles, extraParams=[]):
51
66
52
67
options .extend (inputFiles )
53
68
options .extend (extraParams )
54
- options .extend ([' --no-undo-log-file' ])
69
+ options .extend ([" --no-undo-log-file" ])
55
70
56
71
stream = io .StringIO ()
57
72
handler = logging .StreamHandler (stream )
58
- log = logging .getLogger (' normfn' )
73
+ log = logging .getLogger (" normfn" )
59
74
log .propagate = False
60
75
log .setLevel (logging .DEBUG )
61
76
log .addHandler (handler )
@@ -70,21 +85,29 @@ def invokeDirectly(self, inputFiles, extraParams=[]):
70
85
71
86
return error
72
87
73
- def invokeAsSubprocess (self , inputFiles , extraParams = [], feedInput = None , cwd = None , expectOutput = False , useUndoFile = False ):
88
+ def invokeAsSubprocess (
89
+ self ,
90
+ inputFiles ,
91
+ extraParams = [],
92
+ feedInput = None ,
93
+ cwd = None ,
94
+ expectOutput = False ,
95
+ useUndoFile = False ,
96
+ ):
74
97
if cwd is None :
75
98
cwd = self .workingDir
76
99
77
100
with tempfile .NamedTemporaryFile (delete = False ) as undo_log_file :
78
101
undo_log_file .close ()
79
102
80
103
if os .name == "nt" :
81
- options = [' python' , NormalizeFilenameTestCase .COMMAND ]
104
+ options = [" python" , NormalizeFilenameTestCase .COMMAND ]
82
105
else :
83
106
options = [NormalizeFilenameTestCase .COMMAND ]
84
107
85
108
options .extend (inputFiles )
86
109
options .extend (extraParams )
87
- options .extend ([' --undo-log-file=' + undo_log_file .name ])
110
+ options .extend ([" --undo-log-file=" + undo_log_file .name ])
88
111
89
112
if feedInput :
90
113
p = Popen (options , stdin = PIPE , stdout = PIPE , stderr = PIPE , cwd = cwd )
@@ -122,13 +145,19 @@ def executeUndoCommands(self, commands):
122
145
return maxReturnCode
123
146
124
147
@contextmanager
125
- def invokeAsPexpect (self , inputFiles , extraParams = [], expectedExitStatus = None , expectedOutputRegex = None ):
148
+ def invokeAsPexpect (
149
+ self ,
150
+ inputFiles ,
151
+ extraParams = [],
152
+ expectedExitStatus = None ,
153
+ expectedOutputRegex = None ,
154
+ ):
126
155
options = [NormalizeFilenameTestCase .COMMAND ]
127
156
options .extend (inputFiles )
128
157
options .extend (extraParams )
129
- options .extend ([' --no-undo-log-file' ])
158
+ options .extend ([" --no-undo-log-file" ])
130
159
131
- command = ' ' .join (options )
160
+ command = " " .join (options )
132
161
133
162
stream = io .BytesIO ()
134
163
@@ -144,18 +173,20 @@ def invokeAsPexpect(self, inputFiles, extraParams=[], expectedExitStatus=None, e
144
173
self .assertEqual (expectedExitStatus , child .exitstatus )
145
174
146
175
if expectedOutputRegex is not None :
147
- self .assertRegex (str (child .logfile_read .getvalue (), 'utf-8' ), expectedOutputRegex )
176
+ self .assertRegex (
177
+ str (child .logfile_read .getvalue (), "utf-8" ), expectedOutputRegex
178
+ )
148
179
149
180
def touch (self , fname ):
150
181
os .makedirs (os .path .dirname (fname ), exist_ok = True )
151
- open (fname , 'w' ).close ()
182
+ open (fname , "w" ).close ()
152
183
153
184
def remove_dir_write_permissions (self , fname ):
154
185
os .chmod (fname , S_IRUSR | S_IXUSR )
155
186
156
187
def writeFile (self , fname , contents ):
157
188
os .makedirs (os .path .dirname (fname ), exist_ok = True )
158
- with open (fname , 'w' ) as filename :
189
+ with open (fname , "w" ) as filename :
159
190
filename .write (contents )
160
191
161
192
def readFile (self , fname ):
0 commit comments