Skip to content

Commit

Permalink
test: adapt tests for SPARQLModelAdapter redesign
Browse files Browse the repository at this point in the history
Add a basic test case for array collection behavior
  • Loading branch information
lu-pl committed Oct 8, 2024
1 parent a386516 commit 60d499e
Show file tree
Hide file tree
Showing 19 changed files with 382 additions and 218 deletions.
Empty file removed tests/__init__.py
Empty file.
22 changes: 0 additions & 22 deletions tests/conftest.py

This file was deleted.

22 changes: 0 additions & 22 deletions tests/data/init_model_from_kwargs_parameters.py

This file was deleted.

30 changes: 0 additions & 30 deletions tests/data/models.py

This file was deleted.

22 changes: 22 additions & 0 deletions tests/data/models/author_array_collection_model.py
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")]
26 changes: 26 additions & 0 deletions tests/data/models/author_work_title_model.py
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]
18 changes: 18 additions & 0 deletions tests/data/models/basic_model.py
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
21 changes: 21 additions & 0 deletions tests/data/models/grouping_model.py
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]
24 changes: 24 additions & 0 deletions tests/data/models/nested_grouping_model.py
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 tests/data/parameters/author_array_collection_model_parameters.py
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 tests/data/parameters/author_work_title_model_parameters.py
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"}]}],
},
],
)
]
49 changes: 49 additions & 0 deletions tests/data/parameters/basic_model_parameters.py
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}}},
],
),
]
Loading

0 comments on commit 60d499e

Please sign in to comment.