Back to index

python3.2  3.2.2
Public Member Functions
test.test_io.CIncrementalNewlineDecoderTest Class Reference
Inheritance diagram for test.test_io.CIncrementalNewlineDecoderTest:
Inheritance graph
[legend]
Collaboration diagram for test.test_io.CIncrementalNewlineDecoderTest:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def check_newline_decoding_utf8
def check_newline_decoding
def test_newline_decoder
def test_newline_bytes

Detailed Description

Definition at line 2468 of file test_io.py.


Member Function Documentation

def test.test_io.IncrementalNewlineDecoderTest.check_newline_decoding (   self,
  decoder,
  encoding 
) [inherited]

Definition at line 2406 of file test_io.py.

02406 
02407     def check_newline_decoding(self, decoder, encoding):
02408         result = []
02409         if encoding is not None:
02410             encoder = codecs.getincrementalencoder(encoding)()
02411             def _decode_bytewise(s):
02412                 # Decode one byte at a time
02413                 for b in encoder.encode(s):
02414                     result.append(decoder.decode(bytes([b])))
02415         else:
02416             encoder = None
02417             def _decode_bytewise(s):
02418                 # Decode one char at a time
02419                 for c in s:
02420                     result.append(decoder.decode(c))
02421         self.assertEqual(decoder.newlines, None)
02422         _decode_bytewise("abc\n\r")
02423         self.assertEqual(decoder.newlines, '\n')
02424         _decode_bytewise("\nabc")
02425         self.assertEqual(decoder.newlines, ('\n', '\r\n'))
02426         _decode_bytewise("abc\r")
02427         self.assertEqual(decoder.newlines, ('\n', '\r\n'))
02428         _decode_bytewise("abc")
02429         self.assertEqual(decoder.newlines, ('\r', '\n', '\r\n'))
02430         _decode_bytewise("abc\r")
02431         self.assertEqual("".join(result), "abc\n\nabcabc\nabcabc")
02432         decoder.reset()
02433         input = "abc"
02434         if encoder is not None:
02435             encoder.reset()
02436             input = encoder.encode(input)
02437         self.assertEqual(decoder.decode(input), "abc")
02438         self.assertEqual(decoder.newlines, None)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2364 of file test_io.py.

02364 
02365     def check_newline_decoding_utf8(self, decoder):
02366         # UTF-8 specific tests for a newline decoder
02367         def _check_decode(b, s, **kwargs):
02368             # We exercise getstate() / setstate() as well as decode()
02369             state = decoder.getstate()
02370             self.assertEqual(decoder.decode(b, **kwargs), s)
02371             decoder.setstate(state)
02372             self.assertEqual(decoder.decode(b, **kwargs), s)
02373 
02374         _check_decode(b'\xe8\xa2\x88', "\u8888")
02375 
02376         _check_decode(b'\xe8', "")
02377         _check_decode(b'\xa2', "")
02378         _check_decode(b'\x88', "\u8888")
02379 
02380         _check_decode(b'\xe8', "")
02381         _check_decode(b'\xa2', "")
02382         _check_decode(b'\x88', "\u8888")
02383 
02384         _check_decode(b'\xe8', "")
02385         self.assertRaises(UnicodeDecodeError, decoder.decode, b'', final=True)
02386 
02387         decoder.reset()
02388         _check_decode(b'\n', "\n")
02389         _check_decode(b'\r', "")
02390         _check_decode(b'', "\n", final=True)
02391         _check_decode(b'\r', "\n", final=True)
02392 
02393         _check_decode(b'\r', "")
02394         _check_decode(b'a', "\na")
02395 
02396         _check_decode(b'\r\r\n', "\n\n")
02397         _check_decode(b'\r', "")
02398         _check_decode(b'\r', "\n")
02399         _check_decode(b'\na', "\na")
02400 
02401         _check_decode(b'\xe8\xa2\x88\r\n', "\u8888\n")
02402         _check_decode(b'\xe8\xa2\x88', "\u8888")
02403         _check_decode(b'\n', "\n")
02404         _check_decode(b'\xe8\xa2\x88\r', "\u8888")
02405         _check_decode(b'\n', "\n")

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2455 of file test_io.py.

02455 
02456     def test_newline_bytes(self):
02457         # Issue 5433: Excessive optimization in IncrementalNewlineDecoder
02458         def _check(dec):
02459             self.assertEqual(dec.newlines, None)
02460             self.assertEqual(dec.decode("\u0D00"), "\u0D00")
02461             self.assertEqual(dec.newlines, None)
02462             self.assertEqual(dec.decode("\u0A00"), "\u0A00")
02463             self.assertEqual(dec.newlines, None)
02464         dec = self.IncrementalNewlineDecoder(None, translate=False)
02465         _check(dec)
02466         dec = self.IncrementalNewlineDecoder(None, translate=True)
02467         _check(dec)

Here is the call graph for this function:

Definition at line 2439 of file test_io.py.

02439 
02440     def test_newline_decoder(self):
02441         encodings = (
02442             # None meaning the IncrementalNewlineDecoder takes unicode input
02443             # rather than bytes input
02444             None, 'utf-8', 'latin-1',
02445             'utf-16', 'utf-16-le', 'utf-16-be',
02446             'utf-32', 'utf-32-le', 'utf-32-be',
02447         )
02448         for enc in encodings:
02449             decoder = enc and codecs.getincrementaldecoder(enc)()
02450             decoder = self.IncrementalNewlineDecoder(decoder, translate=True)
02451             self.check_newline_decoding(decoder, enc)
02452         decoder = codecs.getincrementaldecoder("utf-8")()
02453         decoder = self.IncrementalNewlineDecoder(decoder, translate=True)
02454         self.check_newline_decoding_utf8(decoder)

Here is the call graph for this function:


The documentation for this class was generated from the following file: