Skip to content

Commit 5d507b1

Browse files
committed
test: adapt SPARQLWrapper.queries test for suppressed warnings
1 parent e09b80c commit 5d507b1

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

tests/test_sparqlwrapper/test_sparqlwrapper_query.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@
77
import operator
88
from typing import NamedTuple
99
from typing import Any
10+
import warnings
1011

12+
import httpx
1113
import pytest
1214
from rdflib import BNode, Graph, Literal, URIRef, XSD
1315
from rdflib.compare import isomorphic
16+
from sparqlx import SPARQLWrapper
17+
from sparqlx.utils.operation_parameters import (
18+
rdf_response_format_map,
19+
sparql_result_response_format_map,
20+
)
1421

1522
from conftest import FusekiEndpoints, RDFLibGraphEndpoints
1623
from data.queries import (
@@ -22,12 +29,6 @@
2229
select_query_types,
2330
select_query_xy_values,
2431
)
25-
import httpx
26-
from sparqlx import SPARQLWrapper
27-
from sparqlx.utils.operation_parameters import (
28-
rdf_response_format_map,
29-
sparql_result_response_format_map,
30-
)
3132
from utils import acall
3233

3334

@@ -309,12 +310,23 @@ async def test_sparqlwrapper_streaming(query_method, query, triplestore):
309310
],
310311
)
311312
def test_sparqlwrapper_queries(query_method, query, triplestore):
313+
"""Compare the results of SPARQLWrapper.queries and manually running SPARQLWrapper.aquery.
314+
315+
The test also checks that no client manager warnings are emitted
316+
from SPARQLWrapper.queries. This is achieved by locally setting
317+
the warnings filter to raise an error for all warnings;
318+
i.e. if no warning is emitted, the test passes because no exceptions
319+
are raised from any warning.
320+
"""
321+
312322
endpoint = triplestore.sparql_endpoint
313323
sparqlwrapper = SPARQLWrapper(sparql_endpoint=endpoint, query_method=query_method)
314324

315325
queries: list[str] = [query for _ in range(5)]
316326

317-
results_queries = sparqlwrapper.queries(*queries)
327+
with warnings.catch_warnings():
328+
warnings.simplefilter("error")
329+
results_queries = sparqlwrapper.queries(*queries)
318330

319331
async def _runner():
320332
async with asyncio.TaskGroup() as tg:

0 commit comments

Comments
 (0)