From 8b606dd5f984fdb340e5b1cda19751775880e59d Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Thu, 30 Apr 2015 13:34:21 +0100 Subject: [PATCH] config: fixing an issue introduced by previous config fix... When the merging logic was updated to preserve duplicates within the same list, it inadvertently broke the logic that removed items marked for removal with a '~'. This commit rectifies that. Note to self: merging functions are doing *way* to much; they should be refactored into several individual function and config should be resolved in distinct stages. --- wlauto/tests/test_config.py | 7 +++++++ wlauto/utils/misc.py | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/wlauto/tests/test_config.py b/wlauto/tests/test_config.py index 0587ddb5..2c9f9ac3 100644 --- a/wlauto/tests/test_config.py +++ b/wlauto/tests/test_config.py @@ -167,6 +167,13 @@ class ConfigTest(TestCase): self.config.finalize() assert_equal(self.config.instrumentation['list_params']['param'], [0.1, 0.1, 0.1]) + def test_remove_instrument(self): + self.config.load_config({'instrumentation': ['list_params']}) + a = Agenda('{config: {instrumentation: [~list_params] }}') + self.config.set_agenda(a) + self.config.finalize() + assert_equal(self.config.instrumentation, {}) + def test_global_instrumentation(self): self.config.load_config({'instrumentation': ['global_instrument']}) ws = AgendaWorkloadEntry(id='a', iterations=1, name='linpack', instrumentation=['local_instrument']) diff --git a/wlauto/utils/misc.py b/wlauto/utils/misc.py index 1eed15d8..6718fa78 100644 --- a/wlauto/utils/misc.py +++ b/wlauto/utils/misc.py @@ -339,6 +339,8 @@ def _merge_two_lists(base, other, duplicates='all', dict_type=dict): # pylint: elif duplicates == 'first': base_norm = normalize(base, dict_type) merged_list = normalize(base, dict_type) + for v in base_norm: + _check_remove_item(merged_list, v) for v in normalize(other, dict_type): if not _check_remove_item(merged_list, v): if v not in base_norm: @@ -351,9 +353,12 @@ def _merge_two_lists(base, other, duplicates='all', dict_type=dict): # pylint: if not _check_remove_item(merged_list, v): if v not in other_norm: merged_list.append(v) - return merged_list + other_norm + for v in other_norm: + if not _check_remove_item(merged_list, v): + merged_list.append(v) + return merged_list else: - raise ValueError('Unexpected value for list duplcates argument: {}. '.format(duplicates) + + raise ValueError('Unexpected value for list duplicates argument: {}. '.format(duplicates) + 'Must be in {"all", "first", "last"}.')