summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-05-23 12:51:42 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-05-23 12:51:42 (GMT)
commit2cca0572848817791537efc9ee5df66d4ceb2d42 (patch)
tree90f1fd48ef074f9a4f31b9bb9c9d94794052014f
parent3c8d12d6b870bd907096da04d1bdb4d917639309 (diff)
downloadcpython-2cca0572848817791537efc9ee5df66d4ceb2d42.zip
cpython-2cca0572848817791537efc9ee5df66d4ceb2d42.tar.gz
cpython-2cca0572848817791537efc9ee5df66d4ceb2d42.tar.bz2
test_codecs now removes the temporay file (created by the test)
-rw-r--r--Lib/test/test_codecs.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 93cdf91..e412a64 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -515,13 +515,11 @@ class UTF16Test(ReadTest):
s1 = 'Hello\r\nworld\r\n'
s = s1.encode(self.encoding)
- try:
- with open(support.TESTFN, 'wb') as fp:
- fp.write(s)
- with codecs.open(support.TESTFN, 'U', encoding=self.encoding) as reader:
- self.assertEqual(reader.read(), s1)
- finally:
- support.unlink(support.TESTFN)
+ self.addCleanup(support.unlink, support.TESTFN)
+ with open(support.TESTFN, 'wb') as fp:
+ fp.write(s)
+ with codecs.open(support.TESTFN, 'U', encoding=self.encoding) as reader:
+ self.assertEqual(reader.read(), s1)
class UTF16LETest(ReadTest):
encoding = "utf-16-le"
@@ -1628,6 +1626,7 @@ class BomTest(unittest.TestCase):
"utf-32",
"utf-32-le",
"utf-32-be")
+ self.addCleanup(support.unlink, support.TESTFN)
for encoding in tests:
# Check if the BOM is written only once
with codecs.open(support.TESTFN, 'w+', encoding=encoding) as f: