diff --git a/src/caoscrawler/crawl.py b/src/caoscrawler/crawl.py index e2110a691ea7c0d73bd1946ceb2be20dce8db7c7..a449a779ed7979719bbe0ac780adecf0e4fec8f6 100644 --- a/src/caoscrawler/crawl.py +++ b/src/caoscrawler/crawl.py @@ -64,6 +64,7 @@ from linkahead.utils.escape import escape_squoted_text from .config import get_config_setting from .converters import Converter, ConverterValidationError from .debug_tree import DebugTree +from .exceptions import ImpossibleMergeError from .identifiable_adapters import (CaosDBIdentifiableAdapter, IdentifiableAdapter) from .logging import configure_server_side_logging diff --git a/unittests/test_crawler.py b/unittests/test_crawler.py index 0a6aee44a1892f1c950a80b936adf184616fd612..aaddec9e8c6b17ad726808bc36b0784adbc3c36d 100644 --- a/unittests/test_crawler.py +++ b/unittests/test_crawler.py @@ -487,9 +487,17 @@ a: ([b1, b2]) # The Bs cannot be merged due to different references to Cs with raises(ImpossibleMergeError) as rte: crawler._split_into_inserts_and_updates(st) + + # The order of the Cs is random so we only know that they are the + # last two elements but not in which order they have been tried to + # be merged. + assert "The problematic property is 'C' with values " in str(rte.value) + assert f"'[{st.nodes[-2]}]'" in str(rte.value) + assert f"'[{st.nodes[-1]}]'" in str(rte.value) + # TODO # assert not isinstance(rte.value, NotImplementedError), \ - # "Exception must not be NotImplementedError, but plain RuntimeError." + # "Exception must not be NotImplementedError, but plain RuntimeError." # assert "Could not find referencing entities" in rte.value.args[0] # assert "merge conflicts in the referencing" in rte.value.args[0] diff --git a/unittests/test_sync_graph.py b/unittests/test_sync_graph.py index 9015e74be69c60c43ece80a2f742d6e9b7badda6..84451790ddd02f90c2a12a3ce7280b17d8f7c73b 100644 --- a/unittests/test_sync_graph.py +++ b/unittests/test_sync_graph.py @@ -30,8 +30,7 @@ from test_crawler import (basic_retrieve_by_name_mock_up, mock_get_entity_by, ) -from caoscrawler.exceptions import (ImpossibleMergeError, - MissingIdentifyingProperty, +from caoscrawler.exceptions import (MissingIdentifyingProperty, MissingRecordType, ) from caoscrawler.identifiable import Identifiable diff --git a/unittests/test_sync_node.py b/unittests/test_sync_node.py index 668a53470d028dfcfce7bb5785d68b685b034595..bd9e1a6ccbc2ac9ec9ccace96e0ec0422ba1d95b 100644 --- a/unittests/test_sync_node.py +++ b/unittests/test_sync_node.py @@ -238,8 +238,9 @@ def test_export_node(): messages = {str(w.message) for w in caught} assert ("Multiproperties are not supported by the crawler.") in messages - with pytest.raises(ImpossibleMergeError): + with pytest.raises(ImpossibleMergeError) as ime: exp = SyncNode(rec_a).export_entity() + assert "The problematic property is 'a' with values '['b']' and '['a']'" in str(ime.value) # SyncNodes with same ID are considered equal rec_a = (db.Record(id=101) @@ -269,18 +270,26 @@ def test_export_node(): .add_property(name="a", value=SyncNode(db.Record())) .add_property(name="a", value=SyncNode(db.Record()))) - with pytest.raises(ImpossibleMergeError): + with pytest.raises(ImpossibleMergeError) as ime: exp = SyncNode(rec_a).export_entity() + msg = (f"The problematic property is 'a' with values '[{SyncNode(db.Record())}]' " + f"and '[{SyncNode(db.Record())}]'") + assert msg in str(ime.value) + # different SyncNode Objects with differing ID are not equal rec_a = (db.Record(id=101) .add_parent("B") .add_property(name="a", value=SyncNode(db.Record(id=1))) .add_property(name="a", value=SyncNode(db.Record(id=2)))) - with pytest.raises(ImpossibleMergeError): + with pytest.raises(ImpossibleMergeError) as ime: exp = SyncNode(rec_a).export_entity() + msg = (f"The problematic property is 'a' with values '[{SyncNode(db.Record(id=1))}]' " + f"and '[{SyncNode(db.Record(id=2))}]'") + assert msg in str(ime.value) + # SyncNodes with same ID are considered equal (list) rec_a = (db.Record(id=101) .add_parent("B") @@ -297,9 +306,14 @@ def test_export_node(): .add_property(name="a", value=[SyncNode(db.Record(id=1)), SyncNode(db.Record(id=2))]) .add_property(name="a", value=[SyncNode(db.Record(id=2)), SyncNode(db.Record(id=1))])) - with pytest.raises(ImpossibleMergeError): + with pytest.raises(ImpossibleMergeError) as ime: exp = SyncNode(rec_a).export_entity() + msg = ("The problematic property is 'a' with values " + f"'{[SyncNode(db.Record(id=1)), SyncNode(db.Record(id=2))]}' " + f"and '{[SyncNode(db.Record(id=2)), SyncNode(db.Record(id=1))]}'") + assert msg in str(ime.value) + # same SyncNode object is obviously equal (list) sn = SyncNode(db.Record(id=1)) rec_a = (db.Record(id=101) @@ -316,26 +330,37 @@ def test_export_node(): .add_property(name="a", value=[SyncNode(db.Record())]) .add_property(name="a", value=[SyncNode(db.Record())])) - with pytest.raises(ImpossibleMergeError): + with pytest.raises(ImpossibleMergeError) as ime: exp = SyncNode(rec_a).export_entity() + msg = ("The problematic property is 'a' with values " + f"'{[SyncNode(db.Record())]}' and '{[SyncNode(db.Record())]}'") + assert msg in str(ime.value) + # different SyncNode Objects with differing are not equal (list) rec_a = (db.Record(id=101) .add_parent("B") .add_property(name="a", value=[SyncNode(db.Record(id=1))]) .add_property(name="a", value=[SyncNode(db.Record(id=2))])) - with pytest.raises(ImpossibleMergeError): + with pytest.raises(ImpossibleMergeError) as ime: exp = SyncNode(rec_a).export_entity() + msg = ("The problematic property is 'a' with values " + f"'{[SyncNode(db.Record(id=1))]}' and '{[SyncNode(db.Record(id=2))]}'") + assert msg in str(ime.value) + # list vs no list rec_a = (db.Record(id=101) .add_parent("B") .add_property(name="a", value=SyncNode(db.Record(id=1))) .add_property(name="a", value=[SyncNode(db.Record(id=1))])) - with pytest.raises(ImpossibleMergeError): + with pytest.raises(ImpossibleMergeError) as ime: exp = SyncNode(rec_a).export_entity() + msg = ("The problematic property is 'a' with values " + f"'[{SyncNode(db.Record(id=1))}]' and '{[SyncNode(db.Record(id=1))]}'") + assert msg in str(ime.value) # different list sizes rec_a = (db.Record(id=101) @@ -343,5 +368,10 @@ def test_export_node(): .add_property(name="a", value=[SyncNode(db.Record(id=1))]) .add_property(name="a", value=[SyncNode(db.Record(id=1)), SyncNode(db.Record(id=1))])) - with pytest.raises(ImpossibleMergeError): + with pytest.raises(ImpossibleMergeError) as ime: exp = SyncNode(rec_a).export_entity() + + msg = ("The problematic property is 'a' with values " + f"'{[SyncNode(db.Record(id=1))]}' and " + f"'{[SyncNode(db.Record(id=1)), SyncNode(db.Record(id=1))]}'") + assert msg in str(ime.value)