19
19
from __future__ import unicode_literals
21
from contextlib import contextmanager
25
27
from quickstart.cli import base
26
28
from quickstart.tests.cli import helpers as cli_helpers
31
class TestCheckEncoding(unittest.TestCase):
34
def patch_urwid(self, supports_unicode=True):
35
"""Patch the urwid.set_encoding and urwid.supports_unicode calls.
37
Ensure the mock functions are called once with the expected arguments.
39
Make the latter return the given supports_unicode argument.
41
mock_supports_unicode = mock.Mock(return_value=supports_unicode)
42
with mock.patch('urwid.set_encoding') as mock_set_encoding:
43
with mock.patch('urwid.supports_unicode', mock_supports_unicode):
45
mock_set_encoding.assert_called_once_with('utf-8')
46
mock_supports_unicode.assert_called_once_with()
48
def test_unicode_supported(self):
49
# The utf-8 encoding is properly set and the function exits without
51
with self.patch_urwid(supports_unicode=True):
52
base._check_encoding()
54
def test_unicode_not_supported(self):
55
# If unicode is not supported, the program exits with an error.
56
with self.patch_urwid(supports_unicode=False):
57
with self.assertRaises(SystemExit) as context_manager:
58
base._check_encoding()
60
b'Error: your terminal does not seem to support UTF-8 encoding.',
61
bytes(context_manager.exception))
29
64
class TestMainLoop(unittest.TestCase):