Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ are correct and expected given the context of the PR.
2. Install all the dependencies from your project, which are typically specified in a `uv.lock` file.

```
uv sync --all-extras --dev
uv sync --all-extras --dev
```

3. Run any python scripts or CLI commands by prefixing with `uv run`.
Expand Down
20 changes: 20 additions & 0 deletions tests/test_loaders_dumpers/input/book_series_lotr_json.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
id: S001
name: Lord of the Rings
genres:
- fantasy
creator:
name: JRR Tolkien
from_country: England
books:
- id: S001.1
name: Fellowship of the Ring
summary: Hobbits
price: 5.99
- id: S001.2
name: The Two Towers
summary: More hobbits
price: 5.99
- id: S001.3
name: Return of the King
summary: Yet more hobbits
price: 6.99
20 changes: 20 additions & 0 deletions tests/test_loaders_dumpers/input/book_series_lotr_yaml.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
id: S001
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is identical to the other file -- I would just have a single file, book_series_lotr.yaml.

name: Lord of the Rings
genres:
- fantasy
creator:
name: JRR Tolkien
from_country: England
books:
- id: S001.1
name: Fellowship of the Ring
summary: Hobbits
price: 5.99
- id: S001.2
name: The Two Towers
summary: More hobbits
price: 5.99
- id: S001.3
name: Return of the King
summary: Yet more hobbits
price: 6.99
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
persons:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like this is also identical to the yaml version -- just add one, no need for duplicates.

- id: P:001
name: fred bloggs
age_in_years: 33
- id: P:002
name: joe schmoe
has_employment_history:
- started_at_time: 2019-01-01
is_current: true
employed_at: ROR:1
has_familial_relationships:
- related_to: P:001
type: SIBLING_OF
has_medical_history:
- started_at_time: 2019-01-01
in_location: GEO:1234
diagnosis:
id: CODE:D0001
name: headache
in_code_system: DiseaseCodes
procedure:
id: CODE:P0001
name: trepanation
in_code_system: ProcedureCodes
addresses:
- street: 1 foo street
city: foo city
companies:
- id: ROR:1
name: foo
activities:
- id: A:1
started_at_time: 2019-01-01
was_associated_with: Agent:987
code_systems:
DiseaseCodes:
id: DiseaseCodes
name: disease codes
ProcedureCodes:
id: ProcedureCodes
name: disease codes
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
persons:
- id: P:001
name: fred bloggs
age_in_years: 33
- id: P:002
name: joe schmoe
has_employment_history:
- started_at_time: 2019-01-01
is_current: true
employed_at: ROR:1
has_familial_relationships:
- related_to: P:001
type: SIBLING_OF
has_medical_history:
- started_at_time: 2019-01-01
in_location: GEO:1234
diagnosis:
id: CODE:D0001
name: headache
in_code_system: DiseaseCodes
procedure:
id: CODE:P0001
name: trepanation
in_code_system: ProcedureCodes
addresses:
- street: 1 foo street
city: foo city
companies:
- id: ROR:1
name: foo
activities:
- id: A:1
started_at_time: 2019-01-01
was_associated_with: Agent:987
code_systems:
DiseaseCodes:
id: DiseaseCodes
name: disease codes
ProcedureCodes:
id: ProcedureCodes
name: disease codes
54 changes: 32 additions & 22 deletions tests/test_loaders_dumpers/test_loaders_pydantic.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
import unittest
from pathlib import Path

import pytest
from hbreader import FileInfo
from pydantic import BaseModel

from linkml_runtime.dumpers import yaml_dumper
from linkml_runtime.loaders import json_loader, yaml_loader
from tests.test_loaders_dumpers.environment import env
from tests.test_loaders_dumpers.loaderdumpertestcase import LoaderDumperTestCase
from tests.test_loaders_dumpers.models.books_normalized_pydantic import BookSeries
from tests.test_loaders_dumpers.models.kitchen_sink_pydantic import Dataset


class PydanticLoadersUnitTest(LoaderDumperTestCase):
env = env

def test_yaml_loader_single(self):
"""Load obo_sample.yaml, emit obo_sample_yaml.yaml and compare to obo_sample_output.yaml"""
self.loader_test("book_series_lotr.yaml", BookSeries, yaml_loader)

def test_json_loader(self):
"""Load obo_sample.json, emit obo_sample_json.yaml and check the results"""
self.loader_test("book_series_lotr.json", BookSeries, json_loader)

def test_yaml_loader_kitchen_sink(self):
self.loader_test("kitchen_sink_normalized_inst_01.yaml", Dataset, yaml_loader)

def test_json_loader_kitchen_sink(self):
self.loader_test("kitchen_sink_normalized_inst_01.json", Dataset, json_loader)


if __name__ == "__main__":
unittest.main()
@pytest.mark.parametrize(
"filename,model,loader",
[
("book_series_lotr.yaml", BookSeries, yaml_loader),
("book_series_lotr.json", BookSeries, json_loader),
("kitchen_sink_normalized_inst_01.yaml", Dataset, yaml_loader),
("kitchen_sink_normalized_inst_01.json", Dataset, json_loader),
],
)
def test_loader_basemodel(filename, model, loader):
name = Path(filename).stem
type = Path(filename).suffix.lstrip(".")
expected_yaml_file = env.input_path(f"{name}_{type}.yaml")

metadata = FileInfo()

python_obj: BaseModel = loader.load(filename, model, metadata=metadata, base_dir=env.indir)

# Load expected output
with open(expected_yaml_file) as expf:
expected = expf.read()

got = yaml_dumper.dumps(python_obj)
expected_trimmed = expected.replace("\r\n", "\n").strip()
got_trimmed = got.replace("\r\n", "\n").strip()
assert expected_trimmed == got_trimmed
Loading