diff options
author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-04-01 22:52:48 (GMT) |
---|---|---|
committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-04-01 22:52:48 (GMT) |
commit | f0a49708eb1a00eca83dbe26eb47e8506b80225f (patch) | |
tree | c7219f2171df01f9dddf5ad664c93c947bbbd3c4 /Lib | |
parent | ce6f6c12c69d6745addf8b12623ab5cc768b0f79 (diff) | |
download | cpython-f0a49708eb1a00eca83dbe26eb47e8506b80225f.zip cpython-f0a49708eb1a00eca83dbe26eb47e8506b80225f.tar.gz cpython-f0a49708eb1a00eca83dbe26eb47e8506b80225f.tar.bz2 |
Newly enabled test appears to leak:
it registers the same codec on each iteration.
Do it only once at load time.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_io.py | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 39d3e5b..7110259 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -574,6 +574,22 @@ class StatefulIncrementalDecoder(codecs.IncrementalDecoder): self.buffer = bytearray() return output + codecEnabled = False + + @classmethod + def lookupTestDecoder(cls, name): + if cls.codecEnabled and name == 'test_decoder': + return codecs.CodecInfo( + name='test_decoder', encode=None, decode=None, + incrementalencoder=None, + streamreader=None, streamwriter=None, + incrementaldecoder=cls) + +# Register the previous decoder for testing. +# Disabled by default, tests will enable it. +codecs.register(StatefulIncrementalDecoder.lookupTestDecoder) + + class StatefulIncrementalDecoderTest(unittest.TestCase): """ Make sure the StatefulIncrementalDecoder actually works. @@ -898,14 +914,6 @@ class TextIOWrapperTest(unittest.TestCase): def testSeekAndTell(self): """Test seek/tell using the StatefulIncrementalDecoder.""" - def lookupTestDecoder(name): - if self.codecEnabled and name == 'test_decoder': - return codecs.CodecInfo( - name='test_decoder', encode=None, decode=None, - incrementalencoder=None, - streamreader=None, streamwriter=None, - incrementaldecoder=StatefulIncrementalDecoder) - def testSeekAndTellWithData(data, min_pos=0): """Tell/seek to various points within a data stream and ensure that the decoded data returned by read() is consistent.""" @@ -926,9 +934,8 @@ class TextIOWrapperTest(unittest.TestCase): self.assertEquals(f.read(), decoded[i:]) f.close() - # Register a special incremental decoder for testing. - codecs.register(lookupTestDecoder) - self.codecEnabled = 1 + # Enable the test decoder. + StatefulIncrementalDecoder.codecEnabled = 1 # Run the tests. try: @@ -947,7 +954,7 @@ class TextIOWrapperTest(unittest.TestCase): # Ensure our test decoder won't interfere with subsequent tests. finally: - self.codecEnabled = 0 + StatefulIncrementalDecoder.codecEnabled = 0 def testEncodedWrites(self): data = u"1234567890" |