README.md: mention @pavreh's PPA for Ubuntu 18.04 users
[git-cola.git] / test / core_test.py
blobab825322d3712cefeba3b39e911be3a49899e3f6
1 #!/usr/bin/env python
2 # encoding: utf-8
3 from __future__ import absolute_import, division, unicode_literals
4 import unittest
6 from cola import core
8 from . import helper
11 class CoreColaUnicodeTestCase(unittest.TestCase):
12 """Tests the cola.core module's unicode handling
13 """
15 def test_core_decode(self):
16 """Test the core.decode function
17 """
18 filename = helper.fixture('unicode.txt')
19 expect = core.decode(core.encode('unicøde'))
20 actual = core.read(filename).strip()
21 self.assertEqual(expect, actual)
23 def test_core_encode(self):
24 """Test the core.encode function
25 """
26 filename = helper.fixture('unicode.txt')
27 expect = core.encode('unicøde')
28 actual = core.encode(core.read(filename).strip())
29 self.assertEqual(expect, actual)
31 def test_decode_None(self):
32 """Ensure that decode(None) returns None"""
33 expect = None
34 actual = core.decode(None)
35 self.assertEqual(expect, actual)
37 def test_decode_utf8(self):
38 filename = helper.fixture('cyrillic-utf-8.txt')
39 actual = core.read(filename)
40 self.assertEqual(actual.encoding, 'utf-8')
42 def test_decode_non_utf8(self):
43 filename = helper.fixture('cyrillic-cp1251.txt')
44 actual = core.read(filename)
45 self.assertEqual(actual.encoding, 'iso-8859-15')
47 def test_decode_non_utf8_string(self):
48 filename = helper.fixture('cyrillic-cp1251.txt')
49 with open(filename, 'rb') as f:
50 content = f.read()
51 actual = core.decode(content)
52 self.assertEqual(actual.encoding, 'iso-8859-15')
55 if __name__ == '__main__':
56 unittest.main()