[Python-checkins] r62096 - python/trunk/Lib/test/test_io.py
amaury.forgeotdarc
python-checkins at python.org
Wed Apr 2 00:52:49 CEST 2008
Author: amaury.forgeotdarc
Date: Wed Apr 2 00:52:48 2008
New Revision: 62096
Modified:
python/trunk/Lib/test/test_io.py
Log:
Newly enabled test appears to leak:
it registers the same codec on each iteration.
Do it only once at load time.
Modified: python/trunk/Lib/test/test_io.py
==============================================================================
--- python/trunk/Lib/test/test_io.py (original)
+++ python/trunk/Lib/test/test_io.py Wed Apr 2 00:52:48 2008
@@ -574,6 +574,22 @@
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 @@
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 @@
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 @@
# Ensure our test decoder won't interfere with subsequent tests.
finally:
- self.codecEnabled = 0
+ StatefulIncrementalDecoder.codecEnabled = 0
def testEncodedWrites(self):
data = u"1234567890"
More information about the Python-checkins
mailing list