diff --git a/tests/functional/openlp_core_utils/test_utils.py b/tests/functional/openlp_core_utils/test_utils.py index 148380cbe..ae8894661 100644 --- a/tests/functional/openlp_core_utils/test_utils.py +++ b/tests/functional/openlp_core_utils/test_utils.py @@ -15,7 +15,30 @@ class TestUtils(TestCase): """ Test the get_filesystem_encoding() function """ - assert False, u'This test needs to be written' + with patch(u'sys.getfilesystemencoding') as mocked_getfilesystemencoding, \ + patch(u'sys.getdefaultencoding') as mocked_getdefaultencoding: + # GIVEN: sys.getfilesystemencoding returns "cp1252" + mocked_getfilesystemencoding.return_value = u'cp1252' + + # WHEN: get_filesystem_encoding() is called + result = get_filesystem_encoding() + + # THEN: getdefaultencoding should have been called + mocked_getfilesystemencoding.assert_called_with() + assert not mocked_getdefaultencoding.called + assert result == u'cp1252', u'The result should be "cp1252"' + + # GIVEN: sys.getfilesystemencoding returns None and sys.getdefaultencoding returns "utf-8" + mocked_getfilesystemencoding.return_value = None + mocked_getdefaultencoding.return_value = u'utf-8' + + # WHEN: get_filesystem_encoding() is called + result = get_filesystem_encoding() + + # THEN: getdefaultencoding should have been called + mocked_getfilesystemencoding.assert_called_with() + mocked_getdefaultencoding.assert_called_with() + assert result == u'utf-8', u'The result should be "utf-8"' def get_frozen_path_test(self): """