Back to index

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

List of all members.

Public Member Functions

def setUp
def tearDown
def make_test_archive
def zip_test
def test_stored
def test_deflated
def zip_open_test
def test_open_stored
def test_open_deflated
def zip_random_open_test
def test_random_open_stored
def test_random_open_deflated

Public Attributes

 data

Detailed Description

Definition at line 1127 of file test_zipfile.py.


Member Function Documentation

def test.test_zipfile.TestsWithRandomBinaryFiles.make_test_archive (   self,
  f,
  compression 
)

Definition at line 1141 of file test_zipfile.py.

01141 
01142     def make_test_archive(self, f, compression):
01143         # Create the ZIP archive
01144         with zipfile.ZipFile(f, "w", compression) as zipfp:
01145             zipfp.write(TESTFN, "another.name")
01146             zipfp.write(TESTFN, TESTFN)

Here is the caller graph for this function:

Definition at line 1128 of file test_zipfile.py.

01128 
01129     def setUp(self):
01130         datacount = randint(16, 64)*1024 + randint(1, 1024)
01131         self.data = b''.join(struct.pack('<f', random()*randint(-1000, 1000))
01132                              for i in range(datacount))
01133 
01134         # Make a source file with some lines
01135         with open(TESTFN, "wb") as fp:
01136             fp.write(self.data)

Here is the caller graph for this function:

Definition at line 1137 of file test_zipfile.py.

01137 
01138     def tearDown(self):
01139         unlink(TESTFN)
01140         unlink(TESTFN2)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1164 of file test_zipfile.py.

01164 
01165     def test_deflated(self):
01166         for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
01167             self.zip_test(f, zipfile.ZIP_DEFLATED)

Here is the call graph for this function:

Definition at line 1204 of file test_zipfile.py.

01204 
01205     def test_open_deflated(self):
01206         for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
01207             self.zip_open_test(f, zipfile.ZIP_DEFLATED)

Here is the call graph for this function:

Definition at line 1199 of file test_zipfile.py.

01199 
01200     def test_open_stored(self):
01201         for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
01202             self.zip_open_test(f, zipfile.ZIP_STORED)

Here is the call graph for this function:

Definition at line 1232 of file test_zipfile.py.

01232 
01233     def test_random_open_deflated(self):
01234         for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
01235             self.zip_random_open_test(f, zipfile.ZIP_DEFLATED)
01236 
01237 
@skipUnless(zlib, "requires zlib")

Here is the call graph for this function:

Definition at line 1227 of file test_zipfile.py.

01227 
01228     def test_random_open_stored(self):
01229         for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
01230             self.zip_random_open_test(f, zipfile.ZIP_STORED)

Here is the call graph for this function:

Definition at line 1159 of file test_zipfile.py.

01159 
01160     def test_stored(self):
01161         for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
01162             self.zip_test(f, zipfile.ZIP_STORED)

Here is the call graph for this function:

def test.test_zipfile.TestsWithRandomBinaryFiles.zip_open_test (   self,
  f,
  compression 
)

Definition at line 1168 of file test_zipfile.py.

01168 
01169     def zip_open_test(self, f, compression):
01170         self.make_test_archive(f, compression)
01171 
01172         # Read the ZIP archive
01173         with zipfile.ZipFile(f, "r", compression) as zipfp:
01174             zipdata1 = []
01175             with zipfp.open(TESTFN) as zipopen1:
01176                 while True:
01177                     read_data = zipopen1.read(256)
01178                     if not read_data:
01179                         break
01180                     zipdata1.append(read_data)
01181 
01182             zipdata2 = []
01183             with zipfp.open("another.name") as zipopen2:
01184                 while True:
01185                     read_data = zipopen2.read(256)
01186                     if not read_data:
01187                         break
01188                     zipdata2.append(read_data)
01189 
01190             testdata1 = b''.join(zipdata1)
01191             self.assertEqual(len(testdata1), len(self.data))
01192             self.assertEqual(testdata1, self.data)
01193 
01194             testdata2 = b''.join(zipdata2)
01195             self.assertEqual(len(testdata2), len(self.data))
01196             self.assertEqual(testdata2, self.data)
01197         if not isinstance(f, str):
01198             f.close()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1208 of file test_zipfile.py.

01208 
01209     def zip_random_open_test(self, f, compression):
01210         self.make_test_archive(f, compression)
01211 
01212         # Read the ZIP archive
01213         with zipfile.ZipFile(f, "r", compression) as zipfp:
01214             zipdata1 = []
01215             with zipfp.open(TESTFN) as zipopen1:
01216                 while True:
01217                     read_data = zipopen1.read(randint(1, 1024))
01218                     if not read_data:
01219                         break
01220                     zipdata1.append(read_data)
01221 
01222             testdata = b''.join(zipdata1)
01223             self.assertEqual(len(testdata), len(self.data))
01224             self.assertEqual(testdata, self.data)
01225         if not isinstance(f, str):
01226             f.close()

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1147 of file test_zipfile.py.

01147 
01148     def zip_test(self, f, compression):
01149         self.make_test_archive(f, compression)
01150 
01151         # Read the ZIP archive
01152         with zipfile.ZipFile(f, "r", compression) as zipfp:
01153             testdata = zipfp.read(TESTFN)
01154             self.assertEqual(len(testdata), len(self.data))
01155             self.assertEqual(testdata, self.data)
01156             self.assertEqual(zipfp.read("another.name"), self.data)
01157         if not isinstance(f, str):
01158             f.close()

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 1130 of file test_zipfile.py.


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