diff --git a/CHANGELOG.md b/CHANGELOG.md index 8766c3af6..be0bad0a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/dessia_common/schemas/core.py b/dessia_common/schemas/core.py index 2e2cd7fe7..b77657743 100644 --- a/dessia_common/schemas/core.py +++ b/dessia_common/schemas/core.py @@ -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 diff --git a/tests/test_schemas/test_computation_structures.py b/tests/test_schemas/test_computation_structures.py index 2c4a5d0f9..82f1bf6f7 100644 --- a/tests/test_schemas/test_computation_structures.py +++ b/tests/test_schemas/test_computation_structures.py @@ -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 @@ -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") @@ -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)