summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-08-21 23:58:12 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-08-21 23:58:12 (GMT)
commit82fb71d662dd9858d2560b72fd0d867604b12389 (patch)
treeda40b00b31b6a4ed9d35739e4b7ffb1bf558cd88 /Lib
parent0f24b879c9ac489a433d6b5f367dcb0553b9abdc (diff)
downloadcpython-82fb71d662dd9858d2560b72fd0d867604b12389.zip
cpython-82fb71d662dd9858d2560b72fd0d867604b12389.tar.gz
cpython-82fb71d662dd9858d2560b72fd0d867604b12389.tar.bz2
Cleanup test_builtin
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_builtin.py16
1 files changed, 4 insertions, 12 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index acbc29c..8d3271f 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -976,29 +976,25 @@ class BuiltinTest(unittest.TestCase):
def write_testfile(self):
# NB the first 4 lines are also used to test input, below
fp = open(TESTFN, 'w')
- try:
+ self.addCleanup(unlink, TESTFN)
+ with fp:
fp.write('1+1\n')
fp.write('The quick brown fox jumps over the lazy dog')
fp.write('.\n')
fp.write('Dear John\n')
fp.write('XXX'*100)
fp.write('YYY'*100)
- finally:
- fp.close()
def test_open(self):
self.write_testfile()
fp = open(TESTFN, 'r')
- try:
+ with fp:
self.assertEqual(fp.readline(4), '1+1\n')
self.assertEqual(fp.readline(), 'The quick brown fox jumps over the lazy dog.\n')
self.assertEqual(fp.readline(4), 'Dear')
self.assertEqual(fp.readline(100), ' John\n')
self.assertEqual(fp.read(300), 'XXX'*100)
self.assertEqual(fp.read(1000), 'YYY'*100)
- finally:
- fp.close()
- unlink(TESTFN)
def test_open_default_encoding(self):
old_environ = dict(os.environ)
@@ -1013,11 +1009,8 @@ class BuiltinTest(unittest.TestCase):
self.write_testfile()
current_locale_encoding = locale.getpreferredencoding(False)
fp = open(TESTFN, 'w')
- try:
+ with fp:
self.assertEqual(fp.encoding, current_locale_encoding)
- finally:
- fp.close()
- unlink(TESTFN)
finally:
os.environ.clear()
os.environ.update(old_environ)
@@ -1132,7 +1125,6 @@ class BuiltinTest(unittest.TestCase):
sys.stdin = savestdin
sys.stdout = savestdout
fp.close()
- unlink(TESTFN)
@unittest.skipUnless(pty, "the pty and signal modules must be available")
def check_input_tty(self, prompt, terminal_input, stdio_encoding=None):