core: add decode_seq() helper
[git-cola.git] / test / core_test.py
blob277835322a717bb6bdda1f3b3fe5c1d5046ef8bc
1 # encoding: utf-8
2 """Tests the cola.core module's unicode handling"""
3 from __future__ import absolute_import, division, print_function, unicode_literals
5 from cola import core
7 from . import helper
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"""
28 expect = 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:
48 content = f.read()
49 actual = core.decode(content)
50 assert actual.encoding == 'iso-8859-15'
53 def test_guess_mimetype():
54 value = '字龍.txt'
55 expect = 'text/plain'
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