Ejemplo n.º 1
0
    def test_wrong_encoding(self):
        with self.assertRaises(UnicodeDecodeError):
            reader, closefunc = _from_csv_path('sample_text_utf16.csv',
                                               encoding='utf-8',
                                               dialect='excel')
            self.addCleanup(closefunc)

            list(reader)  # Trigger evaluation.

        with self.assertRaises(UnicodeDecodeError):
            reader, closefunc = _from_csv_path('sample_text_iso88591.csv',
                                               encoding='ascii',
                                               dialect='excel')
            self.addCleanup(closefunc)
            list(reader)  # Trigger evaluation.

        if PY2:
            return  # <- EXIT!

        # Following ISO-8859-1 (mis-identified as UTF-8) doesn't fail on Py 2.x.
        with self.assertRaises(UnicodeDecodeError):
            reader, closefunc = _from_csv_path('sample_text_iso88591.csv',
                                               encoding='utf-8',
                                               dialect='excel')
            self.addCleanup(closefunc)
            list(reader)  # Trigger evaluation.
Ejemplo n.º 2
0
 def test_utf8(self):
     reader = _from_csv_path('sample_text_utf8.csv', encoding='utf-8')
     expected = [
         ['col1', 'col2'],
         ['utf8', chr(0x003b1)],  # chr(0x003b1) -> α
     ]
     self.assertEqual(list(reader), expected)
Ejemplo n.º 3
0
 def test_iso88591(self):
     reader = _from_csv_path('sample_text_iso88591.csv',
                             encoding='iso8859-1')
     expected = [
         ['col1', 'col2'],
         ['iso88591', chr(0xe6)],  # chr(0xe6) -> æ
     ]
     self.assertEqual(list(reader), expected)
Ejemplo n.º 4
0
    def test_iso88591(self):
        reader, closefunc = _from_csv_path('sample_text_iso88591.csv',
                                           encoding='iso8859-1',
                                           dialect='excel')
        self.addCleanup(closefunc)

        expected = [
            ['col1', 'col2'],
            ['iso88591', unicode_ash],
        ]
        self.assertEqual(list(reader), expected)
Ejemplo n.º 5
0
    def test_utf16(self):
        reader, closefunc = _from_csv_path('sample_text_utf16.csv',
                                           encoding='utf-16',
                                           dialect='excel')
        self.addCleanup(closefunc)

        expected = [
            ['col1', 'col2'],
            ['utf16', 'abc'],
        ]
        self.assertEqual(list(reader), expected)
Ejemplo n.º 6
0
    def test_utf8_with_bom(self):
        reader, closefunc = _from_csv_path('sample_text_utf8_bom.csv',
                                           encoding='utf-8-sig',
                                           dialect='excel')
        self.addCleanup(closefunc)

        expected = [
            ['col1', 'col2'],
            ['utf8', unicode_alpha],
        ]
        self.assertEqual(list(reader), expected)
Ejemplo n.º 7
0
 def test_file_not_found(self):
     with self.assertRaises(FileNotFoundError):
         reader, _ = _from_csv_path('missing_file.csv',
                                    encoding='iso8859-1',
                                    dialect='excel')
Ejemplo n.º 8
0
 def test_file_not_found(self):
     with self.assertRaises(FileNotFoundError):
         reader = _from_csv_path('missing_file.csv', encoding='iso8859-1')
         list(reader)  # Trigger evaluation.
Ejemplo n.º 9
0
 def test_wrong_encoding(self):
     with self.assertRaises(UnicodeDecodeError):
         reader = _from_csv_path('sample_text_iso88591.csv',
                                 encoding='utf-8')
         list(reader)  # Trigger evaluation.