mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Test closed, mode attribute; don't test __exit__().
This commit is contained in:
parent
d410395ea7
commit
31c3a57480
1 changed files with 17 additions and 22 deletions
|
@ -48,14 +48,14 @@ class AutoFileTests(unittest.TestCase):
|
||||||
def testAttributes(self):
|
def testAttributes(self):
|
||||||
# verify expected attributes exist
|
# verify expected attributes exist
|
||||||
f = self.f
|
f = self.f
|
||||||
# XXX do we want these?
|
|
||||||
#f.name # merely shouldn't blow up
|
|
||||||
#f.mode # ditto
|
|
||||||
#f.closed # ditto
|
|
||||||
|
|
||||||
# verify the others aren't
|
self.assertEquals(f.mode, "w")
|
||||||
for attr in 'name', 'mode', 'closed':
|
self.assertEquals(f.closed, False)
|
||||||
self.assertRaises((AttributeError, TypeError), setattr, f, attr, 'oops')
|
|
||||||
|
# verify the attributes are readonly
|
||||||
|
for attr in 'mode', 'closed':
|
||||||
|
self.assertRaises((AttributeError, TypeError),
|
||||||
|
setattr, f, attr, 'oops')
|
||||||
|
|
||||||
def testReadinto(self):
|
def testReadinto(self):
|
||||||
# verify readinto
|
# verify readinto
|
||||||
|
@ -74,12 +74,16 @@ class AutoFileTests(unittest.TestCase):
|
||||||
def testErrors(self):
|
def testErrors(self):
|
||||||
f = self.f
|
f = self.f
|
||||||
self.assert_(not f.isatty())
|
self.assert_(not f.isatty())
|
||||||
#self.assert_(not f.closed) # XXX Do we want to support these?
|
self.assert_(not f.closed)
|
||||||
#self.assertEquals(f.name, TESTFN)
|
#self.assertEquals(f.name, TESTFN)
|
||||||
|
self.assertRaises(ValueError, f.read, 10) # Open for reading
|
||||||
self.assertRaises(TypeError, f.readinto, "")
|
|
||||||
f.close()
|
f.close()
|
||||||
#self.assert_(f.closed) # XXX
|
self.assert_(f.closed)
|
||||||
|
f = _fileio._FileIO(TESTFN, 'r')
|
||||||
|
self.assertRaises(TypeError, f.readinto, "")
|
||||||
|
self.assert_(not f.closed)
|
||||||
|
f.close()
|
||||||
|
self.assert_(f.closed)
|
||||||
|
|
||||||
def testMethods(self):
|
def testMethods(self):
|
||||||
methods = ['fileno', 'isatty', 'read', 'readinto',
|
methods = ['fileno', 'isatty', 'read', 'readinto',
|
||||||
|
@ -88,23 +92,14 @@ class AutoFileTests(unittest.TestCase):
|
||||||
if sys.platform.startswith('atheos'):
|
if sys.platform.startswith('atheos'):
|
||||||
methods.remove('truncate')
|
methods.remove('truncate')
|
||||||
|
|
||||||
# __exit__ should close the file
|
self.f.close()
|
||||||
self.f.__exit__(None, None, None)
|
self.assert_(self.f.closed)
|
||||||
#self.assert_(self.f.closed) # XXX
|
|
||||||
|
|
||||||
for methodname in methods:
|
for methodname in methods:
|
||||||
method = getattr(self.f, methodname)
|
method = getattr(self.f, methodname)
|
||||||
# should raise on closed file
|
# should raise on closed file
|
||||||
self.assertRaises(ValueError, method)
|
self.assertRaises(ValueError, method)
|
||||||
|
|
||||||
# file is closed, __exit__ shouldn't do anything
|
|
||||||
self.assertEquals(self.f.__exit__(None, None, None), None)
|
|
||||||
# it must also return None if an exception was given
|
|
||||||
try:
|
|
||||||
1/0
|
|
||||||
except:
|
|
||||||
self.assertEquals(self.f.__exit__(*sys.exc_info()), None)
|
|
||||||
|
|
||||||
|
|
||||||
class OtherFileTests(unittest.TestCase):
|
class OtherFileTests(unittest.TestCase):
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue