Skip to content

Commit dd90359

Browse files
committed
Fixed the test instance data so that it actually matches the yaml (🤦), checked the contents against an instance file that goes through the empty item cleanup function.
1 parent 51d27f9 commit dd90359

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

‎tests/test_loaders_dumpers/models/books_normalized_pydantic.py‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
from __future__ import annotations
22
from datetime import datetime, date
33
from enum import Enum
4-
from typing import List, Dict, Optional, Any
4+
from typing import List, Dict, Optional, Any, Union, Literal
55
from pydantic import BaseModel as BaseModel, Field
6+
from linkml_runtime.linkml_model import Decimal
67

78
metamodel_version = "None"
89
version = "None"
910

1011
class WeakRefShimBaseModel(BaseModel):
1112
__slots__ = '__weakref__'
12-
13+
1314
class ConfiguredBaseModel(WeakRefShimBaseModel,
14-
validate_assignment = True,
15-
validate_all = True,
16-
underscore_attrs_are_private = True,
17-
extra = 'forbid',
18-
arbitrary_types_allowed = True):
19-
pass
15+
validate_assignment = True,
16+
validate_all = True,
17+
underscore_attrs_are_private = True,
18+
extra = 'forbid',
19+
arbitrary_types_allowed = True,
20+
use_enum_values = True):
21+
pass
2022

2123

2224
class GenreEnum(str, Enum):

‎tests/test_loaders_dumpers/models/kitchen_sink_pydantic.py‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010

1111
class WeakRefShimBaseModel(BaseModel):
1212
__slots__ = '__weakref__'
13-
13+
1414
class ConfiguredBaseModel(WeakRefShimBaseModel,
15-
validate_assignment = True,
16-
validate_all = True,
17-
underscore_attrs_are_private = True,
18-
extra = 'forbid',
19-
arbitrary_types_allowed = True):
20-
pass
15+
validate_assignment = True,
16+
validate_all = True,
17+
underscore_attrs_are_private = True,
18+
extra = 'forbid',
19+
arbitrary_types_allowed = True,
20+
use_enum_values = False):
21+
pass
2122

2223

2324
class FamilialRelationshipType(str, Enum):
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
import json
2+
3+
import yaml
4+
15
from linkml_runtime.dumpers import yaml_dumper, json_dumper, csv_dumper
26
from tests.test_loaders_dumpers.loaderdumpertestcase import LoaderDumperTestCase
37
from tests.test_loaders_dumpers.models.books_normalized_pydantic import Book, BookSeries, Author
8+
from linkml_runtime.utils.formatutils import remove_empty_items
49

510

611
class PydanticDumpersTestCase(LoaderDumperTestCase):
@@ -10,22 +15,29 @@ class PydanticDumpersTestCase(LoaderDumperTestCase):
1015
def setUpClass(cls) -> None:
1116
""" Generate a small sample Books instance for testing purposes """
1217
LoaderDumperTestCase.setUpClass()
13-
b1 = Book(name='The Fellowship of the Ring', id="S001.1", price="5.99", summary="Hobbits")
18+
b1 = Book(name='Fellowship of the Ring', id="S001.1", price="5.99", summary="Hobbits")
1419
b2 = Book(name='The Two Towers', id="S001.2", price="5.99", summary="More hobbits")
15-
b3 = Book(name='The Return of the King', id="S001.3", price="5.99", summary="Yet more hobbits")
16-
jrr = Author(name='JRR Tolkien', from_country='England')
17-
cls.bookseries = BookSeries(name='The Lord of the Rings', id="S001", genres=["fantasy"], creator=jrr, books=[b1, b2, b3])
20+
b3 = Book(name='Return of the King', id="S001.3", price="6.99", summary="Yet more hobbits")
21+
jrr = Author(name='JRR Tolkein', from_country='England')
22+
cls.bookseries = BookSeries(name='Lord of the Rings', id="S001", genres=["fantasy"], creator=jrr, books=[b1, b2, b3])
1823

1924
def test_yaml_dumper(self):
2025
""" Test the yaml emitter """
2126
self.dump_test('book_series_lotr.yaml', lambda out_fname: yaml_dumper.dump(self.bookseries, out_fname))
2227
self.dumps_test('book_series_lotr.yaml', lambda: yaml_dumper.dumps(self.bookseries))
2328

24-
#TODO: test the contents of generated file
29+
# test contents of yaml file with cleaned dict made from bookseries instance in setup
30+
with open(self.env.input_path('book_series_lotr.yaml'), 'r') as f:
31+
data = yaml.safe_load(f)
32+
self.assertEqual(data, remove_empty_items(self.bookseries.dict()))
33+
2534

2635
def test_json_dumper(self):
2736
""" Test the json emitter """
2837
self.dump_test('book_series_lotr.json', lambda out_fname: json_dumper.dump(self.bookseries, out_fname))
2938
self.dumps_test('book_series_lotr.json', lambda: json_dumper.dumps(self.bookseries))
3039

31-
#TODO: test the contents of generated file
40+
# test contents of json file with cleaned dict made from bookseries instance in setup
41+
with open(self.env.input_path('book_series_lotr.json'), 'r') as f:
42+
data = json.load(f)
43+
self.assertEqual(data, remove_empty_items(self.bookseries.dict()))

0 commit comments

Comments
 (0)