summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2009-07-08 22:24:06 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2009-07-08 22:24:06 (GMT)
commit74c96ec39920380ce081c3bd078e9045c95fcc34 (patch)
tree4487b93d39b2cfccd197d0ea7c1d16cbf9a8984e /Lib/test
parent9b102035371d73e44d6ae28620a8e2dc106336b1 (diff)
downloadcpython-74c96ec39920380ce081c3bd078e9045c95fcc34.zip
cpython-74c96ec39920380ce081c3bd078e9045c95fcc34.tar.gz
cpython-74c96ec39920380ce081c3bd078e9045c95fcc34.tar.bz2
Merged revisions 73841 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r73841 | ezio.melotti | 2009-07-04 17:58:27 +0300 (Sat, 04 Jul 2009) | 1 line if zlib -> skipUnless(zlib) and minor cleanups ........
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_zipfile.py92
1 files changed, 54 insertions, 38 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index ed800c5..4b9a2b0 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -3,12 +3,20 @@ try:
import zlib
except ImportError:
zlib = None
-import zipfile, os, unittest, sys, shutil, struct, io
+
+import io
+import os
+import shutil
+import struct
+import zipfile
+import unittest
+
from tempfile import TemporaryFile
from random import randint, random
+from unittest import skipUnless
-import test.support as support
+from test import support
from test.support import TESTFN, run_unittest, findfile
TESTFN2 = TESTFN + "2"
@@ -210,43 +218,51 @@ class TestsWithSourceFile(unittest.TestCase):
for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
self.zipIterlinesTest(f, zipfile.ZIP_STORED)
- if zlib:
- def testDeflated(self):
- for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
- self.zipTest(f, zipfile.ZIP_DEFLATED)
+ @skipUnless(zlib, "requires zlib")
+ def testDeflated(self):
+ for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
+ self.zipTest(f, zipfile.ZIP_DEFLATED)
- def testOpenDeflated(self):
- for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
- self.zipOpenTest(f, zipfile.ZIP_DEFLATED)
- def testRandomOpenDeflated(self):
- for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
- self.zipRandomOpenTest(f, zipfile.ZIP_DEFLATED)
+ @skipUnless(zlib, "requires zlib")
+ def testOpenDeflated(self):
+ for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
+ self.zipOpenTest(f, zipfile.ZIP_DEFLATED)
- def testReadlineDeflated(self):
- for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
- self.zipReadlineTest(f, zipfile.ZIP_DEFLATED)
+ @skipUnless(zlib, "requires zlib")
+ def testRandomOpenDeflated(self):
+ for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
+ self.zipRandomOpenTest(f, zipfile.ZIP_DEFLATED)
- def testReadlinesDeflated(self):
- for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
- self.zipReadlinesTest(f, zipfile.ZIP_DEFLATED)
+ @skipUnless(zlib, "requires zlib")
+ def testReadlineDeflated(self):
+ for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
+ self.zipReadlineTest(f, zipfile.ZIP_DEFLATED)
- def testIterlinesDeflated(self):
- for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
- self.zipIterlinesTest(f, zipfile.ZIP_DEFLATED)
+ @skipUnless(zlib, "requires zlib")
+ def testReadlinesDeflated(self):
+ for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
+ self.zipReadlinesTest(f, zipfile.ZIP_DEFLATED)
+
+ @skipUnless(zlib, "requires zlib")
+ def testIterlinesDeflated(self):
+ for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
+ self.zipIterlinesTest(f, zipfile.ZIP_DEFLATED)
+
+ @skipUnless(zlib, "requires zlib")
+ def testLowCompression(self):
+ # Checks for cases where compressed data is larger than original
+ # Create the ZIP archive
+ zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_DEFLATED)
+ zipfp.writestr("strfile", '12')
+ zipfp.close()
- def testLowCompression(self):
- # Checks for cases where compressed data is larger than original
- # Create the ZIP archive
- zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_DEFLATED)
- zipfp.writestr("strfile", '12')
- zipfp.close()
+ # Get an open object for strfile
+ zipfp = zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_DEFLATED)
+ openobj = zipfp.open("strfile")
+ self.assertEqual(openobj.read(1), b'1')
+ self.assertEqual(openobj.read(1), b'2')
- # Get an open object for strfile
- zipfp = zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_DEFLATED)
- openobj = zipfp.open("strfile")
- self.assertEqual(openobj.read(1), b'1')
- self.assertEqual(openobj.read(1), b'2')
def testAbsoluteArcnames(self):
zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED)
@@ -388,8 +404,8 @@ class TestsWithSourceFile(unittest.TestCase):
orig_zip.close()
def tearDown(self):
- os.remove(TESTFN)
- os.remove(TESTFN2)
+ support.unlink(TESTFN)
+ support.unlink(TESTFN2)
class TestZip64InSmallFiles(unittest.TestCase):
# These tests test the ZIP64 functionality without using large files,
@@ -506,8 +522,8 @@ class TestZip64InSmallFiles(unittest.TestCase):
def tearDown(self):
zipfile.ZIP64_LIMIT = self._limit
- os.remove(TESTFN)
- os.remove(TESTFN2)
+ support.unlink(TESTFN)
+ support.unlink(TESTFN2)
class PyZipFileTests(unittest.TestCase):
def testWritePyfile(self):
@@ -1007,7 +1023,7 @@ class TestsWithMultipleOpens(unittest.TestCase):
zipf.close()
def tearDown(self):
- os.remove(TESTFN2)
+ support.unlink(TESTFN2)
class TestWithDirectory(unittest.TestCase):
def setUp(self):
@@ -1034,7 +1050,7 @@ class TestWithDirectory(unittest.TestCase):
def tearDown(self):
shutil.rmtree(TESTFN2)
if os.path.exists(TESTFN):
- os.remove(TESTFN)
+ support.unlink(TESTFN)
class UniversalNewlineTests(unittest.TestCase):