From 20f329d433276af5ab333291b051781b1e6b9cdc Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Thu, 6 May 2021 07:06:42 +0200 Subject: [PATCH] remove_choice only avalable for choice --- src/rougail/objspace.py | 6 +++++- tests/dictionaries/88remove_choice_not_choice/00-base.xml | 7 +++++++ tests/dictionaries/88remove_choice_not_choice/01-base.xml | 8 ++++++++ tests/dictionaries/88remove_choice_not_choice/__init__.py | 0 tests/dictionaries/88remove_choice_not_choice/errno_33 | 0 5 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/dictionaries/88remove_choice_not_choice/00-base.xml create mode 100644 tests/dictionaries/88remove_choice_not_choice/01-base.xml create mode 100644 tests/dictionaries/88remove_choice_not_choice/__init__.py create mode 100644 tests/dictionaries/88remove_choice_not_choice/errno_33 diff --git a/src/rougail/objspace.py b/src/rougail/objspace.py index dcf8c0e1..3be26728 100644 --- a/src/rougail/objspace.py +++ b/src/rougail/objspace.py @@ -393,7 +393,7 @@ class RougailObjSpace: for attr, val in child.attrib.items(): if redefine and attr in UNREDEFINABLE: msg = _(f'cannot redefine attribute "{attr}" for variable "{child.attrib["name"]}"' - f' in "{xmlfile}", already defined') + f' already defined') raise DictConsistencyError(msg, 48, variableobj.xmlfiles[:-1]) if attr in self.booleans_attributs: val = convert_boolean(val) @@ -411,6 +411,10 @@ class RougailObjSpace: """ if child.tag == 'variable': if child.attrib.get('remove_choice', False): + if variableobj.type != 'choice': + msg = _(f'cannot remove choices for variable "{variableobj.path}"' + f' the variable has type "{variableobj.type}"') + raise DictConsistencyError(msg, 33, variableobj.xmlfiles) variableobj.choice = [] if child.attrib.get('remove_check', False): self.remove_check(variableobj.name) diff --git a/tests/dictionaries/88remove_choice_not_choice/00-base.xml b/tests/dictionaries/88remove_choice_not_choice/00-base.xml new file mode 100644 index 00000000..57cc7646 --- /dev/null +++ b/tests/dictionaries/88remove_choice_not_choice/00-base.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/tests/dictionaries/88remove_choice_not_choice/01-base.xml b/tests/dictionaries/88remove_choice_not_choice/01-base.xml new file mode 100644 index 00000000..f7fb6e5c --- /dev/null +++ b/tests/dictionaries/88remove_choice_not_choice/01-base.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/tests/dictionaries/88remove_choice_not_choice/__init__.py b/tests/dictionaries/88remove_choice_not_choice/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/88remove_choice_not_choice/errno_33 b/tests/dictionaries/88remove_choice_not_choice/errno_33 new file mode 100644 index 00000000..e69de29b