File: core_test.py

package info (click to toggle)
git-cola 4.13.0-1
  • links: PTS
  • area: main
  • in suites: sid
  • size: 6,480 kB
  • sloc: python: 36,938; sh: 304; makefile: 223; xml: 100; tcl: 62
file content (58 lines) | stat: -rw-r--r-- 1,528 bytes parent folder | download | duplicates (2)
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
57
58
"""Tests the cola.core module's unicode handling"""

from cola import core

from . import helper


def test_core_decode():
    """Test the core.decode function"""
    filename = helper.fixture('unicode.txt')
    expect = core.decode(core.encode('unicøde'))
    actual = core.read(filename).strip()
    assert expect == actual


def test_core_encode():
    """Test the core.encode function"""
    filename = helper.fixture('unicode.txt')
    expect = core.encode('unicøde')
    actual = core.encode(core.read(filename).strip())
    assert expect == actual


def test_decode_None():
    """Ensure that decode(None) returns None"""
    expect = None
    actual = core.decode(None)
    assert expect == actual


def test_decode_utf8():
    filename = helper.fixture('cyrillic-utf-8.txt')
    actual = core.read(filename)
    assert actual.encoding == 'utf-8'


def test_decode_non_utf8():
    filename = helper.fixture('cyrillic-cp1251.txt')
    actual = core.read(filename)
    assert actual.encoding == 'iso-8859-15'


def test_decode_non_utf8_string():
    filename = helper.fixture('cyrillic-cp1251.txt')
    with open(filename, 'rb') as f:
        content = f.read()
    actual = core.decode(content)
    assert actual.encoding == 'iso-8859-15'


def test_guess_mimetype():
    value = '字龍.txt'
    expect = 'text/plain'
    actual = core.guess_mimetype(value)
    assert expect == actual
    # This function is robust to bytes vs. unicode
    actual = core.guess_mimetype(core.encode(value))
    assert expect == actual