Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_fileio.AutoFileTests Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def testWeakRefs
def testSeekTell
def testAttributes
def testReadinto
def test_none_args
def test_reject
def testRepr
def testErrors
def testMethods
def testOpendir
def ClosedFD
def ClosedFDRaises
def testErrnoOnClose
def testErrnoOnClosedWrite
def testErrnoOnClosedSeek
def testErrnoOnClosedTell
def testErrnoOnClosedTruncate
def testErrnoOnClosedSeekable
def testErrnoOnClosedReadable
def testErrnoOnClosedWritable
def testErrnoOnClosedFileno
def testErrnoOnClosedIsatty
def ReopenForRead
def testErrnoOnClosedRead
def testErrnoOnClosedReadall
def testErrnoOnClosedReadinto

Public Attributes

 f

Detailed Description

Definition at line 15 of file test_fileio.py.


Member Function Documentation

Definition at line 132 of file test_fileio.py.

00132 
00133     def ClosedFD(func):
00134         @wraps(func)
00135         def wrapper(self):
00136             #forcibly close the fd before invoking the problem function
00137             f = self.f
00138             os.close(f.fileno())
00139             try:
00140                 func(self, f)
00141             finally:
00142                 try:
00143                     self.f.close()
00144                 except IOError:
00145                     pass
00146         return wrapper

Here is the call graph for this function:

Definition at line 147 of file test_fileio.py.

00147 
00148     def ClosedFDRaises(func):
00149         @wraps(func)
00150         def wrapper(self):
00151             #forcibly close the fd before invoking the problem function
00152             f = self.f
00153             os.close(f.fileno())
00154             try:
00155                 func(self, f)
00156             except IOError as e:
00157                 self.assertEqual(e.errno, errno.EBADF)
00158             else:
00159                 self.fail("Should have raised IOError")
00160             finally:
00161                 try:
00162                     self.f.close()
00163                 except IOError:
00164                     pass
00165         return wrapper

Here is the call graph for this function:

Definition at line 206 of file test_fileio.py.

00206 
00207     def ReopenForRead(self):
00208         try:
00209             self.f.close()
00210         except IOError:
00211             pass
00212         self.f = _FileIO(TESTFN, 'r')
00213         os.close(self.f.fileno())
00214         return self.f

Here is the caller graph for this function:

Definition at line 18 of file test_fileio.py.

00018 
00019     def setUp(self):
00020         self.f = _FileIO(TESTFN, 'w')

Here is the caller graph for this function:

Definition at line 21 of file test_fileio.py.

00021 
00022     def tearDown(self):
00023         if self.f:
00024             self.f.close()
00025         os.remove(TESTFN)

Here is the caller graph for this function:

Definition at line 70 of file test_fileio.py.

00070 
00071     def test_none_args(self):
00072         self.f.write(b"hi\nbye\nabc")
00073         self.f.close()
00074         self.f = _FileIO(TESTFN, 'r')
00075         self.assertEqual(self.f.read(None), b"hi\nbye\nabc")
00076         self.f.seek(0)
00077         self.assertEqual(self.f.readline(None), b"hi\n")
00078         self.assertEqual(self.f.readlines(None), [b"bye\n", b"abc"])

Here is the call graph for this function:

Definition at line 79 of file test_fileio.py.

00079 
00080     def test_reject(self):
00081         self.assertRaises(TypeError, self.f.write, "Hello!")

Here is the call graph for this function:

Definition at line 49 of file test_fileio.py.

00049 
00050     def testAttributes(self):
00051         # verify expected attributes exist
00052         f = self.f
00053 
00054         self.assertEqual(f.mode, "wb")
00055         self.assertEqual(f.closed, False)
00056 
00057         # verify the attributes are readonly
00058         for attr in 'mode', 'closed':
00059             self.assertRaises((AttributeError, TypeError),
00060                               setattr, f, attr, 'oops')

Here is the call graph for this function:

Definition at line 167 of file test_fileio.py.

00167 
00168     def testErrnoOnClose(self, f):
00169         f.close()

Definition at line 199 of file test_fileio.py.

00199 
00200     def testErrnoOnClosedFileno(self, f):
00201         f.fileno()

Definition at line 203 of file test_fileio.py.

00203 
00204     def testErrnoOnClosedIsatty(self, f):
00205         self.assertEqual(f.isatty(), False)

Here is the call graph for this function:

Definition at line 216 of file test_fileio.py.

00216 
00217     def testErrnoOnClosedRead(self, f):
00218         f = self.ReopenForRead()
00219         f.read(1)

Here is the call graph for this function:

Definition at line 191 of file test_fileio.py.

00191 
00192     def testErrnoOnClosedReadable(self, f):
00193         f.readable()

Definition at line 221 of file test_fileio.py.

00221 
00222     def testErrnoOnClosedReadall(self, f):
00223         f = self.ReopenForRead()
00224         f.readall()

Here is the call graph for this function:

Definition at line 226 of file test_fileio.py.

00226 
00227     def testErrnoOnClosedReadinto(self, f):
00228         f = self.ReopenForRead()
00229         a = array('b', b'x'*10)
00230         f.readinto(a)

Here is the call graph for this function:

Definition at line 175 of file test_fileio.py.

00175 
00176     def testErrnoOnClosedSeek(self, f):
00177         f.seek(0)

Definition at line 187 of file test_fileio.py.

00187 
00188     def testErrnoOnClosedSeekable(self, f):
00189         f.seekable()

Definition at line 179 of file test_fileio.py.

00179 
00180     def testErrnoOnClosedTell(self, f):
00181         f.tell()

Definition at line 183 of file test_fileio.py.

00183 
00184     def testErrnoOnClosedTruncate(self, f):
00185         f.truncate(0)

Definition at line 195 of file test_fileio.py.

00195 
00196     def testErrnoOnClosedWritable(self, f):
00197         f.writable()

Definition at line 171 of file test_fileio.py.

00171 
00172     def testErrnoOnClosedWrite(self, f):
00173         f.write(b'a')

Definition at line 91 of file test_fileio.py.

00091 
00092     def testErrors(self):
00093         f = self.f
00094         self.assertTrue(not f.isatty())
00095         self.assertTrue(not f.closed)
00096         #self.assertEqual(f.name, TESTFN)
00097         self.assertRaises(ValueError, f.read, 10) # Open for reading
00098         f.close()
00099         self.assertTrue(f.closed)
00100         f = _FileIO(TESTFN, 'r')
00101         self.assertRaises(TypeError, f.readinto, "")
00102         self.assertTrue(not f.closed)
00103         f.close()
00104         self.assertTrue(f.closed)

Here is the call graph for this function:

Definition at line 105 of file test_fileio.py.

00105 
00106     def testMethods(self):
00107         methods = ['fileno', 'isatty', 'read', 'readinto',
00108                    'seek', 'tell', 'truncate', 'write', 'seekable',
00109                    'readable', 'writable']
00110 
00111         self.f.close()
00112         self.assertTrue(self.f.closed)
00113 
00114         for methodname in methods:
00115             method = getattr(self.f, methodname)
00116             # should raise on closed file
00117             self.assertRaises(ValueError, method)

Here is the call graph for this function:

Definition at line 118 of file test_fileio.py.

00118 
00119     def testOpendir(self):
00120         # Issue 3703: opening a directory should fill the errno
00121         # Windows always returns "[Errno 13]: Permission denied
00122         # Unix calls dircheck() and returns "[Errno 21]: Is a directory"
00123         try:
00124             _FileIO('.', 'r')
00125         except IOError as e:
00126             self.assertNotEqual(e.errno, 0)
00127             self.assertEqual(e.filename, ".")
00128         else:
00129             self.fail("Should have raised IOError")

Here is the call graph for this function:

Definition at line 61 of file test_fileio.py.

00061 
00062     def testReadinto(self):
00063         # verify readinto
00064         self.f.write(bytes([1, 2]))
00065         self.f.close()
00066         a = array('b', b'x'*10)
00067         self.f = _FileIO(TESTFN, 'r')
00068         n = self.f.readinto(a)
00069         self.assertEqual(array('b', [1, 2]), a[:n])

Here is the call graph for this function:

Definition at line 82 of file test_fileio.py.

00082 
00083     def testRepr(self):
00084         self.assertEqual(repr(self.f), "<_io.FileIO name=%r mode=%r>"
00085                                         % (self.f.name, self.f.mode))
00086         del self.f.name
00087         self.assertEqual(repr(self.f), "<_io.FileIO fd=%r mode=%r>"
00088                                         % (self.f.fileno(), self.f.mode))
00089         self.f.close()
00090         self.assertEqual(repr(self.f), "<_io.FileIO [closed]>")

Here is the call graph for this function:

Definition at line 35 of file test_fileio.py.

00035 
00036     def testSeekTell(self):
00037         self.f.write(bytes(range(20)))
00038         self.assertEqual(self.f.tell(), 20)
00039         self.f.seek(0)
00040         self.assertEqual(self.f.tell(), 0)
00041         self.f.seek(10)
00042         self.assertEqual(self.f.tell(), 10)
00043         self.f.seek(5, 1)
00044         self.assertEqual(self.f.tell(), 15)
00045         self.f.seek(-5, 1)
00046         self.assertEqual(self.f.tell(), 10)
00047         self.f.seek(-5, 2)
00048         self.assertEqual(self.f.tell(), 15)

Here is the call graph for this function:

Definition at line 26 of file test_fileio.py.

00026 
00027     def testWeakRefs(self):
00028         # verify weak references
00029         p = proxy(self.f)
00030         p.write(bytes(range(10)))
00031         self.assertEqual(self.f.tell(), p.tell())
00032         self.f.close()
00033         self.f = None
00034         self.assertRaises(ReferenceError, getattr, p, 'tell')

Here is the call graph for this function:


Member Data Documentation

Definition at line 19 of file test_fileio.py.


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