From 96d752f6b0bfce9c71856aee7faf63e0a994917d Mon Sep 17 00:00:00 2001 From: Scott Dixon Date: Wed, 10 Jul 2024 19:26:45 -0700 Subject: [PATCH] Improving error handling Promoting case-sensitivity issue from assertion error to DataTypeNameCollisionError --- pydsdl/_data_type_builder.py | 15 ++++++++++++--- pydsdl/_namespace.py | 11 +++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/pydsdl/_data_type_builder.py b/pydsdl/_data_type_builder.py index d7812fb..23a5ba1 100644 --- a/pydsdl/_data_type_builder.py +++ b/pydsdl/_data_type_builder.py @@ -245,14 +245,23 @@ def resolve_versioned_data_type(self, name: str, version: _serializable.Version) path=found[1].file_path, ) raise DataTypeCollisionError("Conflicting definitions: %r" % found) + elif found[0].full_name != full_name and found[0].full_name.lower() == full_name.lower(): + # pragma: no cover + # This only happens if the file system is case-sensitive. + raise DataTypeNameCollisionError( + "Full name of required definition %s differs from %s only by letter case, " + "which is not permitted" % (full_name, found[0].full_name), + path=found[0].file_path + ) target_definition = found[0] - for visitor in self._definition_visitors: - visitor.on_definition(self._definition, target_definition) assert isinstance(target_definition, ReadableDSDLFile) - assert target_definition.full_name == full_name assert target_definition.version == version + + for visitor in self._definition_visitors: + visitor.on_definition(self._definition, target_definition) + # Recursion is cool. dt = target_definition.read( lookup_definitions=self._lookup_definitions, diff --git a/pydsdl/_namespace.py b/pydsdl/_namespace.py index 8f3eeba..725f8d5 100644 --- a/pydsdl/_namespace.py +++ b/pydsdl/_namespace.py @@ -819,6 +819,8 @@ def _unittest_ensure_no_namespace_name_collisions_or_nested_root_namespaces() -> def _unittest_issue_104(temp_dsdl_factory) -> None: # type: ignore """demonstrate that removing _ensure_no_collisions is okay""" + from pytest import raises + thing_1_0 = Path("a/b/thing.1.0.dsdl") thing_type_1_0 = Path("a/b/thing/thingtype.1.0.dsdl") @@ -830,3 +832,12 @@ def _unittest_issue_104(temp_dsdl_factory) -> None: # type: ignore assert len(direct) == 1 assert len(transitive) == 1 + + thing_1_1 = Path("a/b/thing.1.1.dsdl") + + thing_file2 = temp_dsdl_factory.new_file(thing_1_1, "@sealed\na.b.thing.Thingtype.1.0 thing\n") + + from ._data_type_builder import DataTypeNameCollisionError + + with raises(DataTypeNameCollisionError): + read_files(thing_file2, file_at_root.parent, file_at_root.parent)