Finish common

This commit is contained in:
Tim Bentley 2017-12-09 16:29:58 +00:00
parent 17b70f0c0a
commit ac95f4e3ca
6 changed files with 60 additions and 61 deletions

View File

@ -45,7 +45,7 @@ class TestOpenLPJsonDecoder(TestCase):
result = instance.object_hook({'__Path__': ['test', 'path']}) result = instance.object_hook({'__Path__': ['test', 'path']})
# THEN: A Path object should be returned # THEN: A Path object should be returned
self.assertEqual(result, Path('test', 'path')) assert result == Path('test', 'path')
def test_object_hook_non_path_object(self): def test_object_hook_non_path_object(self):
""" """
@ -59,8 +59,8 @@ class TestOpenLPJsonDecoder(TestCase):
result = instance.object_hook({'key': 'value'}) result = instance.object_hook({'key': 'value'})
# THEN: The object should be returned unchanged and a Path object should not have been initiated # THEN: The object should be returned unchanged and a Path object should not have been initiated
self.assertEqual(result, {'key': 'value'}) assert result == {'key': 'value'}
self.assertFalse(mocked_path.called) assert not mocked_path.called
def test_json_decode(self): def test_json_decode(self):
""" """
@ -73,7 +73,7 @@ class TestOpenLPJsonDecoder(TestCase):
obj = json.loads(json_string, cls=OpenLPJsonDecoder) obj = json.loads(json_string, cls=OpenLPJsonDecoder)
# THEN: The object returned should be a python version of the JSON string # THEN: The object returned should be a python version of the JSON string
self.assertEqual(obj, [Path('test', 'path1'), Path('test', 'path2')]) assert obj == [Path('test', 'path1'), Path('test', 'path2')]
class TestOpenLPJsonEncoder(TestCase): class TestOpenLPJsonEncoder(TestCase):
@ -91,7 +91,7 @@ class TestOpenLPJsonEncoder(TestCase):
result = instance.default(Path('test', 'path')) result = instance.default(Path('test', 'path'))
# THEN: A dictionary object that can be JSON encoded should be returned # THEN: A dictionary object that can be JSON encoded should be returned
self.assertEqual(result, {'__Path__': ('test', 'path')}) assert result == {'__Path__': ('test', 'path')}
def test_default_non_path_object(self): def test_default_non_path_object(self):
""" """
@ -119,4 +119,4 @@ class TestOpenLPJsonEncoder(TestCase):
json_string = json.dumps(obj, cls=OpenLPJsonEncoder) json_string = json.dumps(obj, cls=OpenLPJsonEncoder)
# THEN: The JSON string return should be a representation of the object encoded # THEN: The JSON string return should be a representation of the object encoded
self.assertEqual(json_string, '[{"__Path__": ["test", "path1"]}, {"__Path__": ["test", "path2"]}]') assert json_string == '[{"__Path__": ["test", "path1"]}, {"__Path__": ["test", "path2"]}]'

View File

@ -46,7 +46,7 @@ class TestRegistryProperties(TestCase, RegistryProperties):
# GIVEN an Empty Registry # GIVEN an Empty Registry
# WHEN there is no Application # WHEN there is no Application
# THEN the application should be none # THEN the application should be none
self.assertEqual(self.application, None, 'The application value should be None') assert not self.application, 'The application value should be None'
def test_application(self): def test_application(self):
""" """
@ -59,7 +59,7 @@ class TestRegistryProperties(TestCase, RegistryProperties):
Registry().register('application', application) Registry().register('application', application)
# THEN the application should be none # THEN the application should be none
self.assertEqual(self.application, application, 'The application value should match') assert self.application == application, 'The application value should match'
@patch('openlp.core.common.mixins.is_win') @patch('openlp.core.common.mixins.is_win')
def test_application_on_windows(self, mocked_is_win): def test_application_on_windows(self, mocked_is_win):
@ -74,7 +74,7 @@ class TestRegistryProperties(TestCase, RegistryProperties):
Registry().register('application', application) Registry().register('application', application)
# THEN the application should be none # THEN the application should be none
self.assertEqual(self.application, application, 'The application value should match') assert self.application == application, 'The application value should match'
@patch('openlp.core.common.mixins.is_win') @patch('openlp.core.common.mixins.is_win')
def test_get_application_on_windows(self, mocked_is_win): def test_get_application_on_windows(self, mocked_is_win):
@ -93,6 +93,6 @@ class TestRegistryProperties(TestCase, RegistryProperties):
actual_application = reg_props.application actual_application = reg_props.application
# THEN the application should be the mock object, and the correct function should have been called # THEN the application should be the mock object, and the correct function should have been called
self.assertEqual(mock_application, actual_application, 'The application value should match') assert mock_application == actual_application, 'The application value should match'
mocked_is_win.assert_called_with() mocked_is_win.assert_called_with()
mocked_get.assert_called_with('application') mocked_get.assert_called_with('application')

View File

@ -47,8 +47,8 @@ class TestShutil(TestCase):
result_args, result_kwargs = replace_params(test_args, test_kwargs, test_params) result_args, result_kwargs = replace_params(test_args, test_kwargs, test_params)
# THEN: The positional and keyword args should not have changed # THEN: The positional and keyword args should not have changed
self.assertEqual(test_args, result_args) assert test_args == result_args
self.assertEqual(test_kwargs, result_kwargs) assert test_kwargs == result_kwargs
def test_replace_params_params(self): def test_replace_params_params(self):
""" """
@ -63,8 +63,8 @@ class TestShutil(TestCase):
result_args, result_kwargs = replace_params(test_args, test_kwargs, test_params) result_args, result_kwargs = replace_params(test_args, test_kwargs, test_params)
# THEN: The positional and keyword args should have have changed # THEN: The positional and keyword args should have have changed
self.assertEqual(result_args, (1, '2')) assert result_args == (1, '2')
self.assertEqual(result_kwargs, {'arg3': '3', 'arg4': 4}) assert result_kwargs == {'arg3': '3', 'arg4': 4}
def test_copy(self): def test_copy(self):
""" """
@ -82,7 +82,7 @@ class TestShutil(TestCase):
# :func:`shutil.copy` as a Path object. # :func:`shutil.copy` as a Path object.
mocked_shutil_copy.assert_called_once_with(os.path.join('source', 'test', 'path'), mocked_shutil_copy.assert_called_once_with(os.path.join('source', 'test', 'path'),
os.path.join('destination', 'test', 'path')) os.path.join('destination', 'test', 'path'))
self.assertEqual(result, Path('destination', 'test', 'path')) assert result == Path('destination', 'test', 'path')
def test_copy_follow_optional_params(self): def test_copy_follow_optional_params(self):
""" """
@ -114,7 +114,7 @@ class TestShutil(TestCase):
# :func:`shutil.copyfile` as a Path object. # :func:`shutil.copyfile` as a Path object.
mocked_shutil_copyfile.assert_called_once_with(os.path.join('source', 'test', 'path'), mocked_shutil_copyfile.assert_called_once_with(os.path.join('source', 'test', 'path'),
os.path.join('destination', 'test', 'path')) os.path.join('destination', 'test', 'path'))
self.assertEqual(result, Path('destination', 'test', 'path')) assert result == Path('destination', 'test', 'path')
def test_copyfile_optional_params(self): def test_copyfile_optional_params(self):
""" """
@ -147,7 +147,7 @@ class TestShutil(TestCase):
# :func:`shutil.copytree` as a Path object. # :func:`shutil.copytree` as a Path object.
mocked_shutil_copytree.assert_called_once_with(os.path.join('source', 'test', 'path'), mocked_shutil_copytree.assert_called_once_with(os.path.join('source', 'test', 'path'),
os.path.join('destination', 'test', 'path')) os.path.join('destination', 'test', 'path'))
self.assertEqual(result, Path('destination', 'test', 'path')) assert result == Path('destination', 'test', 'path')
def test_copytree_optional_params(self): def test_copytree_optional_params(self):
""" """
@ -182,7 +182,7 @@ class TestShutil(TestCase):
# THEN: :func:`shutil.rmtree` should have been called with the str equivalents of the Path object. # THEN: :func:`shutil.rmtree` should have been called with the str equivalents of the Path object.
mocked_shutil_rmtree.assert_called_once_with( mocked_shutil_rmtree.assert_called_once_with(
os.path.join('test', 'path'), False, None) os.path.join('test', 'path'), False, None)
self.assertIsNone(result) assert not result
def test_rmtree_optional_params(self): def test_rmtree_optional_params(self):
""" """
@ -214,7 +214,7 @@ class TestShutil(TestCase):
# THEN: :func:`shutil.which` should have been called with the command, and :func:`which` should return None. # THEN: :func:`shutil.which` should have been called with the command, and :func:`which` should return None.
mocked_shutil_which.assert_called_once_with('no_command') mocked_shutil_which.assert_called_once_with('no_command')
self.assertIsNone(result) assert not result
def test_which_command(self): def test_which_command(self):
""" """
@ -230,7 +230,7 @@ class TestShutil(TestCase):
# THEN: :func:`shutil.which` should have been called with the command, and :func:`which` should return a # THEN: :func:`shutil.which` should have been called with the command, and :func:`which` should return a
# Path object equivalent of the command path. # Path object equivalent of the command path.
mocked_shutil_which.assert_called_once_with('command') mocked_shutil_which.assert_called_once_with('command')
self.assertEqual(result, Path('path', 'to', 'command')) assert result == Path('path', 'to', 'command')
class TestPath(TestCase): class TestPath(TestCase):
@ -257,7 +257,7 @@ class TestPath(TestCase):
result = path_to_str(None) result = path_to_str(None)
# THEN: `path_to_str` should return an empty string # THEN: `path_to_str` should return an empty string
self.assertEqual(result, '') assert not result
def test_path_to_str_path_object(self): def test_path_to_str_path_object(self):
""" """
@ -268,7 +268,7 @@ class TestPath(TestCase):
result = path_to_str(Path('test/path')) result = path_to_str(Path('test/path'))
# THEN: `path_to_str` should return a string representation of the Path object # THEN: `path_to_str` should return a string representation of the Path object
self.assertEqual(result, os.path.join('test', 'path')) assert result == os.path.join('test', 'path')
def test_str_to_path_type_error(self): def test_str_to_path_type_error(self):
""" """
@ -289,7 +289,7 @@ class TestPath(TestCase):
result = str_to_path('') result = str_to_path('')
# THEN: `path_to_str` should return None # THEN: `path_to_str` should return None
self.assertEqual(result, None) assert not result
def test_path_encode_json(self): def test_path_encode_json(self):
""" """
@ -301,7 +301,7 @@ class TestPath(TestCase):
path = Path.encode_json({'__Path__': ['path', 'to', 'fi.le']}, extra=1, args=2) path = Path.encode_json({'__Path__': ['path', 'to', 'fi.le']}, extra=1, args=2)
# THEN: A Path object should have been returned # THEN: A Path object should have been returned
self.assertEqual(path, Path('path', 'to', 'fi.le')) assert path == Path('path', 'to', 'fi.le')
def test_path_encode_json_base_path(self): def test_path_encode_json_base_path(self):
""" """
@ -313,7 +313,7 @@ class TestPath(TestCase):
path = Path.encode_json({'__Path__': ['path', 'to', 'fi.le']}, base_path=Path('/base')) path = Path.encode_json({'__Path__': ['path', 'to', 'fi.le']}, base_path=Path('/base'))
# THEN: A Path object should have been returned with an absolute path # THEN: A Path object should have been returned with an absolute path
self.assertEqual(path, Path('/', 'base', 'path', 'to', 'fi.le')) assert path == Path('/', 'base', 'path', 'to', 'fi.le')
def test_path_json_object(self): def test_path_json_object(self):
""" """
@ -326,7 +326,7 @@ class TestPath(TestCase):
obj = path.json_object(extra=1, args=2) obj = path.json_object(extra=1, args=2)
# THEN: A JSON decodable object should have been returned. # THEN: A JSON decodable object should have been returned.
self.assertEqual(obj, {'__Path__': ('/', 'base', 'path', 'to', 'fi.le')}) assert obj == {'__Path__': ('/', 'base', 'path', 'to', 'fi.le')}
def test_path_json_object_base_path(self): def test_path_json_object_base_path(self):
""" """
@ -340,7 +340,7 @@ class TestPath(TestCase):
obj = path.json_object(base_path=Path('/', 'base')) obj = path.json_object(base_path=Path('/', 'base'))
# THEN: A JSON decodable object should have been returned. # THEN: A JSON decodable object should have been returned.
self.assertEqual(obj, {'__Path__': ('path', 'to', 'fi.le')}) assert obj == {'__Path__': ('path', 'to', 'fi.le')}
def test_create_paths_dir_exists(self): def test_create_paths_dir_exists(self):
""" """

View File

@ -57,7 +57,7 @@ class testProjectorUtilities(TestCase):
valid = verify_ip_address(addr=ip4_loopback) valid = verify_ip_address(addr=ip4_loopback)
# THEN: Verify we received True # THEN: Verify we received True
self.assertTrue(valid, 'IPv4 loopback address should have been valid') assert valid, 'IPv4 loopback address should have been valid'
def test_ip4_local_valid(self): def test_ip4_local_valid(self):
""" """
@ -67,7 +67,7 @@ class testProjectorUtilities(TestCase):
valid = verify_ip_address(addr=ip4_local) valid = verify_ip_address(addr=ip4_local)
# THEN: Verify we received True # THEN: Verify we received True
self.assertTrue(valid, 'IPv4 local address should have been valid') assert valid, 'IPv4 local address should have been valid'
def test_ip4_broadcast_valid(self): def test_ip4_broadcast_valid(self):
""" """
@ -77,7 +77,7 @@ class testProjectorUtilities(TestCase):
valid = verify_ip_address(addr=ip4_broadcast) valid = verify_ip_address(addr=ip4_broadcast)
# THEN: Verify we received True # THEN: Verify we received True
self.assertTrue(valid, 'IPv4 broadcast address should have been valid') assert valid, 'IPv4 broadcast address should have been valid'
def test_ip4_address_invalid(self): def test_ip4_address_invalid(self):
""" """
@ -87,7 +87,7 @@ class testProjectorUtilities(TestCase):
valid = verify_ip_address(addr=ip4_bad) valid = verify_ip_address(addr=ip4_bad)
# THEN: Verify we received True # THEN: Verify we received True
self.assertFalse(valid, 'Bad IPv4 address should not have been valid') assert not valid, 'Bad IPv4 address should not have been valid'
def test_ip6_loopback_valid(self): def test_ip6_loopback_valid(self):
""" """
@ -97,7 +97,7 @@ class testProjectorUtilities(TestCase):
valid = verify_ip_address(addr=ip6_loopback) valid = verify_ip_address(addr=ip6_loopback)
# THEN: Validate return # THEN: Validate return
self.assertTrue(valid, 'IPv6 loopback address should have been valid') assert valid, 'IPv6 loopback address should have been valid'
def test_ip6_local_valid(self): def test_ip6_local_valid(self):
""" """
@ -107,7 +107,7 @@ class testProjectorUtilities(TestCase):
valid = verify_ip_address(addr=ip6_link_local) valid = verify_ip_address(addr=ip6_link_local)
# THEN: Validate return # THEN: Validate return
self.assertTrue(valid, 'IPv6 link-local address should have been valid') assert valid, 'IPv6 link-local address should have been valid'
def test_ip6_address_invalid(self): def test_ip6_address_invalid(self):
""" """
@ -117,7 +117,7 @@ class testProjectorUtilities(TestCase):
valid = verify_ip_address(addr=ip6_bad) valid = verify_ip_address(addr=ip6_bad)
# THEN: Validate bad return # THEN: Validate bad return
self.assertFalse(valid, 'IPv6 bad address should have been invalid') assert not valid, 'IPv6 bad address should have been invalid'
def test_md5_hash(self): def test_md5_hash(self):
""" """
@ -127,7 +127,7 @@ class testProjectorUtilities(TestCase):
hash_ = md5_hash(salt=salt.encode('utf-8'), data=pin.encode('utf-8')) hash_ = md5_hash(salt=salt.encode('utf-8'), data=pin.encode('utf-8'))
# THEN: Validate return has is same # THEN: Validate return has is same
self.assertEquals(hash_, test_hash, 'MD5 should have returned a good hash') assert hash_ == test_hash, 'MD5 should have returned a good hash'
def test_md5_hash_bad(self): def test_md5_hash_bad(self):
""" """
@ -137,7 +137,7 @@ class testProjectorUtilities(TestCase):
hash_ = md5_hash(salt=pin.encode('utf-8'), data=salt.encode('utf-8')) hash_ = md5_hash(salt=pin.encode('utf-8'), data=salt.encode('utf-8'))
# THEN: return data is different # THEN: return data is different
self.assertNotEquals(hash_, test_hash, 'MD5 should have returned a bad hash') assert hash_ is not test_hash, 'MD5 should have returned a bad hash'
def test_qmd5_hash(self): def test_qmd5_hash(self):
""" """
@ -147,7 +147,7 @@ class testProjectorUtilities(TestCase):
hash_ = qmd5_hash(salt=salt.encode('utf-8'), data=pin.encode('utf-8')) hash_ = qmd5_hash(salt=salt.encode('utf-8'), data=pin.encode('utf-8'))
# THEN: Validate return has is same # THEN: Validate return has is same
self.assertEquals(hash_, test_hash, 'Qt-MD5 should have returned a good hash') assert hash_ == test_hash, 'Qt-MD5 should have returned a good hash'
def test_qmd5_hash_bad(self): def test_qmd5_hash_bad(self):
""" """
@ -157,7 +157,7 @@ class testProjectorUtilities(TestCase):
hash_ = qmd5_hash(salt=pin.encode('utf-8'), data=salt.encode('utf-8')) hash_ = qmd5_hash(salt=pin.encode('utf-8'), data=salt.encode('utf-8'))
# THEN: return data is different # THEN: return data is different
self.assertNotEquals(hash_, test_hash, 'Qt-MD5 should have returned a bad hash') assert hash_ is not test_hash, 'Qt-MD5 should have returned a bad hash'
def test_md5_non_ascii_string(self): def test_md5_non_ascii_string(self):
""" """
@ -167,7 +167,7 @@ class testProjectorUtilities(TestCase):
hash_ = md5_hash(salt=test_non_ascii_string.encode('utf-8'), data=None) hash_ = md5_hash(salt=test_non_ascii_string.encode('utf-8'), data=None)
# THEN: Valid MD5 hash should be returned # THEN: Valid MD5 hash should be returned
self.assertEqual(hash_, test_non_ascii_hash, 'MD5 should have returned a valid hash') assert hash_ == test_non_ascii_hash, 'MD5 should have returned a valid hash'
def test_qmd5_non_ascii_string(self): def test_qmd5_non_ascii_string(self):
""" """
@ -177,4 +177,4 @@ class testProjectorUtilities(TestCase):
hash_ = md5_hash(data=test_non_ascii_string.encode('utf-8')) hash_ = md5_hash(data=test_non_ascii_string.encode('utf-8'))
# THEN: Valid MD5 hash should be returned # THEN: Valid MD5 hash should be returned
self.assertEqual(hash_, test_non_ascii_hash, 'Qt-MD5 should have returned a valid hash') assert hash_ == test_non_ascii_hash, 'Qt-MD5 should have returned a valid hash'

View File

@ -51,19 +51,19 @@ class TestRegistry(TestCase):
# THEN and I will get an exception # THEN and I will get an exception
with self.assertRaises(KeyError) as context: with self.assertRaises(KeyError) as context:
Registry().register('test1', mock_1) Registry().register('test1', mock_1)
self.assertEqual(context.exception.args[0], 'Duplicate service exception test1', assert context.exception.args[0] == 'Duplicate service exception test1', \
'KeyError exception should have been thrown for duplicate service') 'KeyError exception should have been thrown for duplicate service'
# WHEN I try to get back a non existent component # WHEN I try to get back a non existent component
# THEN I will get an exception # THEN I will get an exception
temp = Registry().get('test2') temp = Registry().get('test2')
self.assertEqual(temp, None, 'None should have been returned for missing service') assert not temp, 'None should have been returned for missing service'
# WHEN I try to replace a component I should be allowed # WHEN I try to replace a component I should be allowed
Registry().remove('test1') Registry().remove('test1')
# THEN I will get an exception # THEN I will get an exception
temp = Registry().get('test1') temp = Registry().get('test1')
self.assertEqual(temp, None, 'None should have been returned for deleted service') assert not temp, 'None should have been returned for deleted service'
def test_registry_function(self): def test_registry_function(self):
""" """
@ -77,21 +77,21 @@ class TestRegistry(TestCase):
return_value = Registry().execute('test1') return_value = Registry().execute('test1')
# THEN: I expect then function to have been called and a return given # THEN: I expect then function to have been called and a return given
self.assertEqual(return_value[0], 'function_1', 'A return value is provided and matches') assert return_value[0] == 'function_1', 'A return value is provided and matches'
# WHEN: I execute the a function with the same reference and execute the function # WHEN: I execute the a function with the same reference and execute the function
Registry().register_function('test1', self.dummy_function_1) Registry().register_function('test1', self.dummy_function_1)
return_value = Registry().execute('test1') return_value = Registry().execute('test1')
# THEN: I expect then function to have been called and a return given # THEN: I expect then function to have been called and a return given
self.assertEqual(return_value, ['function_1', 'function_1'], 'A return value list is provided and matches') assert return_value == ['function_1', 'function_1'], 'A return value list is provided and matches'
# WHEN: I execute the a 2nd function with the different reference and execute the function # WHEN: I execute the a 2nd function with the different reference and execute the function
Registry().register_function('test2', self.dummy_function_2) Registry().register_function('test2', self.dummy_function_2)
return_value = Registry().execute('test2') return_value = Registry().execute('test2')
# THEN: I expect then function to have been called and a return given # THEN: I expect then function to have been called and a return given
self.assertEqual(return_value[0], 'function_2', 'A return value is provided and matches') assert return_value[0] == 'function_2', 'A return value is provided and matches'
def test_registry_working_flags(self): def test_registry_working_flags(self):
""" """
@ -107,28 +107,28 @@ class TestRegistry(TestCase):
# THEN: we should be able retrieve the saved component # THEN: we should be able retrieve the saved component
temp = Registry().get_flag('test1') temp = Registry().get_flag('test1')
self.assertEquals(temp, my_data, 'The value should have been saved') assert temp == my_data, 'The value should have been saved'
# WHEN: I add a component for the second time I am not mad. # WHEN: I add a component for the second time I am not mad.
# THEN and I will not get an exception # THEN and I will not get an exception
Registry().set_flag('test1', my_data2) Registry().set_flag('test1', my_data2)
temp = Registry().get_flag('test1') temp = Registry().get_flag('test1')
self.assertEquals(temp, my_data2, 'The value should have been updated') assert temp == my_data2, 'The value should have been updated'
# WHEN I try to get back a non existent Working Flag # WHEN I try to get back a non existent Working Flag
# THEN I will get an exception # THEN I will get an exception
with self.assertRaises(KeyError) as context1: with self.assertRaises(KeyError) as context1:
temp = Registry().get_flag('test2') temp = Registry().get_flag('test2')
self.assertEqual(context1.exception.args[0], 'Working Flag test2 not found in list', assert context1.exception.args[0] == 'Working Flag test2 not found in list', \
'KeyError exception should have been thrown for missing working flag') 'KeyError exception should have been thrown for missing working flag'
# WHEN I try to replace a working flag I should be allowed # WHEN I try to replace a working flag I should be allowed
Registry().remove_flag('test1') Registry().remove_flag('test1')
# THEN I will get an exception # THEN I will get an exception
with self.assertRaises(KeyError) as context: with self.assertRaises(KeyError) as context:
temp = Registry().get_flag('test1') temp = Registry().get_flag('test1')
self.assertEqual(context.exception.args[0], 'Working Flag test1 not found in list', assert context.exception.args[0] == 'Working Flag test1 not found in list', \
'KeyError exception should have been thrown for duplicate working flag') 'KeyError exception should have been thrown for duplicate working flag'
def test_remove_function(self): def test_remove_function(self):
""" """
@ -174,7 +174,7 @@ class TestRegistryBase(TestCase):
PlainStub() PlainStub()
# THEN: Nothing is registered with the registry # THEN: Nothing is registered with the registry
self.assertEqual(len(Registry().functions_list), 0), 'The function should not be in the dict anymore.' assert len(Registry().functions_list) == 0, 'The function should not be in the dict anymore.'
def test_registry_mixin_present(self): def test_registry_mixin_present(self):
""" """
@ -187,4 +187,4 @@ class TestRegistryBase(TestCase):
RegistryStub() RegistryStub()
# THEN: The bootstrap methods should be registered # THEN: The bootstrap methods should be registered
self.assertEqual(len(Registry().functions_list), 2), 'The bootstrap functions should be in the dict.' assert len(Registry().functions_list) == 2, 'The bootstrap functions should be in the dict.'

View File

@ -139,13 +139,13 @@ class TestSettings(TestCase, TestMixin):
extend = settings.value('extend') extend = settings.value('extend')
# THEN the default value is returned # THEN the default value is returned
self.assertEqual('very wide', extend, 'The default value defined should be returned') assert 'very wide' == extend, 'The default value defined should be returned'
# WHEN a new value is saved into config # WHEN a new value is saved into config
Settings().setValue('test/extend', 'very short') Settings().setValue('test/extend', 'very short')
# THEN the new value is returned when re-read # THEN the new value is returned when re-read
self.assertEqual('very short', Settings().value('test/extend'), 'The saved value should be returned') assert 'very short' == Settings().value('test/extend'), 'The saved value should be returned'
def test_settings_nonexisting(self): def test_settings_nonexisting(self):
"""Test the Settings on query for non-existing value""" """Test the Settings on query for non-existing value"""
@ -155,7 +155,7 @@ class TestSettings(TestCase, TestMixin):
Settings().value('core/does not exists') Settings().value('core/does not exists')
# THEN: An exception with the non-existing key should be thrown # THEN: An exception with the non-existing key should be thrown
self.assertEqual(str(cm.exception), "'core/does not exists'", 'We should get an exception') assert str(cm.exception) == "'core/does not exists'", 'We should get an exception'
def test_extend_default_settings(self): def test_extend_default_settings(self):
"""Test that the extend_default_settings method extends the default settings""" """Test that the extend_default_settings method extends the default settings"""
@ -167,9 +167,8 @@ class TestSettings(TestCase, TestMixin):
Settings.extend_default_settings({'test/setting 3': 4, 'test/extended 1': 1, 'test/extended 2': 2}) Settings.extend_default_settings({'test/setting 3': 4, 'test/extended 1': 1, 'test/extended 2': 2})
# THEN: The _default_settings__ dictionary_ should have the new keys # THEN: The _default_settings__ dictionary_ should have the new keys
self.assertEqual( assert Settings.__default_settings__ == {'test/setting 1': 1, 'test/setting 2': 2, 'test/setting 3': 4,
Settings.__default_settings__, {'test/setting 1': 1, 'test/setting 2': 2, 'test/setting 3': 4, 'test/extended 1': 1, 'test/extended 2': 2}
'test/extended 1': 1, 'test/extended 2': 2})
@patch('openlp.core.common.settings.QtCore.QSettings.contains') @patch('openlp.core.common.settings.QtCore.QSettings.contains')
@patch('openlp.core.common.settings.QtCore.QSettings.value') @patch('openlp.core.common.settings.QtCore.QSettings.value')