Back to index

python3.2  3.2.2
Public Member Functions
test.test_tarfile.ContextManagerTest Class Reference

List of all members.

Public Member Functions

def test_basic
def test_closed
def test_exception
def test_no_eof
def test_eof
def test_fileobj

Detailed Description

Definition at line 1590 of file test_tarfile.py.


Member Function Documentation

Definition at line 1592 of file test_tarfile.py.

01592 
01593     def test_basic(self):
01594         with tarfile.open(tarname) as tar:
01595             self.assertFalse(tar.closed, "closed inside runtime context")
01596         self.assertTrue(tar.closed, "context manager failed")

Here is the call graph for this function:

Definition at line 1597 of file test_tarfile.py.

01597 
01598     def test_closed(self):
01599         # The __enter__() method is supposed to raise IOError
01600         # if the TarFile object is already closed.
01601         tar = tarfile.open(tarname)
01602         tar.close()
01603         with self.assertRaises(IOError):
01604             with tar:
01605                 pass

Here is the call graph for this function:

Definition at line 1627 of file test_tarfile.py.

01627 
01628     def test_eof(self):
01629         # __exit__() must write end-of-archive blocks, i.e. call
01630         # TarFile.close() if there was no error.
01631         with tarfile.open(tmpname, "w"):
01632             pass
01633         self.assertNotEqual(os.path.getsize(tmpname), 0,
01634                 "context manager wrote no end-of-archive block")

Here is the call graph for this function:

Definition at line 1606 of file test_tarfile.py.

01606 
01607     def test_exception(self):
01608         # Test if the IOError exception is passed through properly.
01609         with self.assertRaises(Exception) as exc:
01610             with tarfile.open(tarname) as tar:
01611                 raise IOError
01612         self.assertIsInstance(exc.exception, IOError,
01613                               "wrong exception raised in context manager")
01614         self.assertTrue(tar.closed, "context manager failed")

Here is the call graph for this function:

Definition at line 1635 of file test_tarfile.py.

01635 
01636     def test_fileobj(self):
01637         # Test that __exit__() did not close the external file
01638         # object.
01639         with open(tmpname, "wb") as fobj:
01640             try:
01641                 with tarfile.open(fileobj=fobj, mode="w") as tar:
01642                     raise Exception
01643             except:
01644                 pass
01645             self.assertFalse(fobj.closed, "external file object was closed")
01646             self.assertTrue(tar.closed, "context manager failed")
01647 

Here is the call graph for this function:

Definition at line 1615 of file test_tarfile.py.

01615 
01616     def test_no_eof(self):
01617         # __exit__() must not write end-of-archive blocks if an
01618         # exception was raised.
01619         try:
01620             with tarfile.open(tmpname, "w") as tar:
01621                 raise Exception
01622         except:
01623             pass
01624         self.assertEqual(os.path.getsize(tmpname), 0,
01625                 "context manager wrote an end-of-archive block")
01626         self.assertTrue(tar.closed, "context manager failed")

Here is the call graph for this function:


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