Skip to content
Snippets Groups Projects
Commit daec7de4 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

warn in case of multiprop

parent 0c1f0d59
Branches
Tags
2 merge requests!178FIX: #96 Better error output for crawl.py script.,!167Sync Graph
...@@ -28,6 +28,7 @@ from typing import TYPE_CHECKING, Any, Optional, Union ...@@ -28,6 +28,7 @@ from typing import TYPE_CHECKING, Any, Optional, Union
import linkahead as db import linkahead as db
import yaml import yaml
from linkahead.common.models import Parent, _ParentList, _Properties from linkahead.common.models import Parent, _ParentList, _Properties
from warnings import warn
from .exceptions import ImpossibleMergeError from .exceptions import ImpossibleMergeError
...@@ -78,6 +79,7 @@ class SyncNode: ...@@ -78,6 +79,7 @@ class SyncNode:
self.description = entity.description self.description = entity.description
self.parents = _ParentList().extend(entity.parents) self.parents = _ParentList().extend(entity.parents)
self.properties = _Properties().extend(entity.properties) self.properties = _Properties().extend(entity.properties)
self._check_for_multiproperties()
# other members # other members
self.identifiable: Optional[Identifiable] = None self.identifiable: Optional[Identifiable] = None
self.registered_identifiable = registered_identifiable self.registered_identifiable = registered_identifiable
...@@ -216,6 +218,20 @@ class SyncNode: ...@@ -216,6 +218,20 @@ class SyncNode:
+ "=====================================================\n" + "=====================================================\n"
) )
def _check_for_multiproperties(self):
""" warns if multiproperties are present """
ids = set()
names = set()
for p in self.properties:
if p.name is not None:
if p.name in names:
warn("Multiproperties are not supported by the crawler.")
names.add(p.name)
if p.id is not None:
if p.id in ids:
warn("Multiproperties are not supported by the crawler.")
ids.add(p.id)
def parent_in_list(parent: Parent, plist: _ParentList) -> bool: def parent_in_list(parent: Parent, plist: _ParentList) -> bool:
"""helper function that checks whether a parent with the same name or ID is in the plist""" """helper function that checks whether a parent with the same name or ID is in the plist"""
......
...@@ -232,6 +232,12 @@ def test_export_node(): ...@@ -232,6 +232,12 @@ def test_export_node():
.add_property(name="a", value='b') .add_property(name="a", value='b')
.add_property(name="a", value='a')) .add_property(name="a", value='a'))
# there should be a warning when multiproperties are used
with pytest.warns(UserWarning) as caught:
SyncNode(rec_a)
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):
exp = SyncNode(rec_a).export_entity() exp = SyncNode(rec_a).export_entity()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment