1 """Tests the cola.core module's unicode handling"""
8 def test_core_decode():
9 """Test the core.decode function"""
10 filename
= helper
.fixture('unicode.txt')
11 expect
= core
.decode(core
.encode('unicøde'))
12 actual
= core
.read(filename
).strip()
13 assert expect
== actual
16 def test_core_encode():
17 """Test the core.encode function"""
18 filename
= helper
.fixture('unicode.txt')
19 expect
= core
.encode('unicøde')
20 actual
= core
.encode(core
.read(filename
).strip())
21 assert expect
== actual
24 def test_decode_None():
25 """Ensure that decode(None) returns None"""
27 actual
= core
.decode(None)
28 assert expect
== actual
31 def test_decode_utf8():
32 filename
= helper
.fixture('cyrillic-utf-8.txt')
33 actual
= core
.read(filename
)
34 assert actual
.encoding
== 'utf-8'
37 def test_decode_non_utf8():
38 filename
= helper
.fixture('cyrillic-cp1251.txt')
39 actual
= core
.read(filename
)
40 assert actual
.encoding
== 'iso-8859-15'
43 def test_decode_non_utf8_string():
44 filename
= helper
.fixture('cyrillic-cp1251.txt')
45 with
open(filename
, 'rb') as f
:
47 actual
= core
.decode(content
)
48 assert actual
.encoding
== 'iso-8859-15'
51 def test_guess_mimetype():
54 actual
= core
.guess_mimetype(value
)
55 assert expect
== actual
56 # This function is robust to bytes vs. unicode
57 actual
= core
.guess_mimetype(core
.encode(value
))
58 assert expect
== actual