3030except ImportError :
3131 ZIP_SUPPORT = find_executable ('zip' )
3232
33- try :
34- import zlib
35- ZLIB_SUPPORT = True
36- except ImportError :
37- ZLIB_SUPPORT = False
33+ import zlib
3834
3935try :
4036 import bz2
@@ -63,15 +59,13 @@ class ArchiveUtilTestCase(support.TempdirManager,
6359 support .LoggingSilencer ,
6460 unittest .TestCase ):
6561
66- @unittest .skipUnless (ZLIB_SUPPORT , 'Need zlib support to run' )
6762 def test_make_tarball (self , name = 'archive' ):
6863 # creating something to tar
6964 tmpdir = self ._create_files ()
7065 self ._make_tarball (tmpdir , name , '.tar.gz' )
7166 # trying an uncompressed one
7267 self ._make_tarball (tmpdir , name , '.tar' , compress = None )
7368
74- @unittest .skipUnless (ZLIB_SUPPORT , 'Need zlib support to run' )
7569 def test_make_tarball_gzip (self ):
7670 tmpdir = self ._create_files ()
7771 self ._make_tarball (tmpdir , 'archive' , '.tar.gz' , compress = 'gzip' )
@@ -144,9 +138,8 @@ def _create_files(self):
144138 os .mkdir (os .path .join (dist , 'sub2' ))
145139 return tmpdir
146140
147- @unittest .skipUnless (find_executable ('tar' ) and find_executable ('gzip' )
148- and ZLIB_SUPPORT ,
149- 'Need the tar, gzip and zlib command to run' )
141+ @unittest .skipUnless (find_executable ('tar' ) and find_executable ('gzip' ),
142+ 'Need the tar and gzip commands to run' )
150143 def test_tarfile_vs_tar (self ):
151144 tmpdir = self ._create_files ()
152145 tmpdir2 = self .mkdtemp ()
@@ -234,8 +227,7 @@ def test_compress_deprecated(self):
234227 self .assertFalse (os .path .exists (tarball ))
235228 self .assertEqual (len (w .warnings ), 1 )
236229
237- @unittest .skipUnless (ZIP_SUPPORT and ZLIB_SUPPORT ,
238- 'Need zip and zlib support to run' )
230+ @unittest .skipUnless (ZIP_SUPPORT , 'Need zip support to run' )
239231 def test_make_zipfile (self ):
240232 # creating something to tar
241233 tmpdir = self ._create_files ()
@@ -249,32 +241,6 @@ def test_make_zipfile(self):
249241 with zipfile .ZipFile (tarball ) as zf :
250242 self .assertEqual (sorted (zf .namelist ()), self ._zip_created_files )
251243
252- @unittest .skipUnless (ZIP_SUPPORT , 'Need zip support to run' )
253- def test_make_zipfile_no_zlib (self ):
254- patch (self , archive_util .zipfile , 'zlib' , None ) # force zlib ImportError
255-
256- called = []
257- zipfile_class = zipfile .ZipFile
258- def fake_zipfile (* a , ** kw ):
259- if kw .get ('compression' , None ) == zipfile .ZIP_STORED :
260- called .append ((a , kw ))
261- return zipfile_class (* a , ** kw )
262-
263- patch (self , archive_util .zipfile , 'ZipFile' , fake_zipfile )
264-
265- # create something to tar and compress
266- tmpdir = self ._create_files ()
267- base_name = os .path .join (self .mkdtemp (), 'archive' )
268- with change_cwd (tmpdir ):
269- make_zipfile (base_name , 'dist' )
270-
271- tarball = base_name + '.zip'
272- self .assertEqual (called ,
273- [((tarball , "w" ), {'compression' : zipfile .ZIP_STORED })])
274- self .assertTrue (os .path .exists (tarball ))
275- with zipfile .ZipFile (tarball ) as zf :
276- self .assertEqual (sorted (zf .namelist ()), self ._zip_created_files )
277-
278244 def test_check_archive_formats (self ):
279245 self .assertEqual (check_archive_formats (['gztar' , 'xxx' , 'zip' ]),
280246 'xxx' )
@@ -308,7 +274,6 @@ def test_make_archive_tar(self):
308274 self .assertEqual (os .path .basename (res ), 'archive.tar' )
309275 self .assertEqual (self ._tarinfo (res ), self ._created_files )
310276
311- @unittest .skipUnless (ZLIB_SUPPORT , 'Need zlib support to run' )
312277 def test_make_archive_gztar (self ):
313278 base_dir = self ._create_files ()
314279 base_name = os .path .join (self .mkdtemp () , 'archive' )
@@ -362,7 +327,6 @@ def test_make_archive_owner_group(self):
362327 owner = 'kjhkjhkjg' , group = 'oihohoh' )
363328 self .assertTrue (os .path .exists (res ))
364329
365- @unittest .skipUnless (ZLIB_SUPPORT , "Requires zlib" )
366330 @unittest .skipUnless (UID_GID_SUPPORT , "Requires grp and pwd support" )
367331 def test_tarfile_root_owner (self ):
368332 tmpdir = self ._create_files ()
0 commit comments