File: test_issue84_cli_encoding.py

package info (click to toggle)
segno 1.6.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,068 kB
  • sloc: python: 9,936; makefile: 162; javascript: 16
file content (62 lines) | stat: -rw-r--r-- 1,805 bytes parent folder | download
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
59
60
61
62
#
# Copyright (c) 2016 - 2024 -- Lars Heuer
# All rights reserved.
#
# License: BSD License
#
"""\
Tests against issue #84.
<https://github.com/heuer/segno/issues/84>
"""
import os
import tempfile
from segno import cli
import pytest


def test_issue_84_default_encoding():
    with open(os.path.join(os.path.dirname(__file__), 'issue-84',
                           'issue-84-iso-8859-1.txt')) as f:
        expected = f.read()
    f = tempfile.NamedTemporaryFile('w', suffix='.txt', delete=False)
    f.close()
    try:
        cli.main(['-o', f.name, 'Müller'])
        with open(f.name) as f:
            result = f.read()
        assert expected == result
        # Explicit but default encoding
        cli.main(['-o', f.name, '--encoding', 'iso-8859-1', 'Müller'])
        with open(f.name) as f:
            result = f.read()
        assert expected == result
        # Explicit but default encoding
        cli.main(['-o', f.name, '--encoding', 'latin1', 'Müller'])
        with open(f.name) as f:
            result = f.read()
        assert expected == result
    finally:
        os.unlink(f.name)


def test_issue_84_utf8():
    with open(os.path.join(os.path.dirname(__file__), 'issue-84',
                           'issue-84-utf-8.txt')) as f:
        expected = f.read()
    f = tempfile.NamedTemporaryFile('w', suffix='.txt', delete=False)
    f.close()
    try:
        cli.main(['-o', f.name, '--encoding', 'utf-8', 'Müller'])
        with open(f.name) as f:
            result = f.read()
        assert expected == result
        cli.main(['-o', f.name, '--encoding', 'UTf-8', 'Müller'])
        with open(f.name) as f:
            result = f.read()
        assert expected == result
    finally:
        os.unlink(f.name)


if __name__ == '__main__':
    pytest.main([__file__])