2
Functional tests to test the AppLocation class and related methods.
4
from unittest import TestCase
8
from openlp.core.utils import get_filesystem_encoding, _get_frozen_path
10
class TestUtils(TestCase):
12
A test suite to test out various methods around the AppLocation class.
14
def get_filesystem_encoding_test(self):
16
Test the get_filesystem_encoding() function
18
with patch(u'openlp.core.utils.sys.getfilesystemencoding') as mocked_getfilesystemencoding, \
19
patch(u'openlp.core.utils.sys.getdefaultencoding') as mocked_getdefaultencoding:
20
# GIVEN: sys.getfilesystemencoding returns "cp1252"
21
mocked_getfilesystemencoding.return_value = u'cp1252'
23
# WHEN: get_filesystem_encoding() is called
24
result = get_filesystem_encoding()
26
# THEN: getdefaultencoding should have been called
27
mocked_getfilesystemencoding.assert_called_with()
28
assert not mocked_getdefaultencoding.called
29
assert result == u'cp1252', u'The result should be "cp1252"'
31
# GIVEN: sys.getfilesystemencoding returns None and sys.getdefaultencoding returns "utf-8"
32
mocked_getfilesystemencoding.return_value = None
33
mocked_getdefaultencoding.return_value = u'utf-8'
35
# WHEN: get_filesystem_encoding() is called
36
result = get_filesystem_encoding()
38
# THEN: getdefaultencoding should have been called
39
mocked_getfilesystemencoding.assert_called_with()
40
mocked_getdefaultencoding.assert_called_with()
41
assert result == u'utf-8', u'The result should be "utf-8"'
43
def get_frozen_path_test(self):
45
Test the _get_frozen_path() function
47
with patch(u'openlp.core.utils.sys') as mocked_sys:
48
# GIVEN: The sys module "without" a "frozen" attribute
49
mocked_sys.frozen = None
50
# WHEN: We call _get_frozen_path() with two parameters
51
# THEN: The non-frozen parameter is returned
52
assert _get_frozen_path(u'frozen', u'not frozen') == u'not frozen', u'Should return "not frozen"'
53
# GIVEN: The sys module *with* a "frozen" attribute
55
# WHEN: We call _get_frozen_path() with two parameters
56
# THEN: The frozen parameter is returned
57
assert _get_frozen_path(u'frozen', u'not frozen') == u'frozen', u'Should return "frozen"'