diff --git a/test/jsonld/__init__.py b/test/jsonld/__init__.py index a7d8a6b02..b082da4f8 100644 --- a/test/jsonld/__init__.py +++ b/test/jsonld/__init__.py @@ -5,6 +5,5 @@ assert plugin assert serializer assert parser -import json __all__: List[str] = [] diff --git a/test/jsonld/test_api.py b/test/jsonld/test_api.py index 7879bfda6..5beab1fd9 100644 --- a/test/jsonld/test_api.py +++ b/test/jsonld/test_api.py @@ -1,11 +1,4 @@ # -*- coding: UTF-8 -*- -from rdflib.parser import Parser -from rdflib.plugin import register -from rdflib.serializer import Serializer - -register("json-ld", Parser, "rdflib.plugins.parsers.jsonld", "JsonLDParser") -register("json-ld", Serializer, "rdflib.plugins.serializers.jsonld", "JsonLDSerializer") - from rdflib import Graph, Literal, URIRef diff --git a/test/jsonld/test_named_graphs.py b/test/jsonld/test_named_graphs.py index ca25b7954..1d1bd6265 100644 --- a/test/jsonld/test_named_graphs.py +++ b/test/jsonld/test_named_graphs.py @@ -1,10 +1,5 @@ # -*- coding: UTF-8 -*- -from rdflib import * -from rdflib.parser import Parser -from rdflib.plugin import register - -register("json-ld", Parser, "rdflib.plugins.parsers.jsonld", "JsonLDParser") -register("application/ld+json", Parser, "rdflib.plugins.parsers.jsonld", "JsonLDParser") +from rdflib import ConjunctiveGraph, Dataset, Graph, URIRef data = """ { diff --git a/test/test_dataset/test_dataset.py b/test/test_dataset/test_dataset.py index 373383f7c..18c2920ee 100644 --- a/test/test_dataset/test_dataset.py +++ b/test/test_dataset/test_dataset.py @@ -105,7 +105,7 @@ def get_dataset(request): else: try: os.remove(path) - except: + except Exception: pass diff --git a/test/test_graph/test_graph_formula.py b/test/test_graph/test_graph_formula.py index 6f1092ca3..32b3aef71 100644 --- a/test/test_graph/test_graph_formula.py +++ b/test/test_graph/test_graph_formula.py @@ -115,7 +115,7 @@ def checkFormulaStore(store="default", configString=None): os.unlink(path) else: g.store.destroy(configString) - except: + except Exception: g.close() if store == "SQLite": os.unlink(path) diff --git a/test/test_issues/test_issue492.py b/test/test_issues/test_issue492.py index 713ce7aca..83d2d938f 100644 --- a/test/test_issues/test_issue492.py +++ b/test/test_issues/test_issue492.py @@ -1,7 +1,4 @@ # test for https://github.com/RDFLib/rdflib/issues/492 - -#!/usr/bin/env python3 - import rdflib diff --git a/test/test_issues/test_issue604.py b/test/test_issues/test_issue604.py index d56629434..cb5aaac99 100644 --- a/test/test_issues/test_issue604.py +++ b/test/test_issues/test_issue604.py @@ -1,4 +1,4 @@ -from rdflib import * +from rdflib import RDF, BNode, Graph, Literal, Namespace from rdflib.collection import Collection diff --git a/test/test_literal/test_term.py b/test/test_literal/test_term.py index 506f1a3f7..ca2a972f3 100644 --- a/test/test_literal/test_term.py +++ b/test/test_literal/test_term.py @@ -253,7 +253,7 @@ def isclose(a, b, rel_tol=1e-09, abs_tol=0.0): if not case_passed: try: case_passed = isclose((case[1] + case[2].value), case[3].value) - except: + except Exception: pass if not case_passed: diff --git a/test/test_misc/test_events.py b/test/test_misc/test_events.py index c2654ab0c..7e6849ae6 100644 --- a/test/test_misc/test_events.py +++ b/test/test_misc/test_events.py @@ -60,5 +60,5 @@ def testEvents(self): assert c2["bob"] == "uncle" assert c3["bob"] == "uncle" del c3["bob"] - assert ("bob" in c1) == False - assert ("bob" in c2) == False + assert ("bob" in c1) is False + assert ("bob" in c2) is False diff --git a/test/test_namespace/test_namespace.py b/test/test_namespace/test_namespace.py index cb3f26f50..3f439133c 100644 --- a/test/test_namespace/test_namespace.py +++ b/test/test_namespace/test_namespace.py @@ -284,10 +284,10 @@ def test_expand_curie_exception_messages(self) -> None: ["curie", "expected_result"], [ ("ex:tarek", URIRef("urn:example:tarek")), - ("ex:", URIRef(f"urn:example:")), - ("ex:a", URIRef(f"urn:example:a")), - ("ex:a:b", URIRef(f"urn:example:a:b")), - ("ex:a:b:c", URIRef(f"urn:example:a:b:c")), + ("ex:", URIRef("urn:example:")), + ("ex:a", URIRef("urn:example:a")), + ("ex:a:b", URIRef("urn:example:a:b")), + ("ex:a:b:c", URIRef("urn:example:a:b:c")), ("ex", ValueError), ("em:tarek", ValueError), ("em:", ValueError), diff --git a/test/test_parsers/test_parser_hext.py b/test/test_parsers/test_parser_hext.py index f4d1184ac..5f4a180b7 100644 --- a/test/test_parsers/test_parser_hext.py +++ b/test/test_parsers/test_parser_hext.py @@ -1,7 +1,5 @@ -import sys from pathlib import Path -sys.path.append(str(Path(__file__).parent.parent.absolute())) from rdflib import ConjunctiveGraph, Dataset, Literal from rdflib.namespace import XSD @@ -116,8 +114,8 @@ def test_roundtrip(): try: cg = ConjunctiveGraph().parse(f, format="nt") # print(cg.serialize(format="n3")) - except: - print(f"Skipping: could not NT parse") + except Exception: + print("Skipping: could not NT parse") skipped += 1 skip = True if not skip: diff --git a/test/test_parsers/test_swap_n3.py b/test/test_parsers/test_swap_n3.py index cebb55ad9..e173b8452 100644 --- a/test/test_parsers/test_swap_n3.py +++ b/test/test_parsers/test_swap_n3.py @@ -1,10 +1,8 @@ import os +from test.data import TEST_DATA_DIR import pytest -maketrans = str.maketrans -from test.data import TEST_DATA_DIR - import rdflib """ @@ -116,7 +114,7 @@ def get_cases(): tfiles += files for tfile in set(tfiles): gname = tfile.split("/swap-n3/swap/test/")[1][:-3].translate( - maketrans("-/", "__") + str.maketrans("-/", "__") ) e = Envelope(gname, tfile) if gname in skiptests: diff --git a/test/test_serializers/test_serializer_hext.py b/test/test_serializers/test_serializer_hext.py index cae703966..2a75cc895 100644 --- a/test/test_serializers/test_serializer_hext.py +++ b/test/test_serializers/test_serializer_hext.py @@ -1,8 +1,5 @@ -import sys -from pathlib import Path - -sys.path.append(str(Path(__file__).parent.parent.absolute())) import json +from pathlib import Path from rdflib import ConjunctiveGraph, Dataset, Graph diff --git a/test/test_sparql/test_datetime_processing.py b/test/test_sparql/test_datetime_processing.py index 8cec5cca5..9fb0901a8 100644 --- a/test/test_sparql/test_datetime_processing.py +++ b/test/test_sparql/test_datetime_processing.py @@ -86,7 +86,7 @@ def test_dateTime_duration_subs(): f = io.StringIO(data) graph.parse(f, format="n3") - ## 1st Test Case + # 1st Test Case result1 = graph.query( """ @@ -117,7 +117,7 @@ def test_dateTime_duration_subs(): eq_(list(result1)[0][0], expected[0]) eq_(list(result1)[1][0], expected[1]) - ## 2nd Test Case + # 2nd Test Case result2 = graph.query( """ @@ -165,7 +165,7 @@ def test_dateTime_duration_add(): f = io.StringIO(data) graph.parse(f, format="n3") - ## 1st Test case + # 1st Test case result1 = graph.query( """ @@ -198,7 +198,7 @@ def test_dateTime_duration_add(): eq_(list(result1)[0][0], expected[0]) eq_(list(result1)[1][0], expected[1]) - ## 2nd Test case + # 2nd Test case result2 = graph.query( """ diff --git a/test/test_store/test_store_sparqlupdatestore.py b/test/test_store/test_store_sparqlupdatestore.py index c29a6ac6c..c55b3ac62 100644 --- a/test/test_store/test_store_sparqlupdatestore.py +++ b/test/test_store/test_store_sparqlupdatestore.py @@ -28,7 +28,7 @@ try: assert len(urlopen(HOST).read()) > 0 -except: +except Exception: pytest.skip(f"{HOST} is unavailable.", allow_module_level=True) diff --git a/test/test_turtle_quoting.py b/test/test_turtle_quoting.py index bdafd0713..14d82bca2 100644 --- a/test/test_turtle_quoting.py +++ b/test/test_turtle_quoting.py @@ -5,6 +5,7 @@ import itertools import logging +import re from typing import Callable, Dict, Iterable, List, Tuple import pytest @@ -28,8 +29,6 @@ "\\": "\\", } -import re - def make_unquote_correctness_pairs() -> List[Tuple[str, str]]: """ diff --git a/test/test_typing.py b/test/test_typing.py index 7bce69840..1b9113025 100644 --- a/test/test_typing.py +++ b/test/test_typing.py @@ -129,7 +129,7 @@ def test_rdflib_query_exercise() -> None: assert python_two == 2 python_true: bool = literal_true.toPython() - assert python_true == True + assert python_true is True python_iri: str = kb_https_uriref.toPython() assert python_iri == "https://example.org/kb/y" diff --git a/test/test_util.py b/test/test_util.py index c842bc928..37d1db291 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -336,9 +336,9 @@ def test_util_from_n3_not_escapes(self, string: str) -> None: @pytest.mark.parametrize( "string", [ - (f"j\\366rn"), - (f"\\"), - (f"\\0"), + ("j\\366rn"), + ("\\"), + ("\\0"), ], ) def test_util_from_n3_not_escapes_xf(self, string: str) -> None: diff --git a/test/test_w3c_spec/test_n3_w3c.py b/test/test_w3c_spec/test_n3_w3c.py index 436e07901..61b851a70 100644 --- a/test/test_w3c_spec/test_n3_w3c.py +++ b/test/test_w3c_spec/test_n3_w3c.py @@ -55,7 +55,7 @@ def n3(test: RDFTest): res.serialize(), ) - except: + except Exception: if test.syntax: raise