Skip to content

Commit

Permalink
Merge pull request #37 from pyiron/add_restriction
Browse files Browse the repository at this point in the history
Add restriction
  • Loading branch information
samwaseda authored Jan 16, 2025
2 parents 2c30d00 + 25af7e1 commit d21c168
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
2 changes: 2 additions & 0 deletions semantikon/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ def _meta_to_dict(value):
return {
"units": None,
"label": None,
"triple": None,
"uri": None,
"shape": None,
"restriction": None,
"dtype": value,
}
else:
Expand Down
2 changes: 2 additions & 0 deletions semantikon/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def u(
triple: tuple[tuple[str, str, str], ...] | tuple[str, str, str] | None = None,
uri: str | None = None,
shape: tuple[int] | None = None,
restriction: tuple[tuple[str, str]] | None = None,
use_list: bool = True,
**kwargs,
):
Expand All @@ -34,6 +35,7 @@ def u(
"triple": triple,
"uri": uri,
"shape": shape,
"restriction": restriction,
}
for key, value in parent_result.items():
if result[key] is None:
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def test_parse_metadata(self):
"triple": None,
"shape": None,
"uri": None,
"restriction": None,
},
)

Expand Down
30 changes: 27 additions & 3 deletions tests/unit/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,28 @@ def get_speed(
input_args = parse_input_args(get_speed)
for key in ["distance", "time"]:
self.assertTrue(key in input_args)
for key in ["units", "uri", "shape", "label", "dtype"]:
for key in [
"units",
"uri",
"triple",
"shape",
"label",
"restriction",
"dtype"
]:
self.assertTrue(key in input_args["distance"])
self.assertEqual(input_args["distance"]["units"], "meter")
self.assertEqual(input_args["time"]["units"], "second")
output_args = parse_output_args(get_speed)
for key in ["units", "uri", "shape", "label", "dtype"]:
for key in [
"units",
"uri",
"triple",
"shape",
"label",
"restriction",
"dtype"
]:
self.assertTrue(key in output_args)
self.assertEqual(output_args["units"], "meter/second")
self.assertEqual(output_args["label"], "speed")
Expand All @@ -41,7 +57,15 @@ def get_speed(
output_args = parse_output_args(get_speed)
self.assertIsInstance(output_args, tuple)
for output_arg in output_args:
for key in ["units", "uri", "shape", "label", "dtype"]:
for key in [
"units",
"uri",
"triple",
"shape",
"label",
"restriction",
"dtype"
]:
self.assertTrue(key in output_arg)
self.assertEqual(output_args[0]["units"], "meter/second")
self.assertEqual(output_args[0]["label"], "speed")
Expand Down

0 comments on commit d21c168

Please sign in to comment.