2 """Tests the cola.core module's unicode handling"""
3 from __future__
import absolute_import
, division
, print_function
, unicode_literals
10 def test_core_decode():
11 """Test the core.decode function"""
12 filename
= helper
.fixture('unicode.txt')
13 expect
= core
.decode(core
.encode('unicøde'))
14 actual
= core
.read(filename
).strip()
15 assert expect
== actual
18 def test_core_encode():
19 """Test the core.encode function"""
20 filename
= helper
.fixture('unicode.txt')
21 expect
= core
.encode('unicøde')
22 actual
= core
.encode(core
.read(filename
).strip())
23 assert expect
== actual
26 def test_decode_None():
27 """Ensure that decode(None) returns None"""
29 actual
= core
.decode(None)
30 assert expect
== actual
33 def test_decode_utf8():
34 filename
= helper
.fixture('cyrillic-utf-8.txt')
35 actual
= core
.read(filename
)
36 assert actual
.encoding
== 'utf-8'
39 def test_decode_non_utf8():
40 filename
= helper
.fixture('cyrillic-cp1251.txt')
41 actual
= core
.read(filename
)
42 assert actual
.encoding
== 'iso-8859-15'
45 def test_decode_non_utf8_string():
46 filename
= helper
.fixture('cyrillic-cp1251.txt')
47 with
open(filename
, 'rb') as f
:
49 actual
= core
.decode(content
)
50 assert actual
.encoding
== 'iso-8859-15'
53 def test_guess_mimetype():
56 actual
= core
.guess_mimetype(value
)
57 assert expect
== actual
58 # This function is robust to bytes vs. unicode
59 actual
= core
.guess_mimetype(core
.encode(value
))
60 assert expect
== actual