Index: Lib/distutils/tests/test_archive_util.py =================================================================== --- Lib/distutils/tests/test_archive_util.py (revision 74029) +++ Lib/distutils/tests/test_archive_util.py (working copy) @@ -19,10 +19,18 @@ except ImportError: ZIP_SUPPORT = find_executable('zip') +# some tests will fail if zlib is not available +try: + import zlib +except ImportError: + zlib = None + + class ArchiveUtilTestCase(support.TempdirManager, support.LoggingSilencer, unittest.TestCase): + @unittest.skipUnless(zlib, "Requires zlib") def test_make_tarball(self): # creating something to tar tmpdir = self.mkdtemp() @@ -83,6 +91,7 @@ base_name = os.path.join(tmpdir2, 'archive') return tmpdir, tmpdir2, base_name + @unittest.skipUnless(zlib, "Requires zlib") @unittest.skipUnless(find_executable('tar') and find_executable('gzip'), 'Need the tar command to run') def test_tarfile_vs_tar(self): @@ -168,6 +177,7 @@ self.assertTrue(not os.path.exists(tarball)) self.assertEquals(len(w.warnings), 1) + @unittest.skipUnless(zlib, "Requires zlib") @unittest.skipUnless(ZIP_SUPPORT, 'Need zip support to run') def test_make_zipfile(self): # creating something to tar Index: Lib/distutils/tests/test_bdist_dumb.py =================================================================== --- Lib/distutils/tests/test_bdist_dumb.py (revision 74029) +++ Lib/distutils/tests/test_bdist_dumb.py (working copy) @@ -4,6 +4,15 @@ import sys import os +# zlib is not used here, but if it's not available +# test_simple_built will fail +try: + import zlib +except ImportError: + zlib = None + +from unittest import skipUnless + from distutils.core import Distribution from distutils.command.bdist_dumb import bdist_dumb from distutils.tests import support @@ -31,6 +40,7 @@ sys.argv = self.old_sys_argv[:] super(BuildDumbTestCase, self).tearDown() + @skipUnless(zlib, "requires zlib") def test_simple_built(self): # let's create a simple package Index: Lib/distutils/tests/test_sdist.py =================================================================== --- Lib/distutils/tests/test_sdist.py (revision 74029) +++ Lib/distutils/tests/test_sdist.py (working copy) @@ -3,11 +3,21 @@ import unittest import shutil import zipfile + +# zlib is not used here, but if it's not available +# the tests that use zipfile may fail +try: + import zlib +except ImportError: + zlib = None + from os.path import join import sys import tempfile import warnings +from unittest import skipUnless + from test.test_support import check_warnings from test.test_support import captured_stdout @@ -79,6 +89,7 @@ cmd.warn = _warn return dist, cmd + @skipUnless(zlib, "requires zlib") def test_prune_file_list(self): # this test creates a package with some vcs dirs in it # and launch sdist to make sure they get pruned @@ -120,6 +131,7 @@ # making sure everything has been pruned correctly self.assertEquals(len(content), 4) + @skipUnless(zlib, "requires zlib") def test_make_distribution(self): # check if tar and gzip are installed @@ -156,6 +168,7 @@ self.assertEquals(result, ['fake-1.0.tar', 'fake-1.0.tar.gz']) + @skipUnless(zlib, "requires zlib") def test_add_defaults(self): # http://bugs.python.org/issue2279 @@ -217,6 +230,7 @@ manifest = open(join(self.tmp_dir, 'MANIFEST')).read() self.assertEquals(manifest, MANIFEST % {'sep': os.sep}) + @skipUnless(zlib, "requires zlib") def test_metadata_check_option(self): # testing the `medata-check` option dist, cmd = self.get_cmd(metadata={}) Index: Lib/test/test_gzip.py =================================================================== --- Lib/test/test_gzip.py (revision 74029) +++ Lib/test/test_gzip.py (working copy) @@ -5,10 +5,9 @@ import unittest from test import test_support import os -import gzip import struct +gzip = test_support.import_module('gzip') - data1 = """ int length=DEFAULTALLOC, err = Z_OK; PyObject *RetVal; int flushmode = Z_FINISH; Index: Lib/test/test_zipimport.py =================================================================== --- Lib/test/test_zipimport.py (revision 74029) +++ Lib/test/test_zipimport.py (working copy) @@ -6,11 +6,12 @@ import time import unittest -import zlib # implied prerequisite -from zipfile import ZipFile, ZipInfo, ZIP_STORED, ZIP_DEFLATED from test import test_support from test.test_importhooks import ImportHooksBaseTestCase, test_src, test_co +zlib = test_support.import_module('zlib') +from zipfile import ZipFile, ZipInfo, ZIP_STORED, ZIP_DEFLATED + import zipimport import linecache import doctest Index: Lib/test/test_zipfile.py =================================================================== --- Lib/test/test_zipfile.py (revision 74029) +++ Lib/test/test_zipfile.py (working copy) @@ -311,6 +311,7 @@ self.assertEqual(zipfp.read(TESTFN), file(TESTFN).read()) zipfp.close() + @skipUnless(zlib, "requires zlib") def test_per_file_compression(self): # Check that files within a Zip archive can have different compression options zipfp = zipfile.ZipFile(TESTFN2, "w") @@ -872,6 +873,7 @@ self.zip2.setpassword("perl") self.assertRaises(RuntimeError, self.zip2.read, "zero") + @skipUnless(zlib, "requires zlib") def test_good_password(self): self.zip.setpassword("python") self.assertEquals(self.zip.read("test.txt"), self.plain) @@ -972,6 +974,7 @@ self.zip_random_open_test(f, zipfile.ZIP_STORED) +@skipUnless(zlib, "requires zlib") class TestsWithMultipleOpens(unittest.TestCase): def setUp(self): # Create the ZIP archive