Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
test.test_tarfile.StreamReadTest Class Reference
Inheritance diagram for test.test_tarfile.StreamReadTest:
Inheritance graph
[legend]
Collaboration diagram for test.test_tarfile.StreamReadTest:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_read_through
def test_fileobj_regular_file
def test_provoke_stream_error
def test_compare_members
def test_empty_tarfile
def test_null_tarfile
def test_ignore_zeros
def setUp
def tearDown

Public Attributes

 tar

Static Public Attributes

string mode = "r|"
 tarname = tarname

Detailed Description

Definition at line 418 of file test_tarfile.py.


Member Function Documentation

def test.test_tarfile.ReadTest.setUp (   self) [inherited]

Definition at line 43 of file test_tarfile.py.

00043 
00044     def setUp(self):
00045         self.tar = tarfile.open(self.tarname, mode=self.mode, encoding="iso8859-1")

Here is the caller graph for this function:

def test.test_tarfile.ReadTest.tearDown (   self) [inherited]

Definition at line 46 of file test_tarfile.py.

00046 
00047     def tearDown(self):
00048         self.tar.close()
00049 

Here is the caller graph for this function:

Definition at line 450 of file test_tarfile.py.

00450 
00451     def test_compare_members(self):
00452         tar1 = tarfile.open(tarname, encoding="iso8859-1")
00453         try:
00454             tar2 = self.tar
00455 
00456             while True:
00457                 t1 = tar1.next()
00458                 t2 = tar2.next()
00459                 if t1 is None:
00460                     break
00461                 self.assertTrue(t2 is not None, "stream.next() failed.")
00462 
00463                 if t2.islnk() or t2.issym():
00464                     self.assertRaises(tarfile.StreamError, tar2.extractfile, t2)
00465                     continue
00466 
00467                 v1 = tar1.extractfile(t1)
00468                 v2 = tar2.extractfile(t2)
00469                 if v1 is None:
00470                     continue
00471                 self.assertTrue(v2 is not None, "stream.extractfile() failed")
00472                 self.assertEqual(v1.read(), v2.read(), "stream extraction failed")
00473         finally:
00474             tar1.close()
00475 

Here is the call graph for this function:

Definition at line 172 of file test_tarfile.py.

00172 
00173     def test_empty_tarfile(self):
00174         # Test for issue6123: Allow opening empty archives.
00175         # This test checks if tarfile.open() is able to open an empty tar
00176         # archive successfully. Note that an empty tar archive is not the
00177         # same as an empty file!
00178         with tarfile.open(tmpname, self.mode.replace("r", "w")):
00179             pass
00180         try:
00181             tar = tarfile.open(tmpname, self.mode)
00182             tar.getnames()
00183         except tarfile.ReadError:
00184             self.fail("tarfile.open() failed on empty archive")
00185         else:
00186             self.assertListEqual(tar.getmembers(), [])
00187         finally:
00188             tar.close()

Here is the call graph for this function:

Definition at line 438 of file test_tarfile.py.

00438 
00439     def test_fileobj_regular_file(self):
00440         tarinfo = self.tar.next() # get "regtype" (can't use getmember)
00441         fobj = self.tar.extractfile(tarinfo)
00442         data = fobj.read()
00443         self.assertTrue((len(data), md5sum(data)) == (tarinfo.size, md5_regtype),
00444                 "regular file extraction failed")

Here is the call graph for this function:

Definition at line 198 of file test_tarfile.py.

00198 
00199     def test_ignore_zeros(self):
00200         # Test TarFile's ignore_zeros option.
00201         if self.mode.endswith(":gz"):
00202             _open = gzip.GzipFile
00203         elif self.mode.endswith(":bz2"):
00204             _open = bz2.BZ2File
00205         else:
00206             _open = open
00207 
00208         for char in (b'\0', b'a'):
00209             # Test if EOFHeaderError ('\0') and InvalidHeaderError ('a')
00210             # are ignored correctly.
00211             with _open(tmpname, "wb") as fobj:
00212                 fobj.write(char * 1024)
00213                 fobj.write(tarfile.TarInfo("foo").tobuf())
00214 
00215             tar = tarfile.open(tmpname, mode="r", ignore_zeros=True)
00216             try:
00217                 self.assertListEqual(tar.getnames(), ["foo"],
00218                     "ignore_zeros=True should have skipped the %r-blocks" % char)
00219             finally:
00220                 tar.close()
00221 

Here is the call graph for this function:

Definition at line 189 of file test_tarfile.py.

00189 
00190     def test_null_tarfile(self):
00191         # Test for issue6123: Allow opening empty archives.
00192         # This test guarantees that tarfile.open() does not treat an empty
00193         # file as an empty tar archive.
00194         with open(tmpname, "wb"):
00195             pass
00196         self.assertRaises(tarfile.ReadError, tarfile.open, tmpname, self.mode)
00197         self.assertRaises(tarfile.ReadError, tarfile.open, tmpname)

Here is the call graph for this function:

Definition at line 445 of file test_tarfile.py.

00445 
00446     def test_provoke_stream_error(self):
00447         tarinfos = self.tar.getmembers()
00448         f = self.tar.extractfile(tarinfos[0]) # read the first member
00449         self.assertRaises(tarfile.StreamError, f.read)

Here is the call graph for this function:

Definition at line 422 of file test_tarfile.py.

00422 
00423     def test_read_through(self):
00424         # Issue #11224: A poorly designed _FileInFile.read() method
00425         # caused seeking errors with stream tar files.
00426         for tarinfo in self.tar:
00427             if not tarinfo.isreg():
00428                 continue
00429             fobj = self.tar.extractfile(tarinfo)
00430             while True:
00431                 try:
00432                     buf = fobj.read(512)
00433                 except tarfile.StreamError:
00434                     self.fail("simple read-through using TarFile.extractfile() failed")
00435                 if not buf:
00436                     break
00437             fobj.close()

Here is the call graph for this function:


Member Data Documentation

Reimplemented from test.test_tarfile.ReadTest.

Definition at line 420 of file test_tarfile.py.

Reimplemented in test.test_tarfile.MemberReadTest.

Definition at line 44 of file test_tarfile.py.


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