AutoFileTests.tearDown(): Removed mysterious undocumented
try/except. Remove TESTFN. Throughout: used open() instead of file(), and wrapped long lines.
This commit is contained in:
parent
2b6377912e
commit
dbb82f623f
|
@ -11,14 +11,12 @@ class AutoFileTests(unittest.TestCase):
|
||||||
# file tests for which a test file is automatically set up
|
# file tests for which a test file is automatically set up
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.f = file(TESTFN, 'wb')
|
self.f = open(TESTFN, 'wb')
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
try:
|
if self.f:
|
||||||
if self.f:
|
self.f.close()
|
||||||
self.f.close()
|
os.remove(TESTFN)
|
||||||
except IOError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def testWeakRefs(self):
|
def testWeakRefs(self):
|
||||||
# verify weak references
|
# verify weak references
|
||||||
|
@ -73,9 +71,11 @@ class AutoFileTests(unittest.TestCase):
|
||||||
|
|
||||||
def testWritelinesNonString(self):
|
def testWritelinesNonString(self):
|
||||||
# verify writelines with non-string object
|
# verify writelines with non-string object
|
||||||
class NonString: pass
|
class NonString:
|
||||||
|
pass
|
||||||
|
|
||||||
self.assertRaises(TypeError, self.f.writelines, [NonString(), NonString()])
|
self.assertRaises(TypeError, self.f.writelines,
|
||||||
|
[NonString(), NonString()])
|
||||||
|
|
||||||
def testRepr(self):
|
def testRepr(self):
|
||||||
# verify repr works
|
# verify repr works
|
||||||
|
@ -93,8 +93,8 @@ class AutoFileTests(unittest.TestCase):
|
||||||
|
|
||||||
def testMethods(self):
|
def testMethods(self):
|
||||||
methods = ['fileno', 'flush', 'isatty', 'next', 'read', 'readinto',
|
methods = ['fileno', 'flush', 'isatty', 'next', 'read', 'readinto',
|
||||||
'readline', 'readlines', 'seek', 'tell', 'truncate', 'write',
|
'readline', 'readlines', 'seek', 'tell', 'truncate',
|
||||||
'xreadlines', '__iter__']
|
'write', 'xreadlines', '__iter__']
|
||||||
if sys.platform.startswith('atheos'):
|
if sys.platform.startswith('atheos'):
|
||||||
methods.remove('truncate')
|
methods.remove('truncate')
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ class OtherFileTests(unittest.TestCase):
|
||||||
# check invalid mode strings
|
# check invalid mode strings
|
||||||
for mode in ("", "aU", "wU+"):
|
for mode in ("", "aU", "wU+"):
|
||||||
try:
|
try:
|
||||||
f = file(TESTFN, mode)
|
f = open(TESTFN, mode)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
@ -175,11 +175,11 @@ class OtherFileTests(unittest.TestCase):
|
||||||
def bug801631():
|
def bug801631():
|
||||||
# SF bug <http://www.python.org/sf/801631>
|
# SF bug <http://www.python.org/sf/801631>
|
||||||
# "file.truncate fault on windows"
|
# "file.truncate fault on windows"
|
||||||
f = file(TESTFN, 'wb')
|
f = open(TESTFN, 'wb')
|
||||||
f.write('12345678901') # 11 bytes
|
f.write('12345678901') # 11 bytes
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
f = file(TESTFN,'rb+')
|
f = open(TESTFN,'rb+')
|
||||||
data = f.read(5)
|
data = f.read(5)
|
||||||
if data != '12345':
|
if data != '12345':
|
||||||
self.fail("Read on file opened for update failed %r" % data)
|
self.fail("Read on file opened for update failed %r" % data)
|
||||||
|
@ -201,14 +201,14 @@ class OtherFileTests(unittest.TestCase):
|
||||||
os.unlink(TESTFN)
|
os.unlink(TESTFN)
|
||||||
|
|
||||||
def testIteration(self):
|
def testIteration(self):
|
||||||
# Test the complex interaction when mixing file-iteration and the various
|
# Test the complex interaction when mixing file-iteration and the
|
||||||
# read* methods. Ostensibly, the mixture could just be tested to work
|
# various read* methods. Ostensibly, the mixture could just be tested
|
||||||
# when it should work according to the Python language, instead of fail
|
# to work when it should work according to the Python language,
|
||||||
# when it should fail according to the current CPython implementation.
|
# instead of fail when it should fail according to the current CPython
|
||||||
# People don't always program Python the way they should, though, and the
|
# implementation. People don't always program Python the way they
|
||||||
# implemenation might change in subtle ways, so we explicitly test for
|
# should, though, and the implemenation might change in subtle ways,
|
||||||
# errors, too; the test will just have to be updated when the
|
# so we explicitly test for errors, too; the test will just have to
|
||||||
# implementation changes.
|
# be updated when the implementation changes.
|
||||||
dataoffset = 16384
|
dataoffset = 16384
|
||||||
filler = "ham\n"
|
filler = "ham\n"
|
||||||
assert not dataoffset % len(filler), \
|
assert not dataoffset % len(filler), \
|
||||||
|
@ -246,12 +246,13 @@ class OtherFileTests(unittest.TestCase):
|
||||||
(methodname, args))
|
(methodname, args))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
# Test to see if harmless (by accident) mixing of read* and iteration
|
# Test to see if harmless (by accident) mixing of read* and
|
||||||
# still works. This depends on the size of the internal iteration
|
# iteration still works. This depends on the size of the internal
|
||||||
# buffer (currently 8192,) but we can test it in a flexible manner.
|
# iteration buffer (currently 8192,) but we can test it in a
|
||||||
# Each line in the bag o' ham is 4 bytes ("h", "a", "m", "\n"), so
|
# flexible manner. Each line in the bag o' ham is 4 bytes
|
||||||
# 4096 lines of that should get us exactly on the buffer boundary for
|
# ("h", "a", "m", "\n"), so 4096 lines of that should get us
|
||||||
# any power-of-2 buffersize between 4 and 16384 (inclusive).
|
# exactly on the buffer boundary for any power-of-2 buffersize
|
||||||
|
# between 4 and 16384 (inclusive).
|
||||||
f = open(TESTFN)
|
f = open(TESTFN)
|
||||||
for i in range(nchunks):
|
for i in range(nchunks):
|
||||||
f.next()
|
f.next()
|
||||||
|
|
Loading…
Reference in New Issue