From 5c1e8fc72e3b2637d6d44da4740b94ab9661cb42 Mon Sep 17 00:00:00 2001 From: Lukas Plank Date: Sat, 30 Nov 2024 19:38:50 +0100 Subject: [PATCH] fix(test): adapt QueryResult mock to pass runtime checking Runtime checking mock objects is an interesting case! Mock objects rightfully get rejected by runtime type checking, the solution is to point the mock object's __class__ to the class of the mocked object. See https://github.com/beartype/beartype/issues/92. --- tests/unit/test_sad_path_get_bindings_from_query_result.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/test_sad_path_get_bindings_from_query_result.py b/tests/unit/test_sad_path_get_bindings_from_query_result.py index 2bc655c..fc61756 100644 --- a/tests/unit/test_sad_path_get_bindings_from_query_result.py +++ b/tests/unit/test_sad_path_get_bindings_from_query_result.py @@ -4,11 +4,14 @@ import pytest +from SPARQLWrapper.Wrapper import QueryResult from rdfproxy.utils.sparql_utils import get_bindings_from_query_result def test_basic_sad_path_get_bindings_from_query_result(): with mock.patch("SPARQLWrapper.QueryResult") as mock_query_result: + mock_query_result.__class__ = QueryResult + mock_query_result.return_value.requestedFormat = "xml" exception_message = ( "Only QueryResult objects with JSON format are currently supported."