Skip to content

Commit

Permalink
Merge pull request #677 from Dessia-tech/fix/check_schema
Browse files Browse the repository at this point in the history
Fix: object_default/schema
  • Loading branch information
GhislainJ committed Mar 26, 2024
2 parents a821a60 + 7116679 commit f005633
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fix

- PhysicalObject : Remove to_stl encoding element
- Schema : Take `None` default value into account
- WorkflowRun : Compute memory usage, subtract before_memory


Expand Down
2 changes: 1 addition & 1 deletion dessia_common/schemas/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,7 @@ def object_default(default_value: CoreDessiaObject = UNDEFINED, class_schema: Cl
Return serialized user default if definition, else None.
"""
if default_value is not UNDEFINED:
if default_value is not UNDEFINED and default_value is not None:
return default_value.to_dict(use_pointers=False)
if class_schema is not None:
# TODO Should we implement this ? Right now, tests state that the result is None
Expand Down
18 changes: 17 additions & 1 deletion tests/test_schemas/test_computation_structures.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from dessia_common.schemas.core import ClassProperty, MethodTypeProperty, AttributeTypeProperty, SchemaAttribute
from dessia_common.core import DessiaObject
from dessia_common.schemas.core import ClassProperty, MethodTypeProperty, AttributeTypeProperty, SchemaAttribute, \
CustomClass
from dessia_common.forms import StandaloneObject
from dessia_common.typings import MethodType, ClassMethodType, AttributeType, ClassAttributeType
from typing import Type
Expand All @@ -8,6 +10,7 @@


CUSTOM_CLASS = SchemaAttribute(name="custom_class")
CUSTOM_CLASS_DEFAULT = SchemaAttribute(name="custom_class", editable=True, title="CustomClass", default_value=None)
ATTRIBUTE = SchemaAttribute(name="attribute")
METHOD = SchemaAttribute(name="method")

Expand Down Expand Up @@ -58,6 +61,19 @@ def test_attributes(self, schema, expected_type, expected_typing, expected_class
self.assertEqual(computed_schema["properties"]["class_"]["type"], "object")
self.assertEqual(computed_schema["properties"]["class_"]["python_typing"], expected_class)

@parameterized.expand([
(CustomClass(annotation=DessiaObject, attribute=CUSTOM_CLASS_DEFAULT),
"object", "dessia_common.core.DessiaObject"),
(CustomClass(annotation=DessiaObject, attribute=CUSTOM_CLASS),
"object", "dessia_common.core.DessiaObject")
])
def test_custom_classes(self, schema, expected_type, expected_python_typing):
computed_schema = schema.to_dict()
self.assertEqual(computed_schema["type"], expected_type)
self.assertEqual(computed_schema["python_typing"], expected_python_typing)
self.assertEqual(computed_schema["title"], schema.attribute.title)
self.assertEqual(computed_schema["editable"], schema.attribute.editable)


if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit f005633

Please sign in to comment.