Skip to content

Commit

Permalink
Improving error handling
Browse files Browse the repository at this point in the history
Promoting case-sensitivity issue from assertion error to DataTypeNameCollisionError
  • Loading branch information
thirtytwobits committed Jul 11, 2024
1 parent 1299df4 commit 96d752f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pydsdl/_data_type_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions pydsdl/_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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)

0 comments on commit 96d752f

Please sign in to comment.