]> granicus.if.org Git - python/commitdiff
Fix my test introduced in test_sys by r79394:
authorVictor Stinner <victor.stinner@haypocalc.com>
Thu, 25 Mar 2010 12:24:38 +0000 (12:24 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Thu, 25 Mar 2010 12:24:38 +0000 (12:24 +0000)
Restore the orginal filesystem encoding before testing
assertRaises(LookupError, sys.setfilesystemencoding, "xxx"). Unittest formats
the exception, but the formatting failed because the file system was invalid
(set to iso-8859-1 by the previous test).

Anyway, ensure to restore the original filesystem encoding when exiting
test_setfilesystemencoding() to avoid error propagation to the other tests.

Lib/test/test_sys.py

index 23ec39962c1a669617f2f541ac5356331091b30e..1b21f50f313f3518c1307cd3640f68f275385afc 100644 (file)
@@ -797,10 +797,15 @@ class SizeofTest(unittest.TestCase):
 
     def test_setfilesystemencoding(self):
         old = sys.getfilesystemencoding()
-        sys.setfilesystemencoding("iso-8859-1")
-        self.assertEqual(sys.getfilesystemencoding(), "iso-8859-1")
-        self.assertRaises(LookupError, sys.setfilesystemencoding, "xxx")
-        sys.setfilesystemencoding(old)
+        try:
+            sys.setfilesystemencoding("iso-8859-1")
+            self.assertEqual(sys.getfilesystemencoding(), "iso-8859-1")
+        finally:
+            sys.setfilesystemencoding(old)
+        try:
+            self.assertRaises(LookupError, sys.setfilesystemencoding, "xxx")
+        finally:
+            sys.setfilesystemencoding(old)
 
 def test_main():
     test.support.run_unittest(SysModuleTest, SizeofTest)