-
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: implement basic unit tests for OrderByFieldBindingsMap
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
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,48 @@ | ||
"""Basic unit tests for OrderableFieldsBindingsMap""" | ||
|
||
from typing import Annotated | ||
|
||
from pydantic import BaseModel | ||
import pytest | ||
from rdfproxy.utils._types import SPARQLBinding | ||
from rdfproxy.utils.utils import OrderableFieldsBindingsMap | ||
|
||
|
||
class ReallyDeeplyNestedModel(BaseModel): | ||
c: Annotated[str, SPARQLBinding("C_ALIAS")] | ||
|
||
|
||
class DeeplyNestedModel(BaseModel): | ||
really_deeply_nested: ReallyDeeplyNestedModel | ||
really_deeply_nested_list: list[ReallyDeeplyNestedModel] | ||
|
||
|
||
class NestedModel(BaseModel): | ||
b: Annotated[str, SPARQLBinding("B_ALIAS")] | ||
deeply_nested: DeeplyNestedModel | ||
|
||
|
||
class TopModel(BaseModel): | ||
a: str | ||
nested: NestedModel | ||
nested_list: list[NestedModel] | ||
nested_alias_list: Annotated[list[NestedModel], SPARQLBinding("NOT_ORDERABLE")] | ||
some_list: list[int] | ||
|
||
|
||
def test_basic_ordery_by_field_bindings_map(): | ||
mapping = OrderableFieldsBindingsMap(model=TopModel) | ||
|
||
expected = { | ||
"a": "a", | ||
"NestedModel.b": "B_ALIAS", | ||
"ReallyDeeplyNestedModel.c": "C_ALIAS", | ||
} | ||
assert mapping == expected | ||
|
||
|
||
def test_sad_ordery_by_field_bindings_map(): | ||
mapping = OrderableFieldsBindingsMap(model=TopModel) | ||
|
||
with pytest.raises(ValueError): | ||
mapping["dne"] |