forked from git-cola/git-cola
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core_test.py
56 lines (44 loc) · 1.66 KB
/
core_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
# encoding: utf-8
from __future__ import absolute_import, division, unicode_literals
import unittest
from cola import core
from . import helper
class CoreColaUnicodeTestCase(unittest.TestCase):
"""Tests the cola.core module's unicode handling
"""
def test_core_decode(self):
"""Test the core.decode function
"""
filename = helper.fixture('unicode.txt')
expect = core.decode(core.encode('unicøde'))
actual = core.read(filename).strip()
self.assertEqual(expect, actual)
def test_core_encode(self):
"""Test the core.encode function
"""
filename = helper.fixture('unicode.txt')
expect = core.encode('unicøde')
actual = core.encode(core.read(filename).strip())
self.assertEqual(expect, actual)
def test_decode_None(self):
"""Ensure that decode(None) returns None"""
expect = None
actual = core.decode(None)
self.assertEqual(expect, actual)
def test_decode_utf8(self):
filename = helper.fixture('cyrillic-utf-8.txt')
actual = core.read(filename)
self.assertEqual(actual.encoding, 'utf-8')
def test_decode_non_utf8(self):
filename = helper.fixture('cyrillic-cp1251.txt')
actual = core.read(filename)
self.assertEqual(actual.encoding, 'iso-8859-15')
def test_decode_non_utf8_string(self):
filename = helper.fixture('cyrillic-cp1251.txt')
with open(filename, 'rb') as f:
content = f.read()
actual = core.decode(content)
self.assertEqual(actual.encoding, 'iso-8859-15')
if __name__ == '__main__':
unittest.main()