classification
Title: test_(zipfile|zipimport|gzip|distutils|sqlite) fail if zlib is not available
Type: behavior Stage: committed/rejected
Components: Tests Versions: Python 3.1, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: amaury.forgeotdarc, ezio.melotti, nicdumz (3)
Priority: normal Keywords

Created on 2009-05-15 00:58 by ezio.melotti, last changed 2009-09-12 18:46 by ezio.melotti.

Files
File name Uploaded Description Edit Remove
issue6026.diff ezio.melotti, 2009-07-17 02:40 Patch against the trunk for test_(zipfile|zipimport|gzip|distutils)
issue6026-2.diff ezio.melotti, 2009-07-20 00:11 Patch against the trunk for test_(zipfile|zipimport|gzip|distutils|sqlite)
Messages (9)
msg87783 - (view) Author: Ezio Melotti (ezio.melotti) Date: 2009-05-15 00:58
Python build finished, but the necessary bits to build these modules
were not found: _dbm _gdbm _hashlib _sqlite3 _ssl _tkinter bz2 zlib


When zlib is missing some tests fail:

./python -m test.regrtest -uall -v test_zipimport
Could not find '/home/wolf/py3k/Lib/test' in sys.path to remove it
test_zipimport
test test_zipimport crashed -- <class 'ImportError'>: No module named zlib
Traceback (most recent call last):
  File "/home/wolf/py3k/Lib/test/regrtest.py", line 613, in runtest_inner
    the_package = __import__(abstest, globals(), locals(), [])
  File "/home/wolf/py3k/Lib/test/test_zipimport.py", line 9, in <module>
    import zlib # implied prerequisite
ImportError: No module named zlib
1 test failed:
    test_zipimport


./python -m test.regrtest -uall -v test_zipfile
Could not find '/home/wolf/py3k/Lib/test' in sys.path to remove it
test_zipfile
testAbsoluteArcnames (test.test_zipfile.TestsWithSourceFile) ... ok
[...]
 
======================================================================
ERROR: test_PerFileCompression (test.test_zipfile.TestsWithSourceFile)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/wolf/py3k/Lib/test/test_zipfile.py", line 300, in
test_PerFileCompression
    zipfp.write(TESTFN, 'deflateme', zipfile.ZIP_DEFLATED)
  File "/home/wolf/py3k/Lib/zipfile.py", line 1045, in write
    self._writecheck(zinfo)
  File "/home/wolf/py3k/Lib/zipfile.py", line 1004, in _writecheck
    "Compression requires the (missing) zlib module")
RuntimeError: Compression requires the (missing) zlib module
 
======================================================================
ERROR: testGoodPassword (test.test_zipfile.DecryptionTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/wolf/py3k/Lib/test/test_zipfile.py", line 856, in
testGoodPassword
    self.assertEquals(self.zip2.read("zero"), self.plain2)
  File "/home/wolf/py3k/Lib/zipfile.py", line 850, in read
    return self.open(name, "r", pwd).read()
  File "/home/wolf/py3k/Lib/zipfile.py", line 923, in open
    zef = ZipExtFile(zef_file, zinfo, zd)
  File "/home/wolf/py3k/Lib/zipfile.py", line 470, in __init__
    self.dc = zlib.decompressobj(-15)
AttributeError: 'NoneType' object has no attribute 'decompressobj'
 
======================================================================
ERROR: testDifferentFile (test.test_zipfile.TestsWithMultipleOpens)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/wolf/py3k/Lib/test/test_zipfile.py", line 955, in setUp
    zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_DEFLATED)
  File "/home/wolf/py3k/Lib/zipfile.py", line 669, in __init__
    "Compression requires the (missing) zlib module")
RuntimeError: Compression requires the (missing) zlib module
 
======================================================================
ERROR: testInterleaved (test.test_zipfile.TestsWithMultipleOpens)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/wolf/py3k/Lib/test/test_zipfile.py", line 955, in setUp
    zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_DEFLATED)
  File "/home/wolf/py3k/Lib/zipfile.py", line 669, in __init__
    "Compression requires the (missing) zlib module")
RuntimeError: Compression requires the (missing) zlib module
 
======================================================================
ERROR: testSameFile (test.test_zipfile.TestsWithMultipleOpens)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/wolf/py3k/Lib/test/test_zipfile.py", line 955, in setUp
    zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_DEFLATED)
  File "/home/wolf/py3k/Lib/zipfile.py", line 669, in __init__
    "Compression requires the (missing) zlib module")
RuntimeError: Compression requires the (missing) zlib module
 
----------------------------------------------------------------------
Ran 53 tests in 1.292s
 
FAILED (errors=5)
test test_zipfile failed -- errors occurred; run in verbose mode for details
1 test failed:
    test_zipfile


./python -m test.regrtest -uall -v test_gzip
Could not find '/home/wolf/py3k/Lib/test' in sys.path to remove it
test_gzip
test test_gzip crashed -- <class 'ImportError'>: No module named zlib
Traceback (most recent call last):
  File "/home/wolf/py3k/Lib/test/regrtest.py", line 613, in runtest_inner
    the_package = __import__(abstest, globals(), locals(), [])
  File "/home/wolf/py3k/Lib/test/test_gzip.py", line 8, in <module>
    import gzip
  File "/home/wolf/py3k/Lib/gzip.py", line 9, in <module>
    import zlib
ImportError: No module named zlib
1 test failed:
    test_gzip


./python -m test.regrtest -uall -v test_distutils
Could not find '/home/wolf/py3k/Lib/test' in sys.path to remove it
test_distutils
test_check_all (distutils.tests.test_check.CheckTestCase) ... ok
[...]
 
======================================================================
ERROR: test_simple_built (distutils.tests.test_bdist_dumb.BuildDumbTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/wolf/py3k/Lib/distutils/tests/test_bdist_dumb.py", line
62, in test_simple_built
    cmd.run()
  File "/home/wolf/py3k/Lib/distutils/command/bdist_dumb.py", line 111,
in run
    self.format, root_dir=archive_root)
  File "/home/wolf/py3k/Lib/distutils/cmd.py", line 372, in make_archive
    dry_run=self.dry_run)
  File "/home/wolf/py3k/Lib/distutils/archive_util.py", line 160, in
make_archive
    filename = func(base_name, base_dir, **kwargs)
  File "/home/wolf/py3k/Lib/distutils/archive_util.py", line 97, in
make_zipfile
    compression=zipfile.ZIP_DEFLATED)
  File "/home/wolf/py3k/Lib/zipfile.py", line 669, in __init__
    "Compression requires the (missing) zlib module")
RuntimeError: Compression requires the (missing) zlib module
 
======================================================================
ERROR: test_add_defaults (distutils.tests.test_sdist.sdistTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/wolf/py3k/Lib/distutils/tests/test_sdist.py", line 193, in
test_add_defaults
    cmd.run()
  File "/home/wolf/py3k/Lib/distutils/command/sdist.py", line 150, in run
    self.make_distribution()
  File "/home/wolf/py3k/Lib/distutils/command/sdist.py", line 464, in
make_distribution
    file = self.make_archive(base_name, fmt, base_dir=base_dir)
  File "/home/wolf/py3k/Lib/distutils/cmd.py", line 372, in make_archive
    dry_run=self.dry_run)
  File "/home/wolf/py3k/Lib/distutils/archive_util.py", line 160, in
make_archive
    filename = func(base_name, base_dir, **kwargs)
  File "/home/wolf/py3k/Lib/distutils/archive_util.py", line 97, in
make_zipfile
    compression=zipfile.ZIP_DEFLATED)
  File "/home/wolf/py3k/Lib/zipfile.py", line 669, in __init__
    "Compression requires the (missing) zlib module")
RuntimeError: Compression requires the (missing) zlib module
 
======================================================================
ERROR: test_prune_file_list (distutils.tests.test_sdist.sdistTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/wolf/py3k/Lib/distutils/tests/test_sdist.py", line 100, in
test_prune_file_list
    cmd.run()
  File "/home/wolf/py3k/Lib/distutils/command/sdist.py", line 150, in run
    self.make_distribution()
  File "/home/wolf/py3k/Lib/distutils/command/sdist.py", line 464, in
make_distribution
    file = self.make_archive(base_name, fmt, base_dir=base_dir)
  File "/home/wolf/py3k/Lib/distutils/cmd.py", line 372, in make_archive
    dry_run=self.dry_run)
  File "/home/wolf/py3k/Lib/distutils/archive_util.py", line 160, in
make_archive
    filename = func(base_name, base_dir, **kwargs)
  File "/home/wolf/py3k/Lib/distutils/archive_util.py", line 97, in
make_zipfile
    compression=zipfile.ZIP_DEFLATED)
  File "/home/wolf/py3k/Lib/zipfile.py", line 669, in __init__
    "Compression requires the (missing) zlib module")
RuntimeError: Compression requires the (missing) zlib module
 
----------------------------------------------------------------------
Ran 108 tests in 0.739s
 
FAILED (errors=3)
test test_distutils failed -- errors occurred; run in verbose mode for
details
1 test failed:
    test_distutils


Should these tests be skipped instead?
msg89999 - (view) Author: Ezio Melotti (ezio.melotti) Date: 2009-07-01 23:30
I tried also with the final release of Python 3.1, but when zlib is
missing only test_zlib is skipped, test_zipfile, test_zipimport,
test_gzip and test_distutils fail.
These tests should check if zlib is available too.
msg90002 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) Date: 2009-07-02 08:27
test_zipfile and test_zipimport should be enabled when zlib is not
available: a zip file can store data uncompressed, and does not need
zlib in this case.
Only disable tests that require compression.
msg90003 - (view) Author: Ezio Melotti (ezio.melotti) Date: 2009-07-02 08:32
I'm working on a patch.
There a few more tests that need to be skipped in test_zipfile when zlib
is not available. test_gzip has to be skipped entirely if zlib is not
available. I still have to look at test_zipimport and test_distutils.
msg90597 - (view) Author: Ezio Melotti (ezio.melotti) Date: 2009-07-17 00:06
Now (Python2.7a0 trunk:74029) there are 3 more tests that fail because
zlib is not available: test_multiprocessing, test_xmlrpc and test_docxmlrpc.
msg90602 - (view) Author: Ezio Melotti (ezio.melotti) Date: 2009-07-17 02:40
The 3 new failures (test_multiprocessing, test_xmplrpc and
test_docxmlrpc) were introduced in r73638 and I opened a new issue about
that (#6499). I'll wait to see if and how they should be fixed (and
possibly open a new issue for them).

The attached patch fixes test_zipfile, test_zipimport, test_gzip and
test_distutils.

I used two techniques to fix these files:
1) checking if zlib was available with
   try:
       import zlib
   except ImportError:
       zlib = None
   and then using @skipUnless(zlib, "requires zlib")
   to skip individual tests/classes
2) using zlib = test_support.import_module('zlib') when
   zlib (or other modules like gzip) was necessary for
   all the tests

The patch includes the following fixes:

In test_zipfile there were 5 tests that were failing. Several other
tests work without zlib too. Fixed adding 3 @skipUnless(zlib, "requires
zlib") to two methods and to the TestsWithMultipleOpens class.

In test_zipimport there are 3 test classes. The 3rd class tests various
errors that are raised when, for example, the file doesn't exists. This
class works without zlib too, but since it's pointless to run it if the
other two don't work I decided to skip everything. Fixed adding zlib =
test_support.import_module('zlib').

In test_gzip all the files require gzip to work, and gzip requires zlib.
Fixed adding gzip = test_support.import_module('gzip').

In test_distutils there are several files affected:
test_sdist: fixed with 4 @skipUnless(zlib, "requires zlib")
test_bdist_dumb: fixed with a @skipUnless(zlib, "requires zlib")
test_archive_util: fixed with 3 @skipUnless(zlib, "requires zlib")

If the patch is good I'll commit it.
msg90716 - (view) Author: Ezio Melotti (ezio.melotti) Date: 2009-07-20 00:11
Here's a new patch.

I added a could of @skipUnless in test_sqlite because two tests were
failing. 
I couldn't notice this before because I didn't have _sqlite3 and these
tests were skipped. Thanks to R. David Murray for reporting the problem.

In test_zipimport, the tests in 2/3 of the classes can be executed when
zlib is missing (and not only 1/3 as I initially thought). Removed zlib
= test_support.import_module('zlib') and added a @skipUnless(zlib,
"requires zlib"). Thanks again to David for this.

test_multiprocessing, test_xmplrpc and test_docxmlrpc were fixed in
#6499, so they are not part of this issue anymore.
msg91927 - (view) Author: Nicolas Dumazet (nicdumz) Date: 2009-08-24 17:20
Great, I don't know how I missed that bug.

It looks really similar to the patch I had written at
http://codereview.appspot.com/111041

So your patch looks correct to me, and does solve the issue locally.
msg92551 - (view) Author: Ezio Melotti (ezio.melotti) Date: 2009-09-12 18:46
Fixed in r74754 (trunk) and r74755 (py3k).
History
Date User Action Args
2009-09-12 18:46:50ezio.melottisetstatus: open -> closed
messages: + msg92551

keywords: - patch, needs review
resolution: fixed
stage: patch review -> committed/rejected
2009-08-24 17:20:05nicdumzsetnosy: + nicdumz
messages: + msg91927
2009-08-24 15:56:41r.david.murraylinkissue6776 superseder
2009-07-22 22:37:47ezio.melottisetdependencies: - Can't import xmlrpclib, DocXMLRPCServer and SimpleXMLRPCServer when zlib is not available
2009-07-20 00:12:28ezio.melottisetkeywords: + patch
2009-07-20 00:11:05ezio.melottisetkeywords: - patch
files: + issue6026-2.diff
messages: + msg90716

title: test_(zipfile|zipimport|gzip|distutils|multiprocessing|xmlrpc|docxmlrpc) fail if zlib is not available -> test_(zipfile|zipimport|gzip|distutils|sqlite) fail if zlib is not available
2009-07-17 02:40:28ezio.melottisetfiles: + issue6026.diff
messages: + msg90602

dependencies: + Can't import xmlrpclib, DocXMLRPCServer and SimpleXMLRPCServer when zlib is not available
keywords: + needs review, patch
stage: needs patch -> patch review
2009-07-17 00:06:17ezio.melottisetmessages: + msg90597
title: test_(zipfile|zipimport|gzip|distutils) fail if zlib is not available -> test_(zipfile|zipimport|gzip|distutils|multiprocessing|xmlrpc|docxmlrpc) fail if zlib is not available
2009-07-02 08:32:08ezio.melottisetmessages: + msg90003
versions: + Python 2.7
2009-07-02 08:27:49amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg90002
2009-07-02 00:11:31ezio.melottisetpriority: normal
assignee: ezio.melotti
stage: needs patch
2009-07-01 23:30:30ezio.melottisetmessages: + msg89999
2009-05-15 00:58:25ezio.melotticreate