~mbernis/openlp/2.2_remote_app_enhancement

« back to all changes in this revision

Viewing changes to tests/functional/openlp_core_utils/test_utils.py

  • Committer: Tim Bentley
  • Date: 2012-12-08 11:27:22 UTC
  • mfrom: (2127 openlp)
  • mto: This revision was merged to the branch mainline in revision 2149.
  • Revision ID: tim.bentley@gmail.com-20121208112722-sy5wud6xz1xsmrty
Head

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
Functional tests to test the AppLocation class and related methods.
 
3
"""
 
4
from unittest import TestCase
 
5
 
 
6
from mock import patch
 
7
 
 
8
from openlp.core.utils import get_filesystem_encoding, _get_frozen_path
 
9
 
 
10
class TestUtils(TestCase):
 
11
    """
 
12
    A test suite to test out various methods around the AppLocation class.
 
13
    """
 
14
    def get_filesystem_encoding_test(self):
 
15
        """
 
16
        Test the get_filesystem_encoding() function
 
17
        """
 
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'
 
22
 
 
23
            # WHEN: get_filesystem_encoding() is called
 
24
            result = get_filesystem_encoding()
 
25
 
 
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"'
 
30
 
 
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'
 
34
 
 
35
            # WHEN: get_filesystem_encoding() is called
 
36
            result = get_filesystem_encoding()
 
37
 
 
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"'
 
42
 
 
43
    def get_frozen_path_test(self):
 
44
        """
 
45
        Test the _get_frozen_path() function
 
46
        """
 
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
 
54
            mocked_sys.frozen = 1
 
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"'
 
58