From 7216fc27e5db3fc0eb45f2889578a1c3e371251d Mon Sep 17 00:00:00 2001 From: Alexander Schlemmer <a.schlemmer@indiscale.com> Date: Mon, 27 May 2024 09:28:25 +0200 Subject: [PATCH] TST: added a small test for the treatement of None values --- unittests/test_sync_graph.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/unittests/test_sync_graph.py b/unittests/test_sync_graph.py index ab0a46bc..8dbceadb 100644 --- a/unittests/test_sync_graph.py +++ b/unittests/test_sync_graph.py @@ -29,7 +29,7 @@ from caoscrawler.exceptions import (ImpossibleMergeError, MissingIdentifyingProperty) from caoscrawler.identifiable import Identifiable from caoscrawler.identifiable_adapters import CaosDBIdentifiableAdapter -from caoscrawler.sync_graph import SyncGraph +from caoscrawler.sync_graph import SyncGraph, _set_each_scalar_value from caoscrawler.sync_node import SyncNode, parent_in_list, property_in_list from itertools import product @@ -604,3 +604,15 @@ def test_detect_circular_dependency(crawler_mocked_identifiable_retrieve, caplog assert "Found circular dependency" in caplog.text assert "\n--------\n\n> Parent: C\n\n>> Name: a\n[\'C\']" in caplog.text caplog.clear() + + +def test_set_each_scalar_value(): + """Test whether properties with None as value are treated appropriately.""" + a = SyncNode(db.Record().add_parent("RT1").add_property(name="bla"), + db.RecordType().add_property("is_referenced_by", ["RT2"])) + _set_each_scalar_value(a, lambda x: False, None) + _set_each_scalar_value(a, lambda x: isinstance(x, SyncNode), None) + _set_each_scalar_value(a, lambda x: x is None, lambda x: 42) + assert a.properties[0].value == 42 + _set_each_scalar_value(a, lambda x: x == 42, lambda x: None) + assert a.properties[0].value is None -- GitLab