Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Attributes
test.test_zipfile.TestZip64InSmallFiles Class Reference

List of all members.

Public Member Functions

def setUp
def large_file_exception_test
def large_file_exception_test2
def test_large_file_exception
def zip_test
def test_stored
def test_deflated
def test_absolute_arcnames
def tearDown

Public Attributes

 data

Private Attributes

 _limit

Detailed Description

Definition at line 523 of file test_zipfile.py.


Member Function Documentation

Definition at line 539 of file test_zipfile.py.

00539 
00540     def large_file_exception_test(self, f, compression):
00541         with zipfile.ZipFile(f, "w", compression) as zipfp:
00542             self.assertRaises(zipfile.LargeZipFile,
00543                               zipfp.write, TESTFN, "another.name")

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 544 of file test_zipfile.py.

00544 
00545     def large_file_exception_test2(self, f, compression):
00546         with zipfile.ZipFile(f, "w", compression) as zipfp:
00547             self.assertRaises(zipfile.LargeZipFile,
00548                               zipfp.writestr, "another.name", self.data)
00549         if not isinstance(f, str):
00550             f.close()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 527 of file test_zipfile.py.

00527 
00528     def setUp(self):
00529         self._limit = zipfile.ZIP64_LIMIT
00530         zipfile.ZIP64_LIMIT = 5
00531 
00532         line_gen = (bytes("Test of zipfile line %d." % i, "ascii")
00533                     for i in range(0, FIXEDTEST_SIZE))
00534         self.data = b'\n'.join(line_gen)
00535 
00536         # Make a source file with some lines
00537         with open(TESTFN, "wb") as fp:
00538             fp.write(self.data)

Here is the caller graph for this function:

Definition at line 632 of file test_zipfile.py.

00632 
00633     def tearDown(self):
00634         zipfile.ZIP64_LIMIT = self._limit
00635         unlink(TESTFN)
00636         unlink(TESTFN2)
00637 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 624 of file test_zipfile.py.

00624 
00625     def test_absolute_arcnames(self):
00626         with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED,
00627                              allowZip64=True) as zipfp:
00628             zipfp.write(TESTFN, "/absolute")
00629 
00630         with zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_STORED) as zipfp:
00631             self.assertEqual(zipfp.namelist(), ["absolute"])

Here is the call graph for this function:

Definition at line 620 of file test_zipfile.py.

00620 
00621     def test_deflated(self):
00622         for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
00623             self.zip_test(f, zipfile.ZIP_DEFLATED)

Here is the call graph for this function:

Definition at line 551 of file test_zipfile.py.

00551 
00552     def test_large_file_exception(self):
00553         for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
00554             self.large_file_exception_test(f, zipfile.ZIP_STORED)
00555             self.large_file_exception_test2(f, zipfile.ZIP_STORED)

Here is the call graph for this function:

Definition at line 615 of file test_zipfile.py.

00615 
00616     def test_stored(self):
00617         for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
00618             self.zip_test(f, zipfile.ZIP_STORED)

Here is the call graph for this function:

def test.test_zipfile.TestZip64InSmallFiles.zip_test (   self,
  f,
  compression 
)

Definition at line 556 of file test_zipfile.py.

00556 
00557     def zip_test(self, f, compression):
00558         # Create the ZIP archive
00559         with zipfile.ZipFile(f, "w", compression, allowZip64=True) as zipfp:
00560             zipfp.write(TESTFN, "another.name")
00561             zipfp.write(TESTFN, TESTFN)
00562             zipfp.writestr("strfile", self.data)
00563 
00564         # Read the ZIP archive
00565         with zipfile.ZipFile(f, "r", compression) as zipfp:
00566             self.assertEqual(zipfp.read(TESTFN), self.data)
00567             self.assertEqual(zipfp.read("another.name"), self.data)
00568             self.assertEqual(zipfp.read("strfile"), self.data)
00569 
00570             # Print the ZIP directory
00571             fp = io.StringIO()
00572             zipfp.printdir(fp)
00573 
00574             directory = fp.getvalue()
00575             lines = directory.splitlines()
00576             self.assertEqual(len(lines), 4) # Number of files + header
00577 
00578             self.assertIn('File Name', lines[0])
00579             self.assertIn('Modified', lines[0])
00580             self.assertIn('Size', lines[0])
00581 
00582             fn, date, time_, size = lines[1].split()
00583             self.assertEqual(fn, 'another.name')
00584             self.assertTrue(time.strptime(date, '%Y-%m-%d'))
00585             self.assertTrue(time.strptime(time_, '%H:%M:%S'))
00586             self.assertEqual(size, str(len(self.data)))
00587 
00588             # Check the namelist
00589             names = zipfp.namelist()
00590             self.assertEqual(len(names), 3)
00591             self.assertIn(TESTFN, names)
00592             self.assertIn("another.name", names)
00593             self.assertIn("strfile", names)
00594 
00595             # Check infolist
00596             infos = zipfp.infolist()
00597             names = [i.filename for i in infos]
00598             self.assertEqual(len(names), 3)
00599             self.assertIn(TESTFN, names)
00600             self.assertIn("another.name", names)
00601             self.assertIn("strfile", names)
00602             for i in infos:
00603                 self.assertEqual(i.file_size, len(self.data))
00604 
00605             # check getinfo
00606             for nm in (TESTFN, "another.name", "strfile"):
00607                 info = zipfp.getinfo(nm)
00608                 self.assertEqual(info.filename, nm)
00609                 self.assertEqual(info.file_size, len(self.data))
00610 
00611             # Check that testzip doesn't raise an exception
00612             zipfp.testzip()
00613         if not isinstance(f, str):
00614             f.close()

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 528 of file test_zipfile.py.

Definition at line 533 of file test_zipfile.py.


The documentation for this class was generated from the following file: