Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Apr 22, 2024
1 parent 5fe2a21 commit 9308e01
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/curies/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,12 @@ def _key(self) -> RecordKey:

from pydantic import BaseModel

class Records(BaseModel):
class Records(BaseModel): # type:ignore
"""A list of records."""

class Config:
"""Configuration for the records."""

arbitrary_types_allowed = True

__root__: List[Record]
Expand All @@ -331,10 +333,12 @@ class Config:

from pydantic import RootModel

class Records(RootModel):
class Records(RootModel[List[Record]]): # type:ignore
"""A list of records."""

root: List[Record]
def __iter__(self) -> Iterable[Record]:
"""Iterate over records."""
return cast(Iterable[Record], iter(self.root))


class DuplicateSummary(NamedTuple):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ExpansionError,
PrefixStandardizationError,
Record,
Records,
Reference,
ReferenceTuple,
URIStandardizationError,
Expand All @@ -41,6 +42,16 @@
GO_URI_PREFIX = "http://purl.obolibrary.org/obo/GO_"


class TestStruct(unittest.TestCase):
"""Test the data structures."""

def test_records(self):
"""Test a list of records."""
records = Records.parse_obj([{"prefix": "chebi", "uri_prefix": CHEBI_URI_PREFIX}])
converter = Converter(records=records)
self.assertEqual({"chebi"}, converter.get_prefixes())


class TestAddRecord(unittest.TestCase):
"""Test adding records."""

Expand Down

0 comments on commit 9308e01

Please sign in to comment.