Skip to content

Commit

Permalink
- Add: TestWrite.test_missing_entries()
Browse files Browse the repository at this point in the history
  • Loading branch information
joeflack4 committed May 20, 2024
1 parent 91d08b8 commit 43fa8f5
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/test_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import unittest
from typing import Any, Dict

import curies
import pandas as pd
from curies import Converter

Expand Down Expand Up @@ -191,3 +192,69 @@ def test_write_sssom_ontoportal_json(self):
self.mapping_count,
f"{path} has the wrong number of mappings.",
)

# TODO: Determine assertions that should pass
# TODO: Fix failing assertions that should pass
# TODO: before merging, remove pass/fail comments at end of assertion lines
def test_missing_entries(self):
"""Test to make sure that missing entires do not appear."""
df = pd.DataFrame(
[
{
"subject_id": "Orphanet:58",
"subject_label": "Alexander disease",
"predicate_id": "skos:exactMatch",
"object_id": "icd11.foundation:2023359698",
"object_label": "Alexander disease",
"mapping_justification": "semapv:UnspecifiedMatching",
}
]
)
metadata = {
"creator_id": "orcid:0000-0002-2906-7319",
"curie_map": {
"MONDO": "http://purl.obolibrary.org/obo/MONDO_",
"Orphanet": "http://www.orpha.net/ORDO/Orphanet_",
"icd11.foundation": "http://id.who.int/icd/entity/",
"oboInOwl": "http://www.geneontology.org/formats/oboInOwl#",
"orcid": "https://orcid.org/",
"owl": "http://www.w3.org/2002/07/owl#",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"semapv": "https://w3id.org/semapv/",
"skos": "http://www.w3.org/2004/02/skos/core#",
"sssom": "https://w3id.org/sssom/",
},
"license": "http://w3id.org/sssom/license/unspecified",
"mapping_provider": "https://www.orpha.net/",
}

# When passing Converter
msdf: MappingSetDataFrame = MappingSetDataFrame(
converter=curies.Converter.from_prefix_map(metadata["curie_map"]),
df=df,
metadata=metadata,
)
self.assertIn("curie_map", msdf.metadata) # pass
self.assertIn("icd11.foundation", msdf.metadata["curie_map"]) # pass
self.assertIn("icd11.foundation", msdf.prefix_map) # pass
tmp_file = os.path.join(test_out_dir, "test_missing_entries.sssom.tsv")
with open(tmp_file, "w") as f:
write_table(msdf, f)
msdf2 = parse_sssom_table(tmp_file)
self.assertIn("curie_map", msdf2.metadata) # fail
self.assertIn("icd11.foundation", msdf2.metadata["curie_map"]) # KeyError
self.assertIn("icd11.foundation", msdf2.prefix_map) # pass

# When no passed Converter
msdf: MappingSetDataFrame = MappingSetDataFrame(df=df, metadata=metadata)
self.assertIn("curie_map", msdf.metadata) # pass
self.assertIn("icd11.foundation", msdf.metadata["curie_map"]) # pass
self.assertIn("icd11.foundation", msdf.prefix_map) # fail
tmp_file = os.path.join(test_out_dir, "test_missing_entries.sssom.tsv")
with open(tmp_file, "w") as f:
write_table(msdf, f)
msdf2 = parse_sssom_table(tmp_file)
self.assertIn("curie_map", msdf2.metadata) # fail
self.assertIn("icd11.foundation", msdf2.metadata["curie_map"]) # KeyError
self.assertIn("icd11.foundation", msdf2.prefix_map) # fail

0 comments on commit 43fa8f5

Please sign in to comment.