Пример #1
0
    def test_utf16_big(self):
        output = six.StringIO()
        writer = csv_py2.UnicodeWriter(output, encoding='utf-16-be')
        self.assertEqual(writer._eight_bit, False)
        writer.writerow(['a', 'b', 'c'])
        writer.writerow(['1', '2', '3'])
        writer.writerow(['4', '5', u'ʤ'])

        written = six.StringIO(output.getvalue())

        reader = csv_py2.UnicodeReader(written, encoding='utf-16-be')
        self.assertEqual(next(reader), ['a', 'b', 'c'])
        self.assertEqual(next(reader), ['1', '2', '3'])
        self.assertEqual(next(reader), ['4', '5', u'\u02A4'])
Пример #2
0
    def test_latin1(self):
        output = six.StringIO()
        writer = csv_py2.UnicodeWriter(output, encoding='latin1')
        self.assertEqual(writer._eight_bit, True)
        writer.writerow(['a', 'b', 'c'])
        writer.writerow(['1', '2', '3'])
        writer.writerow(['4', '5', u'©'])

        written = six.StringIO(output.getvalue())

        reader = csv_py2.UnicodeReader(written, encoding='latin1')
        self.assertEqual(next(reader), ['a', 'b', 'c'])
        self.assertEqual(next(reader), ['1', '2', '3'])
        self.assertEqual(next(reader), ['4', '5', u'©'])