Skip to content

Commit

Permalink
test: implement basic test for explicit binding to model allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
lu-pl committed Aug 16, 2024
1 parent 0eff884 commit 02ed884
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
12 changes: 12 additions & 0 deletions tests/data/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Pydantic model definitions for testing."""

from typing import Annotated

from pydantic import BaseModel
from rdfproxy.utils._types import SPARQLBinding


class SimpleModel(BaseModel):
Expand All @@ -16,3 +19,12 @@ class NestedModel(BaseModel):
class ComplexModel(BaseModel):
p: str
q: NestedModel


class Work(BaseModel):
name: Annotated[str, SPARQLBinding("title")]


class Person(BaseModel):
name: str
work: Work
10 changes: 10 additions & 0 deletions tests/test_instantiate_model_from_kwargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from tests.data.init_model_from_kwargs_parameters import (
init_model_from_kwargs_parameters,
)
from tests.data.models import Person


@pytest.mark.parametrize(("model", "kwargs"), init_model_from_kwargs_parameters)
Expand All @@ -14,3 +15,12 @@ def test_init_model_from_kwargs(model, kwargs):
for _kwargs in kwargs:
model_instance = instantiate_model_from_kwargs(model, **_kwargs)
assert isinstance(model_instance, model)


def test_explicit_sparql_binding_allocation():
bindings: dict = {"title": "Test Title", "name": "Test Name"}
expected: dict = {"name": "Test Name", "work": {"name": "Test Title"}}

model = instantiate_model_from_kwargs(Person, **bindings)

assert expected == model.dict()
3 changes: 2 additions & 1 deletion tests/test_sparql_model_adapter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Pytest entry point for rdfproxy.SPARQLModelAdapter tests."""

from hypothesis import given, settings
import pytest

from hypothesis import given, settings
from rdfproxy import SPARQLModelAdapter
from rdfproxy.utils._exceptions import UndefinedBindingException
from tests.data.models import ComplexModel
Expand Down

0 comments on commit 02ed884

Please sign in to comment.