Back to index

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

List of all members.

Public Member Functions

def test_empty_tarfile
def test_null_tarfile
def test_ignore_zeros
def setUp
def tearDown

Public Attributes

 tar

Static Public Attributes

 tarname = tarname
string mode = "r:"

Detailed Description

Definition at line 170 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 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 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:


Member Data Documentation

string test.test_tarfile.ReadTest.mode = "r:" [static, inherited]

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: