3 from __future__
import absolute_import
, division
, unicode_literals
11 class CoreColaUnicodeTestCase(unittest
.TestCase
):
12 """Tests the cola.core module's unicode handling
15 def test_core_decode(self
):
16 """Test the core.decode function
18 filename
= helper
.fixture('unicode.txt')
19 expect
= core
.decode(core
.encode('unicøde'))
20 actual
= core
.read(filename
).strip()
21 self
.assertEqual(expect
, actual
)
23 def test_core_encode(self
):
24 """Test the core.encode function
26 filename
= helper
.fixture('unicode.txt')
27 expect
= core
.encode('unicøde')
28 actual
= core
.encode(core
.read(filename
).strip())
29 self
.assertEqual(expect
, actual
)
31 def test_decode_None(self
):
32 """Ensure that decode(None) returns None"""
34 actual
= core
.decode(None)
35 self
.assertEqual(expect
, actual
)
37 def test_decode_utf8(self
):
38 filename
= helper
.fixture('cyrillic-utf-8.txt')
39 actual
= core
.read(filename
)
40 self
.assertEqual(actual
.encoding
, 'utf-8')
42 def test_decode_non_utf8(self
):
43 filename
= helper
.fixture('cyrillic-cp1251.txt')
44 actual
= core
.read(filename
)
45 self
.assertEqual(actual
.encoding
, 'iso-8859-15')
47 def test_decode_non_utf8_string(self
):
48 filename
= helper
.fixture('cyrillic-cp1251.txt')
49 with
open(filename
, 'rb') as f
:
51 actual
= core
.decode(content
)
52 self
.assertEqual(actual
.encoding
, 'iso-8859-15')
55 if __name__
== '__main__':