Skip to content

Commit

Permalink
Fix for issue #111 (#112)
Browse files Browse the repository at this point in the history
Resolve inputs into DSDLDefinition constructor
  • Loading branch information
thirtytwobits authored Dec 11, 2024
1 parent 3ea74de commit 97fb20c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pydsdl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sys as _sys
from pathlib import Path as _Path

__version__ = "1.22.0"
__version__ = "1.22.1"
__version_info__ = tuple(map(int, __version__.split(".")[:3]))
__license__ = "MIT"
__author__ = "OpenCyphal"
Expand Down
2 changes: 1 addition & 1 deletion pydsdl/_data_schema_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def offset(self) -> _bit_length_set.BitLengthSet:
# only the total offset (i.e., total size) is defined.
self._bit_length_computed_at_least_once = True
ty = _serializable.UnionType if self.union else _serializable.StructureType
out = ty.aggregate_bit_length_sets([f.data_type for f in self.fields]) # type: ignore
out = ty.aggregate_bit_length_sets([f.data_type for f in self.fields])
assert isinstance(out, _bit_length_set.BitLengthSet) and len(out) > 0
return out

Expand Down
14 changes: 12 additions & 2 deletions pydsdl/_dsdl_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ def from_first_in(cls: Type["DSDLDefinition"], dsdl_path: Path, valid_dsdl_roots
def __init__(self, file_path: Path, root_namespace_path: Path):
""" """
# Normalizing the path and reading the definition text
self._file_path = Path(file_path)
self._file_path = Path(file_path).resolve()
del file_path

if not self._file_path.exists():
raise InvalidDefinitionError(
"Attempt to construct ReadableDSDLFile object for file that doesn't exist.", self._file_path
)

self._root_namespace_path = Path(root_namespace_path)
self._root_namespace_path = Path(root_namespace_path).resolve()
del root_namespace_path
self._text: str | None = None

Expand Down Expand Up @@ -385,6 +385,16 @@ def _unittest_dsdl_definition_read_text(temp_dsdl_factory) -> None: # type: ign
assert "@sealed" == target_definition.text


def _unittest_dsdl_definition_issue_111(temp_dsdl_factory) -> None: # type: ignore
target_root = Path("root", "ns")
target_file_path = Path(target_root / "Target.1.1.dsdl")
dsdl_file = temp_dsdl_factory.new_file(target_root / target_file_path, "@sealed")
actual_root = Path(str(dsdl_file.parent) + "/..")

target_definition = DSDLDefinition(actual_root / dsdl_file.parent / dsdl_file.name, actual_root)
assert "@sealed" == target_definition.text


def _unittest_type_from_path_inference() -> None:
from pytest import raises as expect_raises

Expand Down

0 comments on commit 97fb20c

Please sign in to comment.