]> 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 12:51:42 +0000 (14:51 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Mon, 23 May 2011 12:51:42 +0000 (14:51 +0200)
Lib/test/test_codecs.py

index 93cdf915b89383accc8ec820d0f5032166e7c2ed..e412a6444e2b3cf2716363aba71c8477eb0e6ab1 100644 (file)
@@ -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: