Skip to content

Commit

Permalink
Merge pull request #18 from DSD-DBS/optional-scopes
Browse files Browse the repository at this point in the history
feat: make scope optional in onthology_schema
  • Loading branch information
nalquas authored Jan 27, 2025
2 parents 7a5e44f + 101319e commit 97d4138
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def fromdict(cls, attribute_dict: dict) -> _BooleanAttribute:

return _BooleanAttribute(
optional=attribute_dict.get("optional", False),
scope=_Scope(attribute_dict["scope"]),
scope=_Scope(attribute_dict.get("scope", "annotation")),
sensor_types=attribute_dict.get("sensor_types", ["camera", "lidar", "radar"]),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def fromdict(cls, attribute_dict: dict) -> _IntegerAttribute:

return _IntegerAttribute(
optional=attribute_dict.get("optional", False),
scope=_Scope(attribute_dict["scope"]),
scope=_Scope(attribute_dict.get("scope", "annotation")),
sensor_types=attribute_dict.get("sensor_types", ["camera", "lidar", "radar"]),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def fromdict(cls, attribute_dict: dict) -> _MultiReferenceAttribute:

return _MultiReferenceAttribute(
optional=attribute_dict.get("optional", False),
scope=_Scope(attribute_dict["scope"]),
scope=_Scope(attribute_dict.get("scope", "annotation")),
sensor_types=attribute_dict.get("sensor_types", ["camera", "lidar", "radar"]),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def fromdict(cls, attribute_dict: dict) -> _MultiSelectAttribute:

return _MultiSelectAttribute(
optional=attribute_dict.get("optional", False),
scope=_Scope(attribute_dict["scope"]),
scope=_Scope(attribute_dict.get("scope", "annotation")),
sensor_types=attribute_dict.get("sensor_types", ["camera", "lidar", "radar"]),
options=set(attribute_dict["attribute_type"]["options"]),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def fromdict(cls, attribute_dict: dict) -> _SingleSelectAttribute:

return _SingleSelectAttribute(
optional=attribute_dict.get("optional", False),
scope=_Scope(attribute_dict["scope"]),
scope=_Scope(attribute_dict.get("scope", "annotation")),
sensor_types=attribute_dict.get("sensor_types", ["camera", "lidar", "radar"]),
options=set(attribute_dict["attribute_type"]["options"]),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def fromdict(cls, attribute_dict: dict) -> _StringAttribute:

return _StringAttribute(
optional=attribute_dict.get("optional", False),
scope=_Scope(attribute_dict["scope"]),
scope=_Scope(attribute_dict.get("scope", "annotation")),
sensor_types=attribute_dict.get("sensor_types", ["camera", "lidar", "radar"]),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def fromdict(cls, attribute_dict: dict) -> _VectorAttribute:

return _VectorAttribute(
optional=attribute_dict.get("optional", False),
scope=_Scope(attribute_dict["scope"]),
scope=_Scope(attribute_dict.get("scope", "annotation")),
sensor_types=attribute_dict.get("sensor_types", ["camera", "lidar", "radar"]),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

"$schema": http://json-schema.org/draft-07/schema#
version: 2.0.0
version: 2.1.0

definitions:

Expand All @@ -19,7 +19,7 @@ definitions:
items:
enum: [camera, lidar, radar]
type: array
required: [attribute_type, scope]
required: [attribute_type]
type: object

attribute_type:
Expand Down
5 changes: 5 additions & 0 deletions tests/validation/validate_onthology/test_boolean_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def test_fromdict__scope_invalid(example_boolean_attribute_dict):
_BooleanAttribute.fromdict(example_boolean_attribute_dict)


def test_fromdict__scope_empty(example_boolean_attribute_dict):
del example_boolean_attribute_dict["scope"]
assert _BooleanAttribute.fromdict(example_boolean_attribute_dict).scope == _Scope.ANNOTATION


def test_fromdict__scope_annotation(example_boolean_attribute_dict):
example_boolean_attribute_dict["scope"] = "annotation"
assert _BooleanAttribute.fromdict(example_boolean_attribute_dict).scope == _Scope.ANNOTATION
Expand Down
5 changes: 5 additions & 0 deletions tests/validation/validate_onthology/test_integer_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def test_fromdict__scope_invalid(example_integer_attribute_dict):
_IntegerAttribute.fromdict(example_integer_attribute_dict)


def test_fromdict__scope_empty(example_integer_attribute_dict):
del example_integer_attribute_dict["scope"]
assert _IntegerAttribute.fromdict(example_integer_attribute_dict).scope == _Scope.ANNOTATION


def test_fromdict__scope_annotation(example_integer_attribute_dict):
example_integer_attribute_dict["scope"] = "annotation"
assert _IntegerAttribute.fromdict(example_integer_attribute_dict).scope == _Scope.ANNOTATION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def test_fromdict__scope_invalid(example_multi_reference_attribute_dict):
_MultiReferenceAttribute.fromdict(example_multi_reference_attribute_dict)


def test_fromdict__scope_empty(example_multi_reference_attribute_dict):
del example_multi_reference_attribute_dict["scope"]
assert (
_MultiReferenceAttribute.fromdict(example_multi_reference_attribute_dict).scope
== _Scope.ANNOTATION
)


def test_fromdict__scope_annotation(example_multi_reference_attribute_dict):
example_multi_reference_attribute_dict["scope"] = "annotation"
assert (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ def test_fromdict__scope_invalid(example_multi_select_attribute_dict):
_MultiSelectAttribute.fromdict(example_multi_select_attribute_dict)


def test_fromdict__scope_empty(example_multi_select_attribute_dict):
del example_multi_select_attribute_dict["scope"]
assert (
_MultiSelectAttribute.fromdict(example_multi_select_attribute_dict).scope
== _Scope.ANNOTATION
)


def test_fromdict__scope_annotation(example_multi_select_attribute_dict):
example_multi_select_attribute_dict["scope"] = "annotation"
assert (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ def test_fromdict__scope_invalid(example_single_select_attribute_dict):
_SingleSelectAttribute.fromdict(example_single_select_attribute_dict)


def test_fromdict__scope_empty(example_single_select_attribute_dict):
del example_single_select_attribute_dict["scope"]
assert (
_SingleSelectAttribute.fromdict(example_single_select_attribute_dict).scope
== _Scope.ANNOTATION
)


def test_fromdict__scope_annotation(example_single_select_attribute_dict):
example_single_select_attribute_dict["scope"] = "annotation"
assert (
Expand Down
5 changes: 5 additions & 0 deletions tests/validation/validate_onthology/test_string_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def test_fromdict__scope_invalid(example_string_attribute_dict):
_StringAttribute.fromdict(example_string_attribute_dict)


def test_fromdict__scope_empty(example_string_attribute_dict):
del example_string_attribute_dict["scope"]
assert _StringAttribute.fromdict(example_string_attribute_dict).scope == _Scope.ANNOTATION


def test_fromdict__scope_annotation(example_string_attribute_dict):
example_string_attribute_dict["scope"] = "annotation"
assert _StringAttribute.fromdict(example_string_attribute_dict).scope == _Scope.ANNOTATION
Expand Down
5 changes: 5 additions & 0 deletions tests/validation/validate_onthology/test_vector_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def test_fromdict__scope_invalid(example_vector_attribute_dict):
_VectorAttribute.fromdict(example_vector_attribute_dict)


def test_fromdict__scope_empty(example_vector_attribute_dict):
del example_vector_attribute_dict["scope"]
assert _VectorAttribute.fromdict(example_vector_attribute_dict).scope == _Scope.ANNOTATION


def test_fromdict__scope_annotation(example_vector_attribute_dict):
example_vector_attribute_dict["scope"] = "annotation"
assert _VectorAttribute.fromdict(example_vector_attribute_dict).scope == _Scope.ANNOTATION
Expand Down

0 comments on commit 97d4138

Please sign in to comment.