glowtables/glowtables/tests/conftest.py

48 lines
1.4 KiB
Python

# This file is part of the Glowtables software
# Copyright (C) 2023 Valentin Lorentz
#
# This program is free software: you can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License version 3, as published by the
# Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
"""pytest fixtures"""
# pylint: disable=redefined-outer-name
from typing import Iterable
import pytest
import rdflib
from glowtables.sparql import SparqlBackend
class RdflibSparqlBackend(SparqlBackend):
"""Mock SPARQL backend that queries a local rdflib graph."""
def __init__(self, graph: rdflib.Graph):
self._graph = graph
def query(self, query: str) -> Iterable[tuple]:
ret = self._graph.query(query)
return ret
@pytest.fixture()
def rdflib_graph() -> rdflib.Graph:
"""Returns an empty rdflib graph."""
return rdflib.Graph()
@pytest.fixture()
def rdflib_sparql(rdflib_graph: rdflib.Graph) -> RdflibSparqlBackend:
"""Returns a SPARQL backend instance for ``rdflib_graph``."""
return RdflibSparqlBackend(rdflib_graph)