Skip to content

Commit

Permalink
fix(test): adapt QueryResult mock to pass runtime checking
Browse files Browse the repository at this point in the history
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 beartype/beartype#92.
  • Loading branch information
lu-pl committed Nov 30, 2024
1 parent 07cfe93 commit 5c1e8fc
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/unit/test_sad_path_get_bindings_from_query_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 5c1e8fc

Please sign in to comment.