Skip to content

Commit

Permalink
Fix where some tests were broken due to updated typing (auto-replace …
Browse files Browse the repository at this point in the history
…mistakes)
  • Loading branch information
ashleysommer committed Nov 1, 2024
1 parent ad32b23 commit bace976
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 39 deletions.
2 changes: 1 addition & 1 deletion rdflib/plugins/serializers/n3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Notation 3 (N3) RDF graph serializer for RDFLib.
"""

from typing import TYPE_CHECKING, cast
from typing import cast

from rdflib.graph import Graph, QuotedGraph
from rdflib.namespace import OWL, Namespace
Expand Down
10 changes: 5 additions & 5 deletions test/test_misc/test_input_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class InputSourceChecker:
:param encoding: Expected encoding of input source. If ``None``, then the encoding is not checked. If it has a value (i.e. an instance of :class:`Holder`), then the encoding is expected to match ``encoding.value``.
"""

type: type[InputSource]
type_: type[InputSource]
stream_check: StreamCheck
encoding: Optional[Holder[Optional[str]]]
public_id: Optional[str]
Expand All @@ -288,14 +288,14 @@ def check(
Check that ``input_source`` matches expectations.
"""
logging.debug(
"input_source = %s / %s, self.type = %s",
"input_source = %s / %s, self.type_ = %s",
type(input_source),
input_source,
self.type,
self.type_,
)
assert isinstance(input_source, InputSource)
if self.type is not None:
assert isinstance(input_source, self.type)
if self.type_ is not None:
assert isinstance(input_source, self.type_)

if self.stream_check is StreamCheck.BYTE:
binary_io: BinaryIO = input_source.getByteStream()
Expand Down
4 changes: 2 additions & 2 deletions test/test_sparql/test_sparql_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import math
import sys

from rdflib import Graph, Literal
from rdflib import Graph, Literal, Variable
from rdflib.namespace import Namespace
from rdflib.plugins.sparql.processor import processUpdate
from rdflib.term import IdentifiedNode, Node


def triple_set(graph: Graph) -> set[tuple[Node, IdentifiedNode, Node]]:
def triple_set(graph: Graph) -> set[tuple[Node, IdentifiedNode | Variable, Node]]:
return set(graph.triples((None, None, None)))


Expand Down
6 changes: 3 additions & 3 deletions test/test_w3c_spec/test_nquads_w3c.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

def check_entry(entry: ManifestEntry) -> None:
assert entry.action is not None
assert entry.type in VALID_TYPES
assert entry.type_ in VALID_TYPES
action_path = entry.uri_mapper.to_local_path(entry.action)
if logger.isEnabledFor(logging.DEBUG):
logger.debug(
Expand All @@ -38,13 +38,13 @@ def check_entry(entry: ManifestEntry) -> None:
catcher: Optional[pytest.ExceptionInfo[Exception]] = None
dataset = Dataset()
with ExitStack() as xstack:
if entry.type == RDFT.TestNQuadsNegativeSyntax:
if entry.type_ == RDFT.TestNQuadsNegativeSyntax:
catcher = xstack.enter_context(pytest.raises(Exception))
dataset.parse(action_path, publicID=entry.action, format="nquads")
if catcher is not None:
assert catcher.value is not None

if entry.type == RDFT.TestNQuadsPositiveSyntax:
if entry.type_ == RDFT.TestNQuadsPositiveSyntax:
graph_data = dataset.serialize(format="nquads")
result_dataset = Dataset()
result_dataset.parse(data=graph_data, publicID=entry.action, format="nquads")
Expand Down
6 changes: 3 additions & 3 deletions test/test_w3c_spec/test_nt_w3c.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

def check_entry(entry: ManifestEntry) -> None:
assert entry.action is not None
assert entry.type in VALID_TYPES
assert entry.type_ in VALID_TYPES
action_path = entry.uri_mapper.to_local_path(entry.action)
if logger.isEnabledFor(logging.DEBUG):
logger.debug(
Expand All @@ -38,13 +38,13 @@ def check_entry(entry: ManifestEntry) -> None:
catcher: Optional[pytest.ExceptionInfo[Exception]] = None
graph = Graph()
with ExitStack() as xstack:
if entry.type == RDFT.TestNTriplesNegativeSyntax:
if entry.type_ == RDFT.TestNTriplesNegativeSyntax:
catcher = xstack.enter_context(pytest.raises(Exception))
graph.parse(action_path, publicID=entry.action, format="ntriples")
if catcher is not None:
assert catcher.value is not None

if entry.type == RDFT.TestNTriplesPositiveSyntax:
if entry.type_ == RDFT.TestNTriplesPositiveSyntax:
graph_data = graph.serialize(format="ntriples")
result_graph = Graph()
result_graph.parse(data=graph_data, publicID=entry.action, format="ntriples")
Expand Down
6 changes: 3 additions & 3 deletions test/test_w3c_spec/test_rdfxml_w3c.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

def check_entry(entry: ManifestEntry) -> None:
assert entry.action is not None
assert entry.type in VALID_TYPES
assert entry.type_ in VALID_TYPES
action_path = entry.uri_mapper.to_local_path(entry.action)
if logger.isEnabledFor(logging.DEBUG):
logger.debug(
Expand All @@ -35,14 +35,14 @@ def check_entry(entry: ManifestEntry) -> None:
catcher: Optional[pytest.ExceptionInfo[Exception]] = None
graph = Graph()
with ExitStack() as xstack:
if entry.type == RDFT.TestXMLNegativeSyntax:
if entry.type_ == RDFT.TestXMLNegativeSyntax:
catcher = xstack.enter_context(pytest.raises(Exception))
graph.parse(action_path, publicID=entry.action, format="xml")

if catcher is not None:
assert catcher.value is not None

if entry.type == RDFT.TestXMLEval:
if entry.type_ == RDFT.TestXMLEval:
assert entry.result is not None
result_source = entry.uri_mapper.to_local_path(entry.result)
result_graph = Graph()
Expand Down
2 changes: 1 addition & 1 deletion test/test_w3c_spec/test_sparql10_w3c.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def configure_rdflib() -> Generator[None, None, None]:
markers=(
lambda entry: (
pytest.mark.skip(reason="tester not implemented")
if entry.type in SKIP_TYPES
if entry.type_ in SKIP_TYPES
else None
),
),
Expand Down
2 changes: 1 addition & 1 deletion test/test_w3c_spec/test_sparql11_w3c.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def configure_rdflib() -> Generator[None, None, None]:
markers=(
lambda entry: (
pytest.mark.skip(reason="tester not implemented")
if entry.type in SKIP_TYPES
if entry.type_ in SKIP_TYPES
else None
),
),
Expand Down
2 changes: 1 addition & 1 deletion test/test_w3c_spec/test_sparql_rdflib.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def configure_rdflib() -> Generator[None, None, None]:
markers=(
lambda entry: (
pytest.mark.skip(reason="tester not implemented")
if entry.type in SKIP_TYPES
if entry.type_ in SKIP_TYPES
else None
),
),
Expand Down
6 changes: 3 additions & 3 deletions test/test_w3c_spec/test_trig_w3c.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

def check_entry(entry: ManifestEntry) -> None:
assert entry.action is not None
assert entry.type in VALID_TYPES
assert entry.type_ in VALID_TYPES
action_path = entry.uri_mapper.to_local_path(entry.action)
if logger.isEnabledFor(logging.DEBUG):
logger.debug(
Expand All @@ -49,14 +49,14 @@ def check_entry(entry: ManifestEntry) -> None:
catcher: Optional[pytest.ExceptionInfo[Exception]] = None
dataset = Dataset()
with ExitStack() as xstack:
if entry.type in (RDFT.TestTrigNegativeSyntax, RDFT.TestTrigNegativeEval):
if entry.type_ in (RDFT.TestTrigNegativeSyntax, RDFT.TestTrigNegativeEval):
catcher = xstack.enter_context(pytest.raises(Exception))
dataset.parse(action_path, publicID=entry.action, format="trig")

if catcher is not None:
assert catcher.value is not None

if entry.type == RDFT.TestTrigEval:
if entry.type_ == RDFT.TestTrigEval:
assert entry.result is not None
result_source = entry.uri_mapper.to_local_path(entry.result)
result_dataset = Dataset()
Expand Down
6 changes: 3 additions & 3 deletions test/test_w3c_spec/test_turtle_w3c.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

def check_entry(entry: ManifestEntry) -> None:
assert entry.action is not None
assert entry.type in VALID_TYPES
assert entry.type_ in VALID_TYPES
action_path = entry.uri_mapper.to_local_path(entry.action)
if logger.isEnabledFor(logging.DEBUG):
logger.debug(
Expand All @@ -48,14 +48,14 @@ def check_entry(entry: ManifestEntry) -> None:
catcher: Optional[pytest.ExceptionInfo[Exception]] = None
graph = Graph()
with ExitStack() as xstack:
if entry.type in (RDFT.TestTurtleNegativeSyntax, RDFT.TestTurtleNegativeEval):
if entry.type_ in (RDFT.TestTurtleNegativeSyntax, RDFT.TestTurtleNegativeEval):
catcher = xstack.enter_context(pytest.raises(Exception))
graph.parse(action_path, publicID=entry.action, format="turtle")

if catcher is not None:
assert catcher.value is not None

if entry.type == RDFT.TestTurtleEval:
if entry.type_ == RDFT.TestTurtleEval:
assert entry.result is not None
result_source = entry.uri_mapper.to_local_path(entry.result)
result_graph = Graph()
Expand Down
10 changes: 5 additions & 5 deletions test/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@


def get_unique_plugins(
type: type[PluginT],
type_: type[PluginT],
) -> dict[type[PluginT], set[Plugin[PluginT]]]:
result: dict[type[PluginT], set[Plugin[PluginT]]] = {}
for plugin in rdflib.plugin.plugins(None, type):
for plugin in rdflib.plugin.plugins(None, type_):
cls = plugin.getClass()
plugins = result.setdefault(cls, set())
plugins.add(plugin)
return result


def get_unique_plugin_names(type: type[PluginT]) -> set[str]:
def get_unique_plugin_names(type_: type[PluginT]) -> set[str]:
result: set[str] = set()
unique_plugins = get_unique_plugins(type)
for type, plugin_set in unique_plugins.items():
unique_plugins = get_unique_plugins(type_)
for type_, plugin_set in unique_plugins.items():
result.add(next(iter(plugin_set)).name)
return result

Expand Down
8 changes: 4 additions & 4 deletions test/utils/dawg_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
class ManifestEntry:
manifest: Manifest
identifier: URIRef
type: IdentifiedNode = field(init=False)
type_: IdentifiedNode = field(init=False)
action: Optional[IdentifiedNode] = field(init=False)
result: Optional[IdentifiedNode] = field(init=False)
result_cardinality: Optional[URIRef] = field(init=False)

def __post_init__(self) -> None:
type = self.value(RDF.type, IdentifiedNode)
assert type is not None
self.type = type
type_ = self.value(RDF.type, IdentifiedNode)
assert type_ is not None
self.type_ = type_

self.action = self.value(MF.action, IdentifiedNode)
self.result = self.value(MF.result, IdentifiedNode)
Expand Down
8 changes: 6 additions & 2 deletions test/utils/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
from functools import lru_cache
from typing import Optional, Union

from typing_extensions import TypeAlias

from rdflib.term import BNode, Identifier, Literal, Variable

builtin_set: TypeAlias = set

logger = logging.getLogger(__name__)

try:
Expand Down Expand Up @@ -261,12 +265,12 @@ def info(self) -> ResultFormatInfo:

@classmethod
@lru_cache(maxsize=None)
def set(cls) -> set[ResultFormat]:
def set(cls) -> builtin_set[ResultFormat]:
return set(cls)

@classmethod
@lru_cache(maxsize=None)
def info_set(cls) -> set[ResultFormatInfo]:
def info_set(cls) -> builtin_set[ResultFormatInfo]:
return {format.info for format in cls.set()}


Expand Down
4 changes: 2 additions & 2 deletions test/utils/sparql_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class SPARQLEntry(ManifestEntry):

def __post_init__(self) -> None:
super().__post_init__()
self.type_info = type_info_dict[self.type]
self.type_info = type_info_dict[self.type_]

if self.type_info.syntax is True:
assert self.result is None
Expand Down Expand Up @@ -430,4 +430,4 @@ def check_entry(
return check_update(monkeypatch, entry)
elif entry.type_info.query_type is QueryType.QUERY:
return check_query(exit_stack, entry)
raise ValueError(f"unsupported test {entry.type}")
raise ValueError(f"unsupported test {entry.type_}")

0 comments on commit bace976

Please sign in to comment.