From bace976579345d8c3b2da551b6d26c68a023f02e Mon Sep 17 00:00:00 2001 From: Ashley Sommer Date: Fri, 1 Nov 2024 10:19:06 +1000 Subject: [PATCH] Fix where some tests were broken due to updated typing (auto-replace mistakes) --- rdflib/plugins/serializers/n3.py | 2 +- test/test_misc/test_input_source.py | 10 +++++----- test/test_sparql/test_sparql_parser.py | 4 ++-- test/test_w3c_spec/test_nquads_w3c.py | 6 +++--- test/test_w3c_spec/test_nt_w3c.py | 6 +++--- test/test_w3c_spec/test_rdfxml_w3c.py | 6 +++--- test/test_w3c_spec/test_sparql10_w3c.py | 2 +- test/test_w3c_spec/test_sparql11_w3c.py | 2 +- test/test_w3c_spec/test_sparql_rdflib.py | 2 +- test/test_w3c_spec/test_trig_w3c.py | 6 +++--- test/test_w3c_spec/test_turtle_w3c.py | 6 +++--- test/utils/__init__.py | 10 +++++----- test/utils/dawg_manifest.py | 8 ++++---- test/utils/result.py | 8 ++++++-- test/utils/sparql_checker.py | 4 ++-- 15 files changed, 43 insertions(+), 39 deletions(-) diff --git a/rdflib/plugins/serializers/n3.py b/rdflib/plugins/serializers/n3.py index 3a7fbfe22..8c4cbab54 100644 --- a/rdflib/plugins/serializers/n3.py +++ b/rdflib/plugins/serializers/n3.py @@ -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 diff --git a/test/test_misc/test_input_source.py b/test/test_misc/test_input_source.py index dd56dddec..3673d94f7 100644 --- a/test/test_misc/test_input_source.py +++ b/test/test_misc/test_input_source.py @@ -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] @@ -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() diff --git a/test/test_sparql/test_sparql_parser.py b/test/test_sparql/test_sparql_parser.py index d2cbf3d08..d78e26b13 100644 --- a/test/test_sparql/test_sparql_parser.py +++ b/test/test_sparql/test_sparql_parser.py @@ -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))) diff --git a/test/test_w3c_spec/test_nquads_w3c.py b/test/test_w3c_spec/test_nquads_w3c.py index 255602b73..ae67213e0 100644 --- a/test/test_w3c_spec/test_nquads_w3c.py +++ b/test/test_w3c_spec/test_nquads_w3c.py @@ -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( @@ -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") diff --git a/test/test_w3c_spec/test_nt_w3c.py b/test/test_w3c_spec/test_nt_w3c.py index a37114211..263b08a53 100644 --- a/test/test_w3c_spec/test_nt_w3c.py +++ b/test/test_w3c_spec/test_nt_w3c.py @@ -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( @@ -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") diff --git a/test/test_w3c_spec/test_rdfxml_w3c.py b/test/test_w3c_spec/test_rdfxml_w3c.py index cc3974ce9..560988924 100644 --- a/test/test_w3c_spec/test_rdfxml_w3c.py +++ b/test/test_w3c_spec/test_rdfxml_w3c.py @@ -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( @@ -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() diff --git a/test/test_w3c_spec/test_sparql10_w3c.py b/test/test_w3c_spec/test_sparql10_w3c.py index 149c87008..cfbfaf74a 100644 --- a/test/test_w3c_spec/test_sparql10_w3c.py +++ b/test/test_w3c_spec/test_sparql10_w3c.py @@ -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 ), ), diff --git a/test/test_w3c_spec/test_sparql11_w3c.py b/test/test_w3c_spec/test_sparql11_w3c.py index 6daa75ea9..662283f2d 100644 --- a/test/test_w3c_spec/test_sparql11_w3c.py +++ b/test/test_w3c_spec/test_sparql11_w3c.py @@ -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 ), ), diff --git a/test/test_w3c_spec/test_sparql_rdflib.py b/test/test_w3c_spec/test_sparql_rdflib.py index 246f19579..919ac0093 100644 --- a/test/test_w3c_spec/test_sparql_rdflib.py +++ b/test/test_w3c_spec/test_sparql_rdflib.py @@ -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 ), ), diff --git a/test/test_w3c_spec/test_trig_w3c.py b/test/test_w3c_spec/test_trig_w3c.py index f3cf18ad6..faca987b0 100644 --- a/test/test_w3c_spec/test_trig_w3c.py +++ b/test/test_w3c_spec/test_trig_w3c.py @@ -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( @@ -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() diff --git a/test/test_w3c_spec/test_turtle_w3c.py b/test/test_w3c_spec/test_turtle_w3c.py index bec4754a5..490e6a1fc 100644 --- a/test/test_w3c_spec/test_turtle_w3c.py +++ b/test/test_w3c_spec/test_turtle_w3c.py @@ -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( @@ -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() diff --git a/test/utils/__init__.py b/test/utils/__init__.py index ff95f8318..1552f0af5 100644 --- a/test/utils/__init__.py +++ b/test/utils/__init__.py @@ -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 diff --git a/test/utils/dawg_manifest.py b/test/utils/dawg_manifest.py index d9b685726..f4686021f 100644 --- a/test/utils/dawg_manifest.py +++ b/test/utils/dawg_manifest.py @@ -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) diff --git a/test/utils/result.py b/test/utils/result.py index d3137e07f..c1bdb604a 100644 --- a/test/utils/result.py +++ b/test/utils/result.py @@ -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: @@ -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()} diff --git a/test/utils/sparql_checker.py b/test/utils/sparql_checker.py index 186475be6..4e1c1083e 100644 --- a/test/utils/sparql_checker.py +++ b/test/utils/sparql_checker.py @@ -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 @@ -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_}")