]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport of r41530 (neal.norwitz, 2005-11-24):
authorMartin v. Löwis <martin@v.loewis.de>
Mon, 27 Mar 2006 21:38:32 +0000 (21:38 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Mon, 27 Mar 2006 21:38:32 +0000 (21:38 +0000)
Move registration of the codec search function to the module scope
so it is only executed once.  Otherwise the same search function is
repeated added to the codec search path when regrtest is run with -R
and leaks are reported.

Lib/test/test_unicode.py

index 7f8cf5097c0e8efafea8fdd96358f01fdf61f25b..7f6a1523c43b9465a8c8d8e2f9fe46ffd78dc886 100644 (file)
@@ -9,6 +9,24 @@ Written by Marc-Andre Lemburg (mal@lemburg.com).
 import unittest, sys, string, codecs, new
 from test import test_support, string_tests
 
+# Error handling (bad decoder return)
+def search_function(encoding):
+    def decode1(input, errors="strict"):
+        return 42 # not a tuple
+    def encode1(input, errors="strict"):
+        return 42 # not a tuple
+    def encode2(input, errors="strict"):
+        return (42, 42) # no unicode
+    def decode2(input, errors="strict"):
+        return (42, 42) # no unicode
+    if encoding=="test.unicode1":
+        return (encode1, decode1, None, None)
+    elif encoding=="test.unicode2":
+        return (encode2, decode2, None, None)
+    else:
+        return None
+codecs.register(search_function)
+
 class UnicodeTest(
     string_tests.CommonTest,
     string_tests.MixinStrUnicodeUserStringTest,
@@ -578,23 +596,6 @@ class UnicodeTest(
         # Error handling (truncated escape sequence)
         self.assertRaises(UnicodeError, "\\".decode, "unicode-escape")
 
-        # Error handling (bad decoder return)
-        def search_function(encoding):
-            def decode1(input, errors="strict"):
-                return 42 # not a tuple
-            def encode1(input, errors="strict"):
-                return 42 # not a tuple
-            def encode2(input, errors="strict"):
-                return (42, 42) # no unicode
-            def decode2(input, errors="strict"):
-                return (42, 42) # no unicode
-            if encoding=="test.unicode1":
-                return (encode1, decode1, None, None)
-            elif encoding=="test.unicode2":
-                return (encode2, decode2, None, None)
-            else:
-                return None
-        codecs.register(search_function)
         self.assertRaises(TypeError, "hello".decode, "test.unicode1")
         self.assertRaises(TypeError, unicode, "hello", "test.unicode2")
         self.assertRaises(TypeError, u"hello".encode, "test.unicode1")