Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Sep 7, 2023
1 parent 987ab23 commit 2839455
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/curies/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ def _merge(record: Record, record_into: Record) -> None:
if prefix_synonym not in record_into._all_prefixes:
record_into.prefix_synonyms.append(prefix_synonym)
record_into.prefix_synonyms.sort()

for uri_prefix_synonym in itt.chain([record.uri_prefix], record.uri_prefix_synonyms):
if uri_prefix_synonym not in record_into._all_uri_prefixes:
record_into.uri_prefix_synonyms.append(uri_prefix_synonym)
Expand Down
24 changes: 13 additions & 11 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from curies.version import get_version

CHEBI_URI_PREFIX = "http://purl.obolibrary.org/obo/CHEBI_"
GO_URI_PREFIX = "http://purl.obolibrary.org/obo/GO_"


def _s() -> str:
Expand Down Expand Up @@ -60,7 +61,7 @@ def test_extend_on_prefix_match(self):
prefix="CHEBI",
prefix_synonyms=[s1],
uri_prefix=s2,
uri_prefix_synoynms=[s3],
uri_prefix_synonyms=[s3],
)
with self.assertRaises(ValueError):
self.converter.add_record(record, merge=False)
Expand All @@ -79,7 +80,7 @@ def test_extend_on_prefix_synonym_match(self):
prefix=s1,
prefix_synonyms=["CHEBI"],
uri_prefix=s2,
uri_prefix_synoynms=[s3],
uri_prefix_synonyms=[s3],
)
with self.assertRaises(ValueError):
self.converter.add_record(record, merge=False)
Expand Down Expand Up @@ -438,7 +439,7 @@ def test_combine(self):

def test_combine_with_synonyms(self):
"""Test combination with synonyms."""
r1 = Record(prefix="GO", uri_prefix="http://purl.obolibrary.org/obo/GO_")
r1 = Record(prefix="GO", uri_prefix=GO_URI_PREFIX)
r2 = Record(prefix="go", prefix_synonyms=["GO"], uri_prefix="https://identifiers.org/go:")

c1 = Converter([])
Expand All @@ -447,17 +448,18 @@ def test_combine_with_synonyms(self):

c1.add_record(r2, merge=True)
self.assertEqual(1, len(c1.records))
self.assertNotEquals(r1, c1.records[0])
self.assertNotEquals(r2, c1.records[0])
r = c1.records[0]
self.assertEqual("GO", r.prefix)
self.assertEqual({"go"}, set(r.prefix_synonyms))
self.assertEqual("http://purl.obolibrary.org/obo/GO_", r.uri_prefix)
self.assertEqual({"https://identifiers.org/go:"}, set(r.uri_prefix_synonyms))

c1 = Converter.from_prefix_map({"GO": "http://purl.obolibrary.org/obo/GO_"})
c2 = Converter([])
c3 = chain([c1, c2])
c3 = chain([Converter([r1]), Converter([r2])])
self.assertEqual(1, len(c3.records))
self.assertIn("GO", c3.prefix_map)
self.assertIn("go", c3.prefix_map)
self.assertIn("go", c3.bimap)
self.assertNotIn("GO", c3.bimap)
self.assertIn("go", c3.prefix_map, msg=f"PM: {c3.prefix_map}")
self.assertNotIn("go", c3.bimap)
self.assertIn("GO", c3.bimap)

def test_combine_ci(self):
"""Test combining case insensitive."""
Expand Down

0 comments on commit 2839455

Please sign in to comment.