forked from openlp/openlp
Fix set_value and adjust tests
This commit is contained in:
parent
c13b922148
commit
32ef88f807
|
@ -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 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.
|
:param reference: The data to be saved.
|
||||||
"""
|
"""
|
||||||
if key in self.working_flags:
|
self.working_flags[key] = reference
|
||||||
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
|
|
||||||
|
|
||||||
def remove_flag(self, key):
|
def remove_flag(self, key):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -102,17 +102,18 @@ class TestRegistry(TestCase):
|
||||||
|
|
||||||
# WHEN: I add a working flag it should save it
|
# WHEN: I add a working flag it should save it
|
||||||
my_data = 'Lamas'
|
my_data = 'Lamas'
|
||||||
|
my_data2 = 'More Lamas'
|
||||||
Registry().set_flag('test1', my_data)
|
Registry().set_flag('test1', my_data)
|
||||||
|
|
||||||
# THEN: we should be able retrieve the saved component
|
# 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.
|
# WHEN: I add a component for the second time I am not mad.
|
||||||
# THEN and I will get an exception
|
# THEN and I will not get an exception
|
||||||
with self.assertRaises(KeyError) as context:
|
Registry().set_flag('test1', my_data2)
|
||||||
Registry().set_flag('test1', my_data)
|
temp = Registry().get_flag('test1')
|
||||||
self.assertEqual(context.exception.args[0], 'Duplicate Working Flag exception test1',
|
self.assertEquals(temp, my_data2, 'The value should have been updated')
|
||||||
'KeyError exception should have been thrown for duplicate working flag')
|
|
||||||
|
|
||||||
# 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
|
||||||
|
|
Loading…
Reference in New Issue