Skip to content

Commit

Permalink
test: Eliminate flake8 errors in tests
Browse files Browse the repository at this point in the history
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](flakeheaven/flakeheaven#132)].
  • Loading branch information
aucampia committed Apr 12, 2023
1 parent 4ea1436 commit 2f93018
Show file tree
Hide file tree
Showing 19 changed files with 27 additions and 51 deletions.
1 change: 0 additions & 1 deletion test/jsonld/__init__.py
Expand Up @@ -5,6 +5,5 @@
assert plugin
assert serializer
assert parser
import json

__all__: List[str] = []
7 changes: 0 additions & 7 deletions 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


Expand Down
7 changes: 1 addition & 6 deletions 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 = """
{
Expand Down
2 changes: 1 addition & 1 deletion test/test_dataset/test_dataset.py
Expand Up @@ -105,7 +105,7 @@ def get_dataset(request):
else:
try:
os.remove(path)
except:
except Exception:
pass


Expand Down
2 changes: 1 addition & 1 deletion test/test_graph/test_graph_formula.py
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions 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


Expand Down
2 changes: 1 addition & 1 deletion 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


Expand Down
2 changes: 1 addition & 1 deletion test/test_literal/test_term.py
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions test/test_misc/test_events.py
Expand Up @@ -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
8 changes: 4 additions & 4 deletions test/test_namespace/test_namespace.py
Expand Up @@ -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),
Expand Down
6 changes: 2 additions & 4 deletions 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

Expand Down Expand Up @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions 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

"""
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions 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

Expand Down
8 changes: 4 additions & 4 deletions test/test_sparql/test_datetime_processing.py
Expand Up @@ -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(
"""
Expand Down Expand Up @@ -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(
"""
Expand Down Expand Up @@ -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(
"""
Expand Down Expand Up @@ -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(
"""
Expand Down
2 changes: 1 addition & 1 deletion test/test_store/test_store_sparqlupdatestore.py
Expand Up @@ -28,7 +28,7 @@

try:
assert len(urlopen(HOST).read()) > 0
except:
except Exception:
pytest.skip(f"{HOST} is unavailable.", allow_module_level=True)


Expand Down
3 changes: 1 addition & 2 deletions test/test_turtle_quoting.py
Expand Up @@ -5,6 +5,7 @@

import itertools
import logging
import re
from typing import Callable, Dict, Iterable, List, Tuple

import pytest
Expand All @@ -28,8 +29,6 @@
"\\": "\\",
}

import re


def make_unquote_correctness_pairs() -> List[Tuple[str, str]]:
"""
Expand Down
2 changes: 1 addition & 1 deletion test/test_typing.py
Expand Up @@ -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"
6 changes: 3 additions & 3 deletions test/test_util.py
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion test/test_w3c_spec/test_n3_w3c.py
Expand Up @@ -55,7 +55,7 @@ def n3(test: RDFTest):
res.serialize(),
)

except:
except Exception:
if test.syntax:
raise

Expand Down

0 comments on commit 2f93018

Please sign in to comment.