[Python-checkins] commit of r41530 - python/trunk/Lib/test

neal.norwitz@python.org neal.norwitz at python.org
Thu Nov 24 23:01:02 CET 2005


Author: neal.norwitz
Date: Thu Nov 24 23:00:56 2005
New Revision: 41530

Modified:
   python/trunk/Lib/test/test_unicode.py
Log:
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.



Modified: python/trunk/Lib/test/test_unicode.py
==============================================================================
--- python/trunk/Lib/test/test_unicode.py	(original)
+++ python/trunk/Lib/test/test_unicode.py	Thu Nov 24 23:00:56 2005
@@ -9,6 +9,24 @@
 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,
@@ -567,23 +585,6 @@
         # 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")


More information about the Python-checkins mailing list