Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions
test.test_io.MiscIOTest Class Reference
Inheritance diagram for test.test_io.MiscIOTest:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def tearDown
def test___all__
def test_attributes
def test_io_after_close
def test_blockingioerror
def test_abcs
def test_abc_inheritance
def test_abc_inheritance_official
def test_warn_on_dealloc
def test_warn_on_dealloc_fd
def test_pickling

Private Member Functions

def _check_abc_inheritance
def _check_warn_on_dealloc
def _check_warn_on_dealloc_fd

Detailed Description

Definition at line 2477 of file test_io.py.


Member Function Documentation

def test.test_io.MiscIOTest._check_abc_inheritance (   self,
  abcmodule 
) [private]

Definition at line 2589 of file test_io.py.

02589 
02590     def _check_abc_inheritance(self, abcmodule):
02591         with self.open(support.TESTFN, "wb", buffering=0) as f:
02592             self.assertIsInstance(f, abcmodule.IOBase)
02593             self.assertIsInstance(f, abcmodule.RawIOBase)
02594             self.assertNotIsInstance(f, abcmodule.BufferedIOBase)
02595             self.assertNotIsInstance(f, abcmodule.TextIOBase)
02596         with self.open(support.TESTFN, "wb") as f:
02597             self.assertIsInstance(f, abcmodule.IOBase)
02598             self.assertNotIsInstance(f, abcmodule.RawIOBase)
02599             self.assertIsInstance(f, abcmodule.BufferedIOBase)
02600             self.assertNotIsInstance(f, abcmodule.TextIOBase)
02601         with self.open(support.TESTFN, "w") as f:
02602             self.assertIsInstance(f, abcmodule.IOBase)
02603             self.assertNotIsInstance(f, abcmodule.RawIOBase)
02604             self.assertNotIsInstance(f, abcmodule.BufferedIOBase)
02605             self.assertIsInstance(f, abcmodule.TextIOBase)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_io.MiscIOTest._check_warn_on_dealloc (   self,
  args,
  kwargs 
) [private]

Definition at line 2615 of file test_io.py.

02615 
02616     def _check_warn_on_dealloc(self, *args, **kwargs):
02617         f = open(*args, **kwargs)
02618         r = repr(f)
02619         with self.assertWarns(ResourceWarning) as cm:
02620             f = None
02621             support.gc_collect()
02622         self.assertIn(r, str(cm.warning.args[0]))

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_io.MiscIOTest._check_warn_on_dealloc_fd (   self,
  args,
  kwargs 
) [private]

Definition at line 2628 of file test_io.py.

02628 
02629     def _check_warn_on_dealloc_fd(self, *args, **kwargs):
02630         fds = []
02631         def cleanup_fds():
02632             for fd in fds:
02633                 try:
02634                     os.close(fd)
02635                 except EnvironmentError as e:
02636                     if e.errno != errno.EBADF:
02637                         raise
02638         self.addCleanup(cleanup_fds)
02639         r, w = os.pipe()
02640         fds += r, w
02641         self._check_warn_on_dealloc(r, *args, **kwargs)
02642         # When using closefd=False, there's no warning
02643         r, w = os.pipe()
02644         fds += r, w
02645         with warnings.catch_warnings(record=True) as recorded:
02646             open(r, *args, closefd=False, **kwargs)
02647             support.gc_collect()
02648         self.assertEqual(recorded, [])

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2479 of file test_io.py.

02479 
02480     def tearDown(self):
02481         support.unlink(support.TESTFN)

Here is the caller graph for this function:

Definition at line 2482 of file test_io.py.

02482 
02483     def test___all__(self):
02484         for name in self.io.__all__:
02485             obj = getattr(self.io, name, None)
02486             self.assertTrue(obj is not None, name)
02487             if name == "open":
02488                 continue
02489             elif "error" in name.lower() or name == "UnsupportedOperation":
02490                 self.assertTrue(issubclass(obj, Exception), name)
02491             elif not name.startswith("SEEK_"):
02492                 self.assertTrue(issubclass(obj, self.IOBase))

Here is the call graph for this function:

Definition at line 2606 of file test_io.py.

02606 
02607     def test_abc_inheritance(self):
02608         # Test implementations inherit from their respective ABCs
02609         self._check_abc_inheritance(self)

Here is the call graph for this function:

Definition at line 2610 of file test_io.py.

02610 
02611     def test_abc_inheritance_official(self):
02612         # Test implementations inherit from the official ABCs of the
02613         # baseline "io" module.
02614         self._check_abc_inheritance(io)

Here is the call graph for this function:

Definition at line 2582 of file test_io.py.

02582 
02583     def test_abcs(self):
02584         # Test the visible base classes are ABCs.
02585         self.assertIsInstance(self.IOBase, abc.ABCMeta)
02586         self.assertIsInstance(self.RawIOBase, abc.ABCMeta)
02587         self.assertIsInstance(self.BufferedIOBase, abc.ABCMeta)
02588         self.assertIsInstance(self.TextIOBase, abc.ABCMeta)

Here is the call graph for this function:

Definition at line 2493 of file test_io.py.

02493 
02494     def test_attributes(self):
02495         f = self.open(support.TESTFN, "wb", buffering=0)
02496         self.assertEqual(f.mode, "wb")
02497         f.close()
02498 
02499         f = self.open(support.TESTFN, "U")
02500         self.assertEqual(f.name,            support.TESTFN)
02501         self.assertEqual(f.buffer.name,     support.TESTFN)
02502         self.assertEqual(f.buffer.raw.name, support.TESTFN)
02503         self.assertEqual(f.mode,            "U")
02504         self.assertEqual(f.buffer.mode,     "rb")
02505         self.assertEqual(f.buffer.raw.mode, "rb")
02506         f.close()
02507 
02508         f = self.open(support.TESTFN, "w+")
02509         self.assertEqual(f.mode,            "w+")
02510         self.assertEqual(f.buffer.mode,     "rb+") # Does it really matter?
02511         self.assertEqual(f.buffer.raw.mode, "rb+")
02512 
02513         g = self.open(f.fileno(), "wb", closefd=False)
02514         self.assertEqual(g.mode,     "wb")
02515         self.assertEqual(g.raw.mode, "wb")
02516         self.assertEqual(g.name,     f.fileno())
02517         self.assertEqual(g.raw.name, f.fileno())
02518         f.close()
02519         g.close()

Here is the call graph for this function:

Definition at line 2563 of file test_io.py.

02563 
02564     def test_blockingioerror(self):
02565         # Various BlockingIOError issues
02566         self.assertRaises(TypeError, self.BlockingIOError)
02567         self.assertRaises(TypeError, self.BlockingIOError, 1)
02568         self.assertRaises(TypeError, self.BlockingIOError, 1, 2, 3, 4)
02569         self.assertRaises(TypeError, self.BlockingIOError, 1, "", None)
02570         b = self.BlockingIOError(1, "")
02571         self.assertEqual(b.characters_written, 0)
02572         class C(str):
02573             pass
02574         c = C("")
02575         b = self.BlockingIOError(1, c)
02576         c.b = b
02577         b.c = c
02578         wr = weakref.ref(c)
02579         del c, b
02580         support.gc_collect()
02581         self.assertTrue(wr() is None, wr)

Here is the call graph for this function:

Definition at line 2520 of file test_io.py.

02520 
02521     def test_io_after_close(self):
02522         for kwargs in [
02523                 {"mode": "w"},
02524                 {"mode": "wb"},
02525                 {"mode": "w", "buffering": 1},
02526                 {"mode": "w", "buffering": 2},
02527                 {"mode": "wb", "buffering": 0},
02528                 {"mode": "r"},
02529                 {"mode": "rb"},
02530                 {"mode": "r", "buffering": 1},
02531                 {"mode": "r", "buffering": 2},
02532                 {"mode": "rb", "buffering": 0},
02533                 {"mode": "w+"},
02534                 {"mode": "w+b"},
02535                 {"mode": "w+", "buffering": 1},
02536                 {"mode": "w+", "buffering": 2},
02537                 {"mode": "w+b", "buffering": 0},
02538             ]:
02539             f = self.open(support.TESTFN, **kwargs)
02540             f.close()
02541             self.assertRaises(ValueError, f.flush)
02542             self.assertRaises(ValueError, f.fileno)
02543             self.assertRaises(ValueError, f.isatty)
02544             self.assertRaises(ValueError, f.__iter__)
02545             if hasattr(f, "peek"):
02546                 self.assertRaises(ValueError, f.peek, 1)
02547             self.assertRaises(ValueError, f.read)
02548             if hasattr(f, "read1"):
02549                 self.assertRaises(ValueError, f.read1, 1024)
02550             if hasattr(f, "readall"):
02551                 self.assertRaises(ValueError, f.readall)
02552             if hasattr(f, "readinto"):
02553                 self.assertRaises(ValueError, f.readinto, bytearray(1024))
02554             self.assertRaises(ValueError, f.readline)
02555             self.assertRaises(ValueError, f.readlines)
02556             self.assertRaises(ValueError, f.seek, 0)
02557             self.assertRaises(ValueError, f.tell)
02558             self.assertRaises(ValueError, f.truncate)
02559             self.assertRaises(ValueError, f.write,
02560                               b"" if "b" in kwargs['mode'] else "")
02561             self.assertRaises(ValueError, f.writelines, [])
02562             self.assertRaises(ValueError, next, f)

Here is the call graph for this function:

Definition at line 2655 of file test_io.py.

02655 
02656     def test_pickling(self):
02657         # Pickling file objects is forbidden
02658         for kwargs in [
02659                 {"mode": "w"},
02660                 {"mode": "wb"},
02661                 {"mode": "wb", "buffering": 0},
02662                 {"mode": "r"},
02663                 {"mode": "rb"},
02664                 {"mode": "rb", "buffering": 0},
02665                 {"mode": "w+"},
02666                 {"mode": "w+b"},
02667                 {"mode": "w+b", "buffering": 0},
02668             ]:
02669             for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
02670                 with self.open(support.TESTFN, **kwargs) as f:
02671                     self.assertRaises(TypeError, pickle.dumps, f, protocol)

Here is the call graph for this function:

Definition at line 2623 of file test_io.py.

02623 
02624     def test_warn_on_dealloc(self):
02625         self._check_warn_on_dealloc(support.TESTFN, "wb", buffering=0)
02626         self._check_warn_on_dealloc(support.TESTFN, "wb")
02627         self._check_warn_on_dealloc(support.TESTFN, "w")

Here is the call graph for this function:

Definition at line 2649 of file test_io.py.

02649 
02650     def test_warn_on_dealloc_fd(self):
02651         self._check_warn_on_dealloc_fd("rb", buffering=0)
02652         self._check_warn_on_dealloc_fd("rb")
02653         self._check_warn_on_dealloc_fd("r")
02654 

Here is the call graph for this function:


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