-
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 example test for construct_count_query
- Loading branch information
Showing
2 changed files
with
57 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,11 @@ | ||
"""Simple dummy models e.g. for count query constructor testing.""" | ||
|
||
from pydantic import BaseModel, ConfigDict | ||
|
||
|
||
class Dummy(BaseModel): | ||
pass | ||
|
||
|
||
class GroupedDummy(BaseModel): | ||
model_config = ConfigDict(group_by="x") |
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,46 @@ | ||
"""Pytest entry point for rdfproxy.utils.sparql_utils.construct_count_query tests.""" | ||
|
||
from pydantic import BaseModel, ConfigDict | ||
from rdflib import Graph | ||
from rdflib.plugins.sparql.processor import SPARQLResult | ||
from rdfproxy.utils.sparql_utils import construct_count_query | ||
|
||
|
||
query = """ | ||
select ?x ?y ?z | ||
where { | ||
values (?x ?y ?z) { | ||
(1 2 3) | ||
(1 22 33) | ||
(2 222 333) | ||
} | ||
} | ||
""" | ||
|
||
graph: Graph = Graph() | ||
|
||
|
||
class Dummy(BaseModel): | ||
pass | ||
|
||
|
||
class GroupedDummy(BaseModel): | ||
model_config = ConfigDict(group_by="x") | ||
|
||
|
||
count_query_dummy = construct_count_query(query=query, model=Dummy) | ||
count_query_grouped_dummy = construct_count_query(query=query, model=GroupedDummy) | ||
|
||
|
||
def _get_cnt_value_from_sparql_result( | ||
result: SPARQLResult, count_var: str = "cnt" | ||
) -> int: | ||
return int(result.bindings[0][count_var]) | ||
|
||
|
||
def test_basic_construct_count_query(): | ||
result_dummy: SPARQLResult = graph.query(count_query_dummy) | ||
result_grouped_dummy: SPARQLResult = graph.query(count_query_grouped_dummy) | ||
|
||
assert _get_cnt_value_from_sparql_result(result_dummy) == 3 | ||
assert _get_cnt_value_from_sparql_result(result_grouped_dummy) == 2 |