Kaydet (Commit) 7684f852 authored tarafından Amaury Forgeot d'Arc's avatar Amaury Forgeot d'Arc

In test_io, StatefulIncrementalDecoderTest was not part of the test suite.

And of course, the test failed:
a bytearray was used without reason in io.TextIOWrapper.tell().

The difference is that iterating over bytes (i.e. str in python2.6) returns 1-char bytes,
whereas bytearrays yield integers.
This code should still work with python3.0
üst 64a4bbeb
...@@ -1528,8 +1528,7 @@ class TextIOWrapper(TextIOBase): ...@@ -1528,8 +1528,7 @@ class TextIOWrapper(TextIOBase):
# nearest "safe start point" before the current location # nearest "safe start point" before the current location
# (a point where the decoder has nothing buffered, so seek() # (a point where the decoder has nothing buffered, so seek()
# can safely start from there and advance to this location). # can safely start from there and advance to this location).
next_byte = bytearray(1) for next_byte in next_input:
for next_byte[0] in next_input:
bytes_fed += 1 bytes_fed += 1
chars_decoded += len(decoder.decode(next_byte)) chars_decoded += len(decoder.decode(next_byte))
dec_buffer, dec_flags = decoder.getstate() dec_buffer, dec_flags = decoder.getstate()
......
...@@ -560,9 +560,9 @@ class StatefulIncrementalDecoder(codecs.IncrementalDecoder): ...@@ -560,9 +560,9 @@ class StatefulIncrementalDecoder(codecs.IncrementalDecoder):
def process_word(self): def process_word(self):
output = '' output = ''
if self.buffer[0] == 'i': if self.buffer[0] == ord('i'):
self.i = min(99, int(self.buffer[1:] or 0)) # set input length self.i = min(99, int(self.buffer[1:] or 0)) # set input length
elif self.buffer[0] == 'o': elif self.buffer[0] == ord('o'):
self.o = min(99, int(self.buffer[1:] or 0)) # set output length self.o = min(99, int(self.buffer[1:] or 0)) # set output length
else: else:
output = self.buffer.decode('ascii') output = self.buffer.decode('ascii')
...@@ -1160,10 +1160,10 @@ class MiscIOTest(unittest.TestCase): ...@@ -1160,10 +1160,10 @@ class MiscIOTest(unittest.TestCase):
def test_main(): def test_main():
test_support.run_unittest(IOTest, BytesIOTest, StringIOTest, test_support.run_unittest(IOTest, BytesIOTest, StringIOTest,
BufferedReaderTest, BufferedReaderTest, BufferedWriterTest,
BufferedWriterTest, BufferedRWPairTest, BufferedRWPairTest, BufferedRandomTest,
BufferedRandomTest, TextIOWrapperTest, StatefulIncrementalDecoderTest,
MiscIOTest) TextIOWrapperTest, MiscIOTest)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment