git-cola v4.6.0
[git-cola.git] / test / core_test.py
blobf6ae516eaa4ca22a68e0afaf7910090101e4826f
1 """Tests the cola.core module's unicode handling"""
3 from cola import core
5 from . import helper
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"""
26 expect = 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:
46 content = f.read()
47 actual = core.decode(content)
48 assert actual.encoding == 'iso-8859-15'
51 def test_guess_mimetype():
52 value = '字龍.txt'
53 expect = 'text/plain'
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