-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: adapt tests for SPARQLModelAdapter redesign
Add a basic test case for array collection behavior
- Loading branch information
Showing
19 changed files
with
382 additions
and
218 deletions.
There are no files selected for viewing
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from typing import Annotated | ||
|
||
from pydantic import BaseModel | ||
from rdfproxy.utils._types import SPARQLBinding | ||
|
||
|
||
class Work(BaseModel): | ||
class Config: | ||
group_by = "work_name" | ||
|
||
name: Annotated[str, SPARQLBinding("work_name")] | ||
viafs: Annotated[list[str], SPARQLBinding("viaf")] | ||
|
||
|
||
class Author(BaseModel): | ||
class Config: | ||
group_by = "nameLabel" | ||
|
||
gnd: str | ||
surname: Annotated[str, SPARQLBinding("nameLabel")] | ||
works: list[Work] | ||
education: Annotated[list[str], SPARQLBinding("educated_atLabel")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Toy Author/Work model for testing.""" | ||
|
||
from typing import Annotated | ||
|
||
from pydantic import BaseModel | ||
from rdfproxy.utils._types import SPARQLBinding | ||
|
||
|
||
class Title(BaseModel): | ||
name: Annotated[str, SPARQLBinding("work")] | ||
|
||
|
||
class Work(BaseModel): | ||
class Config: | ||
group_by = "year" | ||
|
||
year: int | ||
titles: list[Title] | ||
|
||
|
||
class Author(BaseModel): | ||
class Config: | ||
group_by = "author" | ||
|
||
name: Annotated[str, SPARQLBinding("author")] | ||
works: list[Work] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"""Basic model for RDFProxy testing.""" | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class BasicSimpleModel(BaseModel): | ||
x: int | ||
y: int | ||
|
||
|
||
class BasicNestedModel(BaseModel): | ||
a: str | ||
b: BasicSimpleModel | ||
|
||
|
||
class BasicComplexModel(BaseModel): | ||
p: str | ||
q: BasicNestedModel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"""Grouping model for RDFProxy testing.""" | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class GroupingSimpleModel(BaseModel): | ||
x: int | ||
y: int | ||
|
||
|
||
class GroupingNestedModel(BaseModel): | ||
a: str | ||
b: GroupingSimpleModel | ||
|
||
|
||
class GroupingComplexModel(BaseModel): | ||
class Config: | ||
group_by = "x" | ||
|
||
p: str | ||
q: list[GroupingNestedModel] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Nested grouping model for RDFProxy testing.""" | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class NestedGroupingSimpleModel(BaseModel): | ||
x: int | ||
y: int | ||
|
||
|
||
class NestedGroupingNestedModel(BaseModel): | ||
class Config: | ||
group_by = "y" | ||
|
||
a: str | ||
b: list[NestedGroupingSimpleModel] | ||
|
||
|
||
class NestedGroupingComplexModel(BaseModel): | ||
class Config: | ||
group_by = "a" | ||
|
||
p: str | ||
q: list[NestedGroupingNestedModel] |
87 changes: 87 additions & 0 deletions
87
tests/data/parameters/author_array_collection_model_parameters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from tests.data.models.author_array_collection_model import Author | ||
from tests.utils._types import Parameter | ||
|
||
|
||
author_array_collection_parameters = [ | ||
Parameter( | ||
model=Author, | ||
bindings=[ | ||
{ | ||
"work": "http://www.wikidata.org/entity/Q1497409", | ||
"gnd": "119359464", | ||
"work_name": "Geb\u00fcrtig", | ||
"nameLabel": "Schindel", | ||
}, | ||
{ | ||
"work": "http://www.wikidata.org/entity/Q15805238", | ||
"gnd": "115612815", | ||
"work_name": "Der alte K\u00f6nig in seinem Exil", | ||
"nameLabel": "Geiger", | ||
"viaf": "299260555", | ||
"educated_atLabel": "University of Vienna", | ||
}, | ||
{ | ||
"work": "http://www.wikidata.org/entity/Q15805238", | ||
"gnd": "115612815", | ||
"work_name": "Der alte K\u00f6nig in seinem Exil", | ||
"nameLabel": "Geiger", | ||
"viaf": "6762154387354230970008", | ||
"educated_atLabel": "University of Vienna", | ||
}, | ||
{ | ||
"work": "http://www.wikidata.org/entity/Q58038819", | ||
"gnd": "115612815", | ||
"work_name": "Unter der Drachenwand", | ||
"nameLabel": "Geiger", | ||
"viaf": "2277151717053313900002", | ||
"educated_atLabel": "University of Vienna", | ||
}, | ||
{ | ||
"work": "http://www.wikidata.org/entity/Q100266054", | ||
"gnd": "1136992030", | ||
"work_name": "Das fl\u00fcssige Land", | ||
"nameLabel": "Edelbauer", | ||
"educated_atLabel": "University of Vienna", | ||
}, | ||
{ | ||
"work": "http://www.wikidata.org/entity/Q100266054", | ||
"gnd": "1136992030", | ||
"work_name": "Das fl\u00fcssige Land", | ||
"nameLabel": "Edelbauer", | ||
"educated_atLabel": "University of Applied Arts Vienna", | ||
}, | ||
], | ||
expected=[ | ||
{ | ||
"gnd": "119359464", | ||
"surname": "Schindel", | ||
"works": [{"name": "Geb\u00fcrtig", "viafs": []}], | ||
"education": [], | ||
}, | ||
{ | ||
"gnd": "115612815", | ||
"surname": "Geiger", | ||
"works": [ | ||
{ | ||
"name": "Der alte K\u00f6nig in seinem Exil", | ||
"viafs": ["299260555", "6762154387354230970008"], | ||
}, | ||
{ | ||
"name": "Unter der Drachenwand", | ||
"viafs": ["2277151717053313900002"], | ||
}, | ||
], | ||
"education": ["University of Vienna"], | ||
}, | ||
{ | ||
"gnd": "1136992030", | ||
"surname": "Edelbauer", | ||
"works": [{"name": "Das fl\u00fcssige Land", "viafs": []}], | ||
"education": [ | ||
"University of Vienna", | ||
"University of Applied Arts Vienna", | ||
], | ||
}, | ||
], | ||
) | ||
] |
28 changes: 28 additions & 0 deletions
28
tests/data/parameters/author_work_title_model_parameters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from tests.data.models.author_work_title_model import Author | ||
from tests.utils._types import Parameter | ||
|
||
|
||
author_work_title_parameters = [ | ||
Parameter( | ||
model=Author, | ||
bindings=[ | ||
{"author": "Author 1", "work": "Work 1", "year": 2000}, | ||
{"author": "Author 2", "work": "Work 4", "year": 2000}, | ||
{"author": "Author 1", "work": "Work 2", "year": 2000}, | ||
{"author": "Author 1", "work": "Work 3", "year": 2001}, | ||
], | ||
expected=[ | ||
{ | ||
"name": "Author 1", | ||
"works": [ | ||
{"year": 2000, "titles": [{"name": "Work 1"}, {"name": "Work 2"}]}, | ||
{"year": 2001, "titles": [{"name": "Work 3"}]}, | ||
], | ||
}, | ||
{ | ||
"name": "Author 2", | ||
"works": [{"year": 2000, "titles": [{"name": "Work 4"}]}], | ||
}, | ||
], | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"""Parameters for instantiate_model_from_bindings with basic models tests.""" | ||
|
||
from tests.data.models.basic_model import ( | ||
BasicComplexModel, | ||
BasicNestedModel, | ||
BasicSimpleModel, | ||
) | ||
from tests.utils._types import Parameter | ||
|
||
|
||
basic_parameters = [ | ||
Parameter( | ||
model=BasicSimpleModel, bindings=[{"x": 1, "y": 2}], expected=[{"x": 1, "y": 2}] | ||
), | ||
Parameter( | ||
model=BasicSimpleModel, | ||
bindings=[{"x": 3, "y": 4}, {"x": 5, "y": 6}], | ||
expected=[{"x": 3, "y": 4}, {"x": 5, "y": 6}], | ||
), | ||
Parameter( | ||
model=BasicNestedModel, | ||
bindings=[{"a": "a value", "x": 1, "y": 2}], | ||
expected=[{"a": "a value", "b": {"x": 1, "y": 2}}], | ||
), | ||
Parameter( | ||
model=BasicNestedModel, | ||
bindings=[{"a": "a value", "x": 1, "y": 2}, {"a": "a value", "x": 3, "y": 4}], | ||
expected=[ | ||
{"a": "a value", "b": {"x": 1, "y": 2}}, | ||
{"a": "a value", "b": {"x": 3, "y": 4}}, | ||
], | ||
), | ||
Parameter( | ||
model=BasicComplexModel, | ||
bindings=[{"a": "a value", "x": 1, "y": 2, "p": "p value"}], | ||
expected=[{"p": "p value", "q": {"a": "a value", "b": {"x": 1, "y": 2}}}], | ||
), | ||
Parameter( | ||
model=BasicComplexModel, | ||
bindings=[ | ||
{"a": "a value", "x": 1, "y": 2, "p": "p value"}, | ||
{"a": "a value", "x": 3, "y": 4, "p": "p value"}, | ||
], | ||
expected=[ | ||
{"p": "p value", "q": {"a": "a value", "b": {"x": 1, "y": 2}}}, | ||
{"p": "p value", "q": {"a": "a value", "b": {"x": 3, "y": 4}}}, | ||
], | ||
), | ||
] |
Oops, something went wrong.