Skip to content

Commit

Permalink
Amended the code to also look for "property" in extension slot defini…
Browse files Browse the repository at this point in the history
…tions

Updated test case to show this works.
  • Loading branch information
matentzn committed Dec 7, 2024
1 parent 9847b67 commit 57d24f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/sssom/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ def _get_seperator_symbol_from_file_path(file):

def _is_check_valid_extension_slot(slot_name, meta):
extension_definitions = meta.get("extension_definitions", [])
return any(entry.get("slot_name") == slot_name for entry in extension_definitions)

return any("property" in entry and entry.get("slot_name") == slot_name for entry in extension_definitions)

def _is_irregular_metadata(metadata_list: List[Dict]):
fail_metadata = False
Expand Down
17 changes: 13 additions & 4 deletions tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,23 +464,32 @@ def test_strict_parsing(self):

def test_check_irregular_metadata(self):
"""Test if irregular metadata check works according to https://w3id.org/sssom/spec."""
meta_fail = {
meta_fail_because_undeclared_extension = {
"licenses": "http://licen.se",
"mapping_set_id": "http://mapping.set/id1",
"ext_test": "value",
}
meta_ok = {
meta_fail_because_extension_without_property = {
"license": "http://licen.se",
"mapping_set_id": "http://mapping.set/id1",
"ext_test": "value",
"extension_definitions": [{"slot_name": "ext_test"}],
}

meta_ok = {
"license": "http://licen.se",
"mapping_set_id": "http://mapping.set/id1",
"ext_test": "value",
"extension_definitions": [{"slot_name": "ext_test", "property": "skos:fantasyRelation"}],
}

from sssom.parsers import _is_check_valid_extension_slot, _is_irregular_metadata

is_irregular_metadata_fail_case = _is_irregular_metadata([meta_fail])
is_irregular_metadata_fail_undeclared_case = _is_irregular_metadata([meta_fail_because_undeclared_extension])
is_valid_extension = _is_check_valid_extension_slot("ext_test", meta_ok)
is_irregular_metadata_ok_case = _is_irregular_metadata([meta_ok])
self.assertTrue(is_irregular_metadata_fail_case)
is_irregular_metadata_fail_missing_property_case = _is_irregular_metadata([meta_fail_because_extension_without_property])
self.assertTrue(is_irregular_metadata_fail_undeclared_case)
self.assertTrue(is_irregular_metadata_fail_missing_property_case)
self.assertTrue(is_valid_extension)
self.assertFalse(is_irregular_metadata_ok_case)

0 comments on commit 57d24f9

Please sign in to comment.