diff --git a/src/e3/anod/qualifiers_manager.py b/src/e3/anod/qualifiers_manager.py index 8adce242..4ccc2851 100644 --- a/src/e3/anod/qualifiers_manager.py +++ b/src/e3/anod/qualifiers_manager.py @@ -157,30 +157,35 @@ def value(self, value: str | bool) -> str | bool: def repr(self, value: str | bool, hash_pool: list[str] | None) -> str: """See QualifierDeclaration.repr.""" list_repr = [] - if not self.repr_omit_key: - list_repr.append(self.repr_name) - if value: - list_repr.append(str(value)) - str_repr = "-".join(list_repr) + if not value: + # An empty value for tag value should lead to an empty representation + str_repr = "" + elif ( + value == self.default + and self.choices is not None + and "" not in self.choices + ): + # In the case the value of qualifier is a finite set and + # that "" is not in that set, if value is the default value then + # just return an empty representation. + str_repr = "" + else: + # Otherwise compute components of the representation. + if not self.repr_omit_key: + list_repr.append(self.repr_name) + if value: + list_repr.append(str(value)) + + # And join them with a dash. + str_repr = "-".join(list_repr) if hash_pool is not None and self.repr_in_hash: if str_repr: hash_pool.append(str_repr) return "" else: - if ( - value != "" - and value == self.default - and self.choices is not None - and "" not in self.choices - ): - # In the case the value of qualifier is a finite set and - # that "" is not in that set, if value is the default value then - # just return an empty representation. - return "" - else: - return str_repr + return str_repr class TagDeclaration(QualifierDeclaration): diff --git a/tests/tests_e3/anod/test_qualifier_manager.py b/tests/tests_e3/anod/test_qualifier_manager.py index 62f9fdff..7556f4d6 100644 --- a/tests/tests_e3/anod/test_qualifier_manager.py +++ b/tests/tests_e3/anod/test_qualifier_manager.py @@ -45,7 +45,7 @@ def declare_qualifiers_and_components(self, qualifiers_manager): assert simple_debug.get_qualifier("debug") simple_empty = Simple(qualifier="optional_qual", kind="build") - assert simple_empty.build_space_name == "simple_optional_qual" + assert simple_empty.build_space_name == "simple" # Disable the name generator class Base(Anod): @@ -304,6 +304,7 @@ def declare_qualifiers_and_components(self, qualifiers_manager): name="path", description="The first path.", repr_in_hash=True, + default="", ) # Add the "path_bis" qualifier @@ -311,6 +312,7 @@ def declare_qualifiers_and_components(self, qualifiers_manager): name="path_bis", description="A second path.", repr_in_hash=True, + default="", ) anod_no_component_1 = AnodNoComponent( @@ -331,6 +333,10 @@ def declare_qualifiers_and_components(self, qualifiers_manager): assert anod_no_component_3.build_space_name == "my_spec_debug_1.2_a2aaba2e" assert anod_no_component_3.component is None + anod_no_component_4 = AnodNoComponent(qualifier="debug,version=1.2", kind="build") + assert anod_no_component_4.build_space_name == "my_spec_debug_1.2" + assert anod_no_component_4.component is None + class AnodComponent(Anod): enable_name_generator = True base_name = "my_spec"