Skip to content

Commit

Permalink
test(converters): add tests
Browse files Browse the repository at this point in the history
Extend "linkml-convert" tests to cover the new option
"--include-range-class-descendants".

Signed-off-by: Silvano Cirujano Cuesta <silvano.cirujano-cuesta@siemens.com>
  • Loading branch information
Silvanoc committed Sep 21, 2023
1 parent cd021ee commit 848810a
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/test_utils/input/Person-01.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
id: P:004
name: eventful life
has_events:
- employed_at: ROR:1
started_at_time: "2019-01-01"
is_current: true
- started_at_time: "2023-01-01"
in_location: GEO:1234
diagnosis:
id: CODE:P1789
name: hypertension
procedure:
id: CODE:P1846
name: valve repair

7 changes: 7 additions & 0 deletions tests/test_utils/input/animals.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
animals:
- animal_family: Dog
max_age: "17 years"
breed: Golden Retriever
- animal_family: Ant
max_age: "7 years"
venom: true
36 changes: 36 additions & 0 deletions tests/test_utils/input/schema7.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
id: https://example.org/descendants
name: Test_descendants
imports:
- linkml:types
prefixes:
linkml: https://w3id.org/linkml/
classes:
Animal:
slots:
- animal_family
attributes:
max_age:
range: string
Dog:
is_a: Animal
slots:
- animal_family
- breed
Ant:
is_a: Animal
slots:
- animal_family
- venom
Container:
attributes:
animals:
multivalued: true
range: Animal
slots:
animal_family:
range: string
designates_type: true
breed:
range: string
venom:
range: boolean
37 changes: 37 additions & 0 deletions tests/test_utils/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
YAML_OUT = env.expected_path("data_example.out.yaml")
RDF_OUT = env.expected_path("data_example.out.ttl")

SCHEMA_DESCENDANTS = env.input_path("schema7.yaml")
DATA_DESCENDANTS = env.input_path("animals.yaml")


class TestCommandLineInterface(unittest.TestCase):
def setUp(self) -> None:
Expand Down Expand Up @@ -49,6 +52,40 @@ def test_infer_and_convert(self):
self.assertEqual(p2["age_category"], "adult")
self.assertEqual(p2["full_name"], "first2 last2")

def test_convert_including_descendants(self):
"""
Tests using the --include-range-class-descendants option to support
subtype polymorphism.
"""
result = self.runner.invoke(
cli,
[
"--include-range-class-descendants",
"--validate",
"-C",
"Container",
"-s",
SCHEMA_DESCENDANTS,
"-t",
"json-ld",
"-o",
JSON_OUT,
DATA_DESCENDANTS,
],
)
print(result.stdout)
if result.exit_code:
print(result.exception)
raise result.exception
else:
with open(JSON_OUT) as file:
p1 = json.load(file)
print(p1)
self.assertEqual(p1["animals"][0]["animal_family"], "Dog")
self.assertEqual(p1["animals"][0]["breed"], "Golden Retriever")
self.assertEqual(p1["animals"][1]["animal_family"], "Ant")
self.assertTrue(p1["animals"][1]["venom"])

def test_version(self):
runner = CliRunner(mix_stderr=False)
result = runner.invoke(cli, ["--version"])
Expand Down

0 comments on commit 848810a

Please sign in to comment.