summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIwan Aucamp <aucampia@gmail.com>2023-04-14 21:26:10 +0200
committerGitHub <noreply@github.com>2023-04-14 21:26:10 +0200
commitcbd61510ec581aee262bc2bb8ad95d94f7784842 (patch)
treeabd7f64b89dd3b4bed049af8a157e860396faf31
parent4ea14367ffa2c05e5c288842982dcc3cdd194dd6 (diff)
downloadrdflib-cbd61510ec581aee262bc2bb8ad95d94f7784842.tar.gz
test: Eliminate flake8 errors in tests (#2353)
Eliminate some occurrences of the following flake8 errors in tests: * E265 block comment should start with '# ' * E266 too many leading '#' for block comment * E402 module level import not at top of file * E712 comparison to False should be 'if cond is False:' or 'if not cond:' * E712 comparison to True should be 'if cond is True:' or 'if cond:' * E722 do not use bare 'except' * F401 ... imported but unused * F403 ... used; unable to detect undefined names * F405 ... may be undefined, or defined from star imports: ... * F541 f-string is missing placeholders * F841 local variable 'result' is assigned to but never used * N806 variable 'TEST_DIR' in function should be lowercase This is pursuant to eliminating [flakeheaven](https://github.com/flakeheaven/flakeheaven), as it no longer supports the latest version of flake8 [[ref](https://github.com/flakeheaven/flakeheaven/issues/132)].
-rw-r--r--test/jsonld/__init__.py1
-rw-r--r--test/jsonld/test_api.py7
-rw-r--r--test/jsonld/test_named_graphs.py7
-rw-r--r--test/test_dataset/test_dataset.py2
-rw-r--r--test/test_graph/test_graph_formula.py2
-rw-r--r--test/test_issues/test_issue492.py3
-rw-r--r--test/test_issues/test_issue604.py2
-rw-r--r--test/test_literal/test_term.py2
-rw-r--r--test/test_misc/test_events.py4
-rw-r--r--test/test_namespace/test_namespace.py8
-rw-r--r--test/test_parsers/test_parser_hext.py6
-rw-r--r--test/test_parsers/test_swap_n3.py6
-rw-r--r--test/test_serializers/test_serializer_hext.py5
-rw-r--r--test/test_sparql/test_datetime_processing.py8
-rw-r--r--test/test_store/test_store_sparqlupdatestore.py2
-rw-r--r--test/test_turtle_quoting.py3
-rw-r--r--test/test_typing.py2
-rw-r--r--test/test_util.py6
-rw-r--r--test/test_w3c_spec/test_n3_w3c.py2
19 files changed, 27 insertions, 51 deletions
diff --git a/test/jsonld/__init__.py b/test/jsonld/__init__.py
index a7d8a6b0..b082da4f 100644
--- a/test/jsonld/__init__.py
+++ b/test/jsonld/__init__.py
@@ -5,6 +5,5 @@ from rdflib import parser, plugin, serializer
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 7879bfda..5beab1fd 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 ca25b795..1d1bd626 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 373383f7..18c2920e 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 6f1092ca..32b3aef7 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 713ce7ac..83d2d938 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 d5662943..cb5aaac9 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 506f1a3f..ca2a972f 100644
--- a/test/test_literal/test_term.py
+++ b/test/test_literal/test_term.py
@@ -253,7 +253,7 @@ class TestLiteral:
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 c2654ab0..7e6849ae 100644
--- a/test/test_misc/test_events.py
+++ b/test/test_misc/test_events.py
@@ -60,5 +60,5 @@ class TestEvent:
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 cb3f26f5..3f439133 100644
--- a/test/test_namespace/test_namespace.py
+++ b/test/test_namespace/test_namespace.py
@@ -284,10 +284,10 @@ class TestNamespacePrefix:
["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 f4d1184a..5f4a180b 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 cebb55ad..e173b845 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 cae70396..2a75cc89 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 8cec5cca..9fb0901a 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 c29a6ac6..c55b3ac6 100644
--- a/test/test_store/test_store_sparqlupdatestore.py
+++ b/test/test_store/test_store_sparqlupdatestore.py
@@ -28,7 +28,7 @@ othergraphuri = URIRef("urn:example:othergraph")
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 bdafd071..14d82bca 100644
--- a/test/test_turtle_quoting.py
+++ b/test/test_turtle_quoting.py
@@ -5,6 +5,7 @@ formats that are related to turtle, such as ntriples, nquads, trig and n3.
import itertools
import logging
+import re
from typing import Callable, Dict, Iterable, List, Tuple
import pytest
@@ -28,8 +29,6 @@ string_escape_map = {
"\\": "\\",
}
-import re
-
def make_unquote_correctness_pairs() -> List[Tuple[str, str]]:
"""
diff --git a/test/test_typing.py b/test/test_typing.py
index 7bce6984..1b911302 100644
--- a/test/test_typing.py
+++ b/test/test_typing.py
@@ -129,7 +129,7 @@ WHERE {
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 c842bc92..37d1db29 100644
--- a/test/test_util.py
+++ b/test/test_util.py
@@ -336,9 +336,9 @@ class TestUtilTermConvert:
@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 436e0790..61b851a7 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