diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2005-11-24 22:00:56 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2005-11-24 22:00:56 (GMT) |
commit | 430f68b447f61aab20b7db58705f6b16b10d5149 (patch) | |
tree | 7823e10f6192058338044f9d9ec70dd22b60f07d /Lib | |
parent | a98e7694eecaaf05c299f5c9f4aa4d0985d374ee (diff) | |
download | cpython-430f68b447f61aab20b7db58705f6b16b10d5149.zip cpython-430f68b447f61aab20b7db58705f6b16b10d5149.tar.gz cpython-430f68b447f61aab20b7db58705f6b16b10d5149.tar.bz2 |
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.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_unicode.py | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index d85f171..e298a14 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -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, @@ -567,23 +585,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") |