@@ -103,7 +103,7 @@ def write_args(fp, args):
103
103
Memory before building targets: 300%(index)s
104
104
Memory after building targets: 400%(index)s
105
105
Object counts:
106
- pre- post- pre- post-
106
+ pre- post- pre- post-
107
107
read read build build Class
108
108
101%(index)s 102%(index)s 103%(index)s 104%(index)s Action.CommandAction
109
109
201%(index)s 202%(index)s 203%(index)s 204%(index)s Action.CommandGeneratorAction
@@ -273,20 +273,16 @@ def write_sample_directory(self, archive, dir, files):
273
273
274
274
def write_sample_tarfile (self , archive , dir , files ):
275
275
import shutil
276
- try :
277
- import tarfile
278
- except ImportError :
279
- self .skip_test ('no tarfile module\n ' , from_framework = True )
280
- else :
281
- base , suffix = self .archive_split (archive )
276
+ import tarfile
277
+ base , suffix = self .archive_split (archive )
282
278
283
- mode = {
284
- '.tar' : 'w' ,
285
- '.tar.gz' : 'w:gz' ,
286
- '.tgz' : 'w:gz' ,
287
- }
279
+ mode = {
280
+ '.tar' : 'w' ,
281
+ '.tar.gz' : 'w:gz' ,
282
+ '.tgz' : 'w:gz' ,
283
+ }
288
284
289
- tar = tarfile .open (archive , mode [suffix ])
285
+ with tarfile .open (archive , mode [suffix ]) as tar :
290
286
for name , content in files :
291
287
path = os .path .join (dir , name )
292
288
with open (path , 'wb' ) as f :
@@ -298,30 +294,20 @@ def write_sample_tarfile(self, archive, dir, files):
298
294
tarinfo .gname = 'fake_group'
299
295
with open (path , 'rb' ) as f :
300
296
tar .addfile (tarinfo , f )
301
- tar .close ()
302
- shutil .rmtree (dir )
303
- return self .workpath (archive )
297
+ shutil .rmtree (dir )
298
+ return self .workpath (archive )
304
299
305
300
def write_sample_zipfile (self , archive , dir , files ):
306
301
import shutil
307
- try :
308
- import zipfile
309
- except ImportError :
310
-
311
- sys .stderr .write ('no zipfile module\n ' )
312
- self .no_result ()
313
-
314
- else :
315
-
316
- zip = zipfile .ZipFile (archive , 'w' )
302
+ import zipfile
303
+ with zipfile .ZipFile (archive , 'w' ) as zip :
317
304
for name , content in files :
318
305
path = os .path .join (dir , name )
319
306
with open (path , 'w' ) as f :
320
307
f .write (content )
321
308
zip .write (path )
322
- zip .close ()
323
- shutil .rmtree (dir )
324
- return self .workpath (archive )
309
+ shutil .rmtree (dir )
310
+ return self .workpath (archive )
325
311
326
312
sample_project_files = [
327
313
('SConstruct' , SConstruct ),
0 commit comments