def testNetAsciiReaderBig(self): input_content = "I\nlike\ncrunchy\nbacon\n" for _ in range(5): input_content += input_content resp_data = StringResponseData(input_content) n = NetasciiReader(resp_data) self.assertGreater(n.size(), 0) self.assertGreater(n.size(), len(input_content)) block_size = 512 output = bytearray() while True: c = n.read(block_size) output += c if len(c) < block_size: break self.assertEqual(input_content.count("\n"), output.count(b"\r\n")) n.close()
def testNetAsciiReader(self): tests = [ # content, expected output ( "foo\nbar\nand another\none", bytearray(b"foo\r\nbar\r\nand another\r\none"), ), ( "foo\r\nbar\r\nand another\r\none", bytearray(b"foo\r\x00\r\nbar\r\x00\r\nand another\r\x00\r\none"), ), ] for input_content, expected in tests: with self.subTest(content=input_content): resp_data = StringResponseData(input_content) n = NetasciiReader(resp_data) self.assertGreater(n.size(), len(input_content)) output = n.read(512) self.assertEqual(output, expected) n.close()
def testNetAsciiReader(self): tests = [ # content, expected output ("foo\nbar\nand another\none", bytearray(b'foo\r\nbar\r\nand another\r\none')), ("foo\r\nbar\r\nand another\r\none", bytearray(b'foo\r\x00\r\nbar\r\x00\r\nand another\r\x00\r\none')), ] for input_content, expected in tests: with self.subTest(content=input_content): resp_data = StringResponseData(input_content) n = NetasciiReader(resp_data) self.assertGreater(n.size(), len(input_content)) output = n.read(512) self.assertEqual(output, expected) n.close()