]> granicus.if.org Git - python/commitdiff
test_codecs now removes the temporay file (created by the test)
authorVictor Stinner <victor.stinner@haypocalc.com>
Mon, 23 May 2011 14:19:31 +0000 (16:19 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Mon, 23 May 2011 14:19:31 +0000 (16:19 +0200)
Lib/test/test_codecs.py

index 7cd7141b0670a6c342fb10a6b77f10f0ea97d2a9..f7f27cc7d9f95c75d79b112559f1be5f9fc2094b 100644 (file)
@@ -469,13 +469,11 @@ class UTF16Test(ReadTest):
         s1 = u'Hello\r\nworld\r\n'
 
         s = s1.encode(self.encoding)
-        try:
-            with open(test_support.TESTFN, 'wb') as fp:
-                fp.write(s)
-            with codecs.open(test_support.TESTFN, 'U', encoding=self.encoding) as reader:
-                self.assertEqual(reader.read(), s1)
-        finally:
-            test_support.unlink(test_support.TESTFN)
+        self.addCleanup(test_support.unlink, test_support.TESTFN)
+        with open(test_support.TESTFN, 'wb') as fp:
+            fp.write(s)
+        with codecs.open(test_support.TESTFN, 'U', encoding=self.encoding) as reader:
+            self.assertEqual(reader.read(), s1)
 
 class UTF16LETest(ReadTest):
     encoding = "utf-16-le"
@@ -1532,6 +1530,7 @@ class BomTest(unittest.TestCase):
                  "utf-32",
                  "utf-32-le",
                  "utf-32-be")
+        self.addCleanup(test_support.unlink, test_support.TESTFN)
         for encoding in tests:
             # Check if the BOM is written only once
             with codecs.open(test_support.TESTFN, 'w+', encoding=encoding) as f: