Fix set_value and adjust tests

This commit is contained in:
Tim Bentley 2016-05-24 17:28:11 +01:00
parent c13b922148
commit 32ef88f807
2 changed files with 9 additions and 13 deletions

View File

@ -166,12 +166,7 @@ class Registry(object):
:param key: The working_flag to be created this is usually a major class like "renderer" or "main_window" .
:param reference: The data to be saved.
"""
if key in self.working_flags:
trace_error_handler(log)
log.error('Duplicate Working Flag exception {key}'.format(key=key))
raise KeyError('Duplicate Working Flag exception {key}'.format(key=key))
else:
self.working_flags[key] = reference
self.working_flags[key] = reference
def remove_flag(self, key):
"""

View File

@ -102,17 +102,18 @@ class TestRegistry(TestCase):
# WHEN: I add a working flag it should save it
my_data = 'Lamas'
my_data2 = 'More Lamas'
Registry().set_flag('test1', my_data)
# THEN: we should be able retrieve the saved component
assert Registry().get_flag('test1') == my_data, 'The working flag can be retrieved and matches'
temp = Registry().get_flag('test1')
self.assertEquals(temp, my_data, 'The value should have been saved')
# WHEN: I add a component for the second time I am mad.
# THEN and I will get an exception
with self.assertRaises(KeyError) as context:
Registry().set_flag('test1', my_data)
self.assertEqual(context.exception.args[0], 'Duplicate Working Flag exception test1',
'KeyError exception should have been thrown for duplicate working flag')
# WHEN: I add a component for the second time I am not mad.
# THEN and I will not get an exception
Registry().set_flag('test1', my_data2)
temp = Registry().get_flag('test1')
self.assertEquals(temp, my_data2, 'The value should have been updated')
# WHEN I try to get back a non existent Working Flag
# THEN I will get an exception