diff options
author | Hai Shi <shihai1992@gmail.com> | 2020-10-16 16:34:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-16 10:34:15 +0200 |
commit | c9f696cb96d1c362d5cad871f61da520572d9b08 (patch) | |
tree | 4dbc6f4960f9058660751bd860589a6e9762ccc7 /Lib/test/test_codecs.py | |
parent | cf693e537dc8aaa14315a7f59baec4a31d1167d3 (diff) | |
download | cpython-git-c9f696cb96d1c362d5cad871f61da520572d9b08.tar.gz |
bpo-41919, test_codecs: Move codecs.register calls to setUp() (GH-22513)
* Move the codecs' (un)register operation to testcases.
* Remove _codecs._forget_codec() and _PyCodec_Forget()
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r-- | Lib/test/test_codecs.py | 25 |
1 files changed, 3 insertions, 22 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 09ceef76eb..9be8281ce5 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -2754,29 +2754,14 @@ _TEST_CODECS = {} def _get_test_codec(codec_name): return _TEST_CODECS.get(codec_name) -codecs.register(_get_test_codec) # Returns None, not usable as a decorator - -try: - # Issue #22166: Also need to clear the internal cache in CPython - from _codecs import _forget_codec -except ImportError: - def _forget_codec(codec_name): - pass class ExceptionChainingTest(unittest.TestCase): def setUp(self): - # There's no way to unregister a codec search function, so we just - # ensure we render this one fairly harmless after the test - # case finishes by using the test case repr as the codec name - # The codecs module normalizes codec names, although this doesn't - # appear to be formally documented... - # We also make sure we use a truly unique id for the custom codec - # to avoid issues with the codec cache when running these tests - # multiple times (e.g. when hunting for refleaks) - unique_id = repr(self) + str(id(self)) - self.codec_name = encodings.normalize_encoding(unique_id).lower() + self.codec_name = 'exception_chaining_test' + codecs.register(_get_test_codec) + self.addCleanup(codecs.unregister, _get_test_codec) # We store the object to raise on the instance because of a bad # interaction between the codec caching (which means we can't @@ -2791,10 +2776,6 @@ class ExceptionChainingTest(unittest.TestCase): _TEST_CODECS.pop(self.codec_name, None) # Issue #22166: Also pop from caches to avoid appearance of ref leaks encodings._cache.pop(self.codec_name, None) - try: - _forget_codec(self.codec_name) - except KeyError: - pass def set_codec(self, encode, decode): codec_info = codecs.CodecInfo(encode, decode, |