Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_file.AutoFileTests Class Reference
Inheritance diagram for test.test_file.AutoFileTests:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def setUp
def tearDown
def testWeakRefs
def testAttributes
def testReadinto
def testReadinto_text
def testWritelinesUserList
def testWritelinesIntegers
def testWritelinesIntegersUserList
def testWritelinesNonString
def testErrors
def testMethods
def testReadWhenWriting

Public Attributes

 f

Detailed Description

Definition at line 13 of file test_file.py.


Member Function Documentation

Definition at line 16 of file test_file.py.

00016 
00017     def setUp(self):
00018         self.f = self.open(TESTFN, 'wb')

Here is the caller graph for this function:

Definition at line 19 of file test_file.py.

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

Here is the caller graph for this function:

Definition at line 33 of file test_file.py.

00033 
00034     def testAttributes(self):
00035         # verify expected attributes exist
00036         f = self.f
00037         f.name     # merely shouldn't blow up
00038         f.mode     # ditto
00039         f.closed   # ditto

Definition at line 83 of file test_file.py.

00083 
00084     def testErrors(self):
00085         f = self.f
00086         self.assertEqual(f.name, TESTFN)
00087         self.assertTrue(not f.isatty())
00088         self.assertTrue(not f.closed)
00089 
00090         if hasattr(f, "readinto"):
00091             self.assertRaises((IOError, TypeError), f.readinto, "")
00092         f.close()
00093         self.assertTrue(f.closed)

Here is the call graph for this function:

Definition at line 94 of file test_file.py.

00094 
00095     def testMethods(self):
00096         methods = [('fileno', ()),
00097                    ('flush', ()),
00098                    ('isatty', ()),
00099                    ('__next__', ()),
00100                    ('read', ()),
00101                    ('write', (b"",)),
00102                    ('readline', ()),
00103                    ('readlines', ()),
00104                    ('seek', (0,)),
00105                    ('tell', ()),
00106                    ('write', (b"",)),
00107                    ('writelines', ([],)),
00108                    ('__iter__', ()),
00109                    ]
00110         methods.append(('truncate', ()))
00111 
00112         # __exit__ should close the file
00113         self.f.__exit__(None, None, None)
00114         self.assertTrue(self.f.closed)
00115 
00116         for methodname, args in methods:
00117             method = getattr(self.f, methodname)
00118             # should raise on closed file
00119             self.assertRaises(ValueError, method, *args)
00120 
00121         # file is closed, __exit__ shouldn't do anything
00122         self.assertEqual(self.f.__exit__(None, None, None), None)
00123         # it must also return None if an exception was given
00124         try:
00125             1/0
00126         except:
00127             self.assertEqual(self.f.__exit__(*sys.exc_info()), None)

Here is the call graph for this function:

Definition at line 40 of file test_file.py.

00040 
00041     def testReadinto(self):
00042         # verify readinto
00043         self.f.write(b'12')
00044         self.f.close()
00045         a = array('b', b'x'*10)
00046         self.f = self.open(TESTFN, 'rb')
00047         n = self.f.readinto(a)
00048         self.assertEqual(b'12', a.tobytes()[:n])

Here is the call graph for this function:

Definition at line 49 of file test_file.py.

00049 
00050     def testReadinto_text(self):
00051         # verify readinto refuses text files
00052         a = array('b', b'x'*10)
00053         self.f.close()
00054         self.f = self.open(TESTFN, 'r')
00055         if hasattr(self.f, "readinto"):
00056             self.assertRaises(TypeError, self.f.readinto, a)

Here is the call graph for this function:

Definition at line 128 of file test_file.py.

00128 
00129     def testReadWhenWriting(self):
00130         self.assertRaises(IOError, self.f.read)

Here is the call graph for this function:

Definition at line 24 of file test_file.py.

00024 
00025     def testWeakRefs(self):
00026         # verify weak references
00027         p = proxy(self.f)
00028         p.write(b'teststring')
00029         self.assertEqual(self.f.tell(), p.tell())
00030         self.f.close()
00031         self.f = None
00032         self.assertRaises(ReferenceError, getattr, p, 'tell')

Here is the call graph for this function:

Definition at line 66 of file test_file.py.

00066 
00067     def testWritelinesIntegers(self):
00068         # verify writelines with integers
00069         self.assertRaises(TypeError, self.f.writelines, [1, 2, 3])

Here is the call graph for this function:

Definition at line 70 of file test_file.py.

00070 
00071     def testWritelinesIntegersUserList(self):
00072         # verify writelines with integers in UserList
00073         l = UserList([1,2,3])
00074         self.assertRaises(TypeError, self.f.writelines, l)

Here is the call graph for this function:

Definition at line 75 of file test_file.py.

00075 
00076     def testWritelinesNonString(self):
00077         # verify writelines with non-string object
00078         class NonString:
00079             pass
00080 
00081         self.assertRaises(TypeError, self.f.writelines,
00082                           [NonString(), NonString()])

Definition at line 57 of file test_file.py.

00057 
00058     def testWritelinesUserList(self):
00059         # verify writelines with instance sequence
00060         l = UserList([b'1', b'2'])
00061         self.f.writelines(l)
00062         self.f.close()
00063         self.f = self.open(TESTFN, 'rb')
00064         buf = self.f.read()
00065         self.assertEqual(buf, b'12')

Here is the call graph for this function:


Member Data Documentation

Definition at line 17 of file test_file.py.


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