Skip to content

Commit 78ea202

Browse files
committed
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 ........
1 parent 049d2aa commit 78ea202

7 files changed

Lines changed: 51 additions & 6 deletions

File tree

Lib/distutils/tests/test_archive_util.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@
1919
except ImportError:
2020
ZIP_SUPPORT = find_executable('zip')
2121

22+
# some tests will fail if zlib is not available
23+
try:
24+
import zlib
25+
except ImportError:
26+
zlib = None
27+
28+
2229
class ArchiveUtilTestCase(support.TempdirManager,
2330
support.LoggingSilencer,
2431
unittest.TestCase):
2532

33+
@unittest.skipUnless(zlib, "Requires zlib")
2634
def test_make_tarball(self):
2735
# creating something to tar
2836
tmpdir = self.mkdtemp()
@@ -83,6 +91,7 @@ def _create_files(self):
8391
base_name = os.path.join(tmpdir2, 'archive')
8492
return tmpdir, tmpdir2, base_name
8593

94+
@unittest.skipUnless(zlib, "Requires zlib")
8695
@unittest.skipUnless(find_executable('tar') and find_executable('gzip'),
8796
'Need the tar command to run')
8897
def test_tarfile_vs_tar(self):
@@ -168,6 +177,7 @@ def test_compress_deprecated(self):
168177
self.assertTrue(not os.path.exists(tarball))
169178
self.assertEquals(len(w.warnings), 1)
170179

180+
@unittest.skipUnless(zlib, "Requires zlib")
171181
@unittest.skipUnless(ZIP_SUPPORT, 'Need zip support to run')
172182
def test_make_zipfile(self):
173183
# creating something to tar

Lib/distutils/tests/test_bdist_dumb.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
import sys
55
import os
66

7+
# zlib is not used here, but if it's not available
8+
# test_simple_built will fail
9+
try:
10+
import zlib
11+
except ImportError:
12+
zlib = None
13+
714
from distutils.core import Distribution
815
from distutils.command.bdist_dumb import bdist_dumb
916
from distutils.tests import support
@@ -31,6 +38,7 @@ def tearDown(self):
3138
sys.argv = self.old_sys_argv[:]
3239
super(BuildDumbTestCase, self).tearDown()
3340

41+
@unittest.skipUnless(zlib, "requires zlib")
3442
def test_simple_built(self):
3543

3644
# let's create a simple package

Lib/distutils/tests/test_sdist.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
import unittest
44
import shutil
55
import zipfile
6+
7+
# zlib is not used here, but if it's not available
8+
# the tests that use zipfile may fail
9+
try:
10+
import zlib
11+
except ImportError:
12+
zlib = None
13+
614
from os.path import join
715
import sys
816
import tempfile
@@ -79,6 +87,7 @@ def _warn(*args):
7987
cmd.warn = _warn
8088
return dist, cmd
8189

90+
@unittest.skipUnless(zlib, "requires zlib")
8291
def test_prune_file_list(self):
8392
# this test creates a package with some vcs dirs in it
8493
# and launch sdist to make sure they get pruned
@@ -120,6 +129,7 @@ def test_prune_file_list(self):
120129
# making sure everything has been pruned correctly
121130
self.assertEquals(len(content), 4)
122131

132+
@unittest.skipUnless(zlib, "requires zlib")
123133
def test_make_distribution(self):
124134

125135
# check if tar and gzip are installed
@@ -156,6 +166,7 @@ def test_make_distribution(self):
156166
self.assertEquals(result,
157167
['fake-1.0.tar', 'fake-1.0.tar.gz'])
158168

169+
@unittest.skipUnless(zlib, "requires zlib")
159170
def test_add_defaults(self):
160171

161172
# http://bugs.python.org/issue2279
@@ -217,6 +228,7 @@ def test_add_defaults(self):
217228
manifest = open(join(self.tmp_dir, 'MANIFEST')).read()
218229
self.assertEquals(manifest, MANIFEST % {'sep': os.sep})
219230

231+
@unittest.skipUnless(zlib, "requires zlib")
220232
def test_metadata_check_option(self):
221233
# testing the `medata-check` option
222234
dist, cmd = self.get_cmd(metadata={})

Lib/sqlite3/test/types.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@
2121
# misrepresented as being the original software.
2222
# 3. This notice may not be removed or altered from any source distribution.
2323

24-
import zlib, datetime
24+
import datetime
2525
import unittest
2626
import sqlite3 as sqlite
27+
try:
28+
import zlib
29+
except ImportError:
30+
zlib = None
31+
2732

2833
class SqliteTypeTests(unittest.TestCase):
2934
def setUp(self):
@@ -312,6 +317,7 @@ def CheckCasterIsUsed(self):
312317
val = self.cur.fetchone()[0]
313318
self.assertEqual(type(val), float)
314319

320+
@unittest.skipUnless(zlib, "requires zlib")
315321
class BinaryConverterTests(unittest.TestCase):
316322
def convert(s):
317323
return zlib.decompress(s)

Lib/test/test_gzip.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
import unittest
66
from test import support
77
import os
8-
import gzip
98
import struct
10-
9+
gzip = support.import_module('gzip')
1110

1211
data1 = b""" int length=DEFAULTALLOC, err = Z_OK;
1312
PyObject *RetVal;

Lib/test/test_zipfile.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ def test_write_default_name(self):
307307
self.assertEqual(zipfp.read(TESTFN), open(TESTFN, "rb").read())
308308
zipfp.close()
309309

310+
@skipUnless(zlib, "requires zlib")
310311
def test_per_file_compression(self):
311312
# Check that files within a Zip archive can have different compression options
312313
zipfp = zipfile.ZipFile(TESTFN2, "w")
@@ -881,6 +882,7 @@ def test_bad_password(self):
881882
self.zip2.setpassword(b"perl")
882883
self.assertRaises(RuntimeError, self.zip2.read, "zero")
883884

885+
@skipUnless(zlib, "requires zlib")
884886
def test_good_password(self):
885887
self.zip.setpassword(b"python")
886888
self.assertEquals(self.zip.read("test.txt"), self.plain)
@@ -982,6 +984,7 @@ def test_random_open_stored(self):
982984
self.zip_random_open_test(f, zipfile.ZIP_STORED)
983985

984986

987+
@skipUnless(zlib, "requires zlib")
985988
class TestsWithMultipleOpens(unittest.TestCase):
986989
def setUp(self):
987990
# Create the ZIP archive

Lib/test/test_zipimport.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66
import time
77
import unittest
88

9-
import zlib # implied prerequisite
10-
from zipfile import ZipFile, ZipInfo, ZIP_STORED, ZIP_DEFLATED
119
from test import support
1210
from test.test_importhooks import ImportHooksBaseTestCase, test_src, test_co
1311

12+
# some tests can be ran even without zlib
13+
try:
14+
import zlib
15+
except ImportError:
16+
zlib = None
17+
18+
from zipfile import ZipFile, ZipInfo, ZIP_STORED, ZIP_DEFLATED
19+
1420
import zipimport
1521
import linecache
1622
import doctest
@@ -53,6 +59,7 @@ def module_path_to_dotted_name(path):
5359
TESTPACK2 = "ziptestpackage2"
5460
TEMP_ZIP = os.path.abspath("junk95142.zip")
5561

62+
5663
class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
5764

5865
compression = ZIP_STORED
@@ -354,7 +361,6 @@ def doDoctestSuite(self, module):
354361
def testDoctestSuite(self):
355362
self.runDoctest(self.doDoctestSuite)
356363

357-
358364
def doTraceback(self, module):
359365
try:
360366
module.do_raise()
@@ -378,6 +384,7 @@ def testTraceback(self):
378384
self.doTest(None, files, TESTMOD, call=self.doTraceback)
379385

380386

387+
@unittest.skipUnless(zlib, "requires zlib")
381388
class CompressedZipImportTestCase(UncompressedZipImportTestCase):
382389
compression = ZIP_DEFLATED
383390

0 commit comments

Comments
 (0)