Merged revisions 74754 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r74754 | ezio.melotti | 2009-09-12 17:43:43 +0300 (Sat, 12 Sep 2009) | 1 line

  #6026 - fix tests that failed without zlib
........
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index d928635..fa91dc0 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -5,9 +5,8 @@
 import unittest
 from test import support
 import os
-import gzip
 import struct
-
+gzip = support.import_module('gzip')
 
 data1 = b"""  int length=DEFAULTALLOC, err = Z_OK;
   PyObject *RetVal;
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index b17f857..76be41c 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -307,6 +307,7 @@
         self.assertEqual(zipfp.read(TESTFN), open(TESTFN, "rb").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")
@@ -881,6 +882,7 @@
         self.zip2.setpassword(b"perl")
         self.assertRaises(RuntimeError, self.zip2.read, "zero")
 
+    @skipUnless(zlib, "requires zlib")
     def test_good_password(self):
         self.zip.setpassword(b"python")
         self.assertEquals(self.zip.read("test.txt"), self.plain)
@@ -982,6 +984,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
diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py
index 5d163c7..62440e1 100644
--- a/Lib/test/test_zipimport.py
+++ b/Lib/test/test_zipimport.py
@@ -6,11 +6,17 @@
 import time
 import unittest
 
-import zlib # implied prerequisite
-from zipfile import ZipFile, ZipInfo, ZIP_STORED, ZIP_DEFLATED
 from test import support
 from test.test_importhooks import ImportHooksBaseTestCase, test_src, test_co
 
+# some tests can be ran even without zlib
+try:
+    import zlib
+except ImportError:
+    zlib = None
+
+from zipfile import ZipFile, ZipInfo, ZIP_STORED, ZIP_DEFLATED
+
 import zipimport
 import linecache
 import doctest
@@ -53,6 +59,7 @@
 TESTPACK2 = "ziptestpackage2"
 TEMP_ZIP = os.path.abspath("junk95142.zip")
 
+
 class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
 
     compression = ZIP_STORED
@@ -354,7 +361,6 @@
     def testDoctestSuite(self):
         self.runDoctest(self.doDoctestSuite)
 
-
     def doTraceback(self, module):
         try:
             module.do_raise()
@@ -378,6 +384,7 @@
         self.doTest(None, files, TESTMOD, call=self.doTraceback)
 
 
+@unittest.skipUnless(zlib, "requires zlib")
 class CompressedZipImportTestCase(UncompressedZipImportTestCase):
     compression = ZIP_DEFLATED