Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black tests #1798

Merged
merged 2 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ exclude = '''
| htmlcov
| benchmarks
| examples # No need to Black examples
| test # Tests are a mess, don't black them
| test_reports
| rdflib.egg-info
| buck-out
Expand Down
2 changes: 1 addition & 1 deletion test/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def query_with_retry(graph: rdflib.Graph, query: str, **kwargs) -> rdflib.query.
if i == MAX_RETRY - 1:
raise e

backoff_s = (BACKOFF_FACTOR ** backoff) / 10
backoff_s = (BACKOFF_FACTOR**backoff) / 10
print(
f"Network error {e} during query, waiting for {backoff_s:.2f}s and retrying"
)
Expand Down
31 changes: 24 additions & 7 deletions test/jsonld/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def _preserving_nodeid(self, bnode_context=None):
return bNode(self.eat(r_nodeid).group(1))




DEFAULT_PARSER_VERSION = 1.0


Expand All @@ -46,7 +44,9 @@ def make_fake_urlinputsource(input_uri, format=None, suite_base=None, options={}
source.content_type = options['contentType']
if "redirectTo" in options:
redir = suite_base + options['redirectTo']
local_redirect = redir.replace("https://w3c.github.io/json-ld-api/tests/", "./")
local_redirect = redir.replace(
"https://w3c.github.io/json-ld-api/tests/", "./"
)
if f:
f.close()
try:
Expand All @@ -59,13 +59,22 @@ def make_fake_urlinputsource(input_uri, format=None, suite_base=None, options={}
source.setSystemId(redir)
return source


def do_test_json(suite_base, cat, num, inputpath, expectedpath, context, options):
input_uri = suite_base + inputpath
input_graph = ConjunctiveGraph()
if cat == "remote-doc":
input_src = make_fake_urlinputsource(input_uri, format="json-ld", suite_base=suite_base, options=options)
input_src = make_fake_urlinputsource(
input_uri, format="json-ld", suite_base=suite_base, options=options
)
p = JsonLDParser()
p.parse(input_src, input_graph, base=input_src.getPublicId(), context_data=context, generalized_rdf=True)
p.parse(
input_src,
input_graph,
base=input_src.getPublicId(),
context_data=context,
generalized_rdf=True,
)
else:
input_obj = _load_json(inputpath)
to_rdf(
Expand Down Expand Up @@ -118,9 +127,17 @@ def do_test_parser(suite_base, cat, num, inputpath, expectedpath, context, optio
elif requested_version == "json-ld-1.0":
version = 1.0
if cat == "remote-doc":
input_src = make_fake_urlinputsource(input_uri, format="json-ld", options=options)
input_src = make_fake_urlinputsource(
input_uri, format="json-ld", options=options
)
p = JsonLDParser()
p.parse(input_src, result_graph, base=input_uri, context_data=context, generalized_rdf=True)
p.parse(
input_src,
result_graph,
base=input_uri,
context_data=context,
generalized_rdf=True,
)
else:
to_rdf(
input_obj,
Expand Down
16 changes: 12 additions & 4 deletions test/jsonld/test_localsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ def get_test_suite_cases():
func = runner.do_test_parser
else: # fromRdf
func = runner.do_test_serializer
rdf_test_uri = URIRef("{0}{1}-manifest.jsonld#t{2}".format(
TC_BASE, cat, num
))
rdf_test_uri = URIRef("{0}{1}-manifest.jsonld#t{2}".format(TC_BASE, cat, num))
yield rdf_test_uri, func, TC_BASE, cat, num, inputpath, expectedpath, context, options


Expand All @@ -55,5 +53,15 @@ def testsuide_dir():
"rdf_test_uri, func, suite_base, cat, num, inputpath, expectedpath, context, options",
get_test_suite_cases(),
)
def test_suite(rdf_test_uri: URIRef, func, suite_base, cat, num, inputpath, expectedpath, context, options):
def test_suite(
rdf_test_uri: URIRef,
func,
suite_base,
cat,
num,
inputpath,
expectedpath,
context,
options,
):
func(suite_base, cat, num, inputpath, expectedpath, context, options)
22 changes: 14 additions & 8 deletions test/jsonld/test_onedotone.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@

if os.name == "nt":
# nquad parser does not correctly handle unnormalized unicode on windows.
known_bugs += ("toRdf/js11-in", )
known_bugs += ("toRdf/js11-in",)

TC_BASE = "https://w3c.github.io/json-ld-api/tests/"
allow_lists_of_lists = True
Expand Down Expand Up @@ -203,9 +203,7 @@ def get_test_suite_cases():
if SKIP_KNOWN_BUGS:
skiptests += known_bugs

for cat, num, inputpath, expectedpath, context, options in read_manifest(
skiptests
):
for cat, num, inputpath, expectedpath, context, options in read_manifest(skiptests):
if options:
if (
SKIP_1_0_TESTS
Expand All @@ -221,9 +219,7 @@ def get_test_suite_cases():
func = runner.do_test_parser
else: # fromRdf
func = runner.do_test_serializer
rdf_test_uri = URIRef("{0}{1}-manifest#t{2}".format(
TC_BASE, cat, num
))
rdf_test_uri = URIRef("{0}{1}-manifest#t{2}".format(TC_BASE, cat, num))
yield rdf_test_uri, func, TC_BASE, cat, num, inputpath, expectedpath, context, options


Expand All @@ -239,5 +235,15 @@ def global_state():
"rdf_test_uri, func, suite_base, cat, num, inputpath, expectedpath, context, options",
get_test_suite_cases(),
)
def test_suite(rdf_test_uri: URIRef, func, suite_base, cat, num, inputpath, expectedpath, context, options):
def test_suite(
rdf_test_uri: URIRef,
func,
suite_base,
cat,
num,
inputpath,
expectedpath,
context,
options,
):
func(suite_base, cat, num, inputpath, expectedpath, context, options)
20 changes: 13 additions & 7 deletions test/jsonld/test_testsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ def get_test_suite_cases(skip_known_bugs=True):
skiptests = unsupported_tests
if skip_known_bugs:
skiptests += known_bugs
for cat, num, inputpath, expectedpath, context, options in read_manifest(
skiptests
):
for cat, num, inputpath, expectedpath, context, options in read_manifest(skiptests):
if inputpath.endswith(".jsonld"): # toRdf
if expectedpath.endswith(".jsonld"): # compact/expand/flatten
func = runner.do_test_json
Expand All @@ -93,9 +91,7 @@ def get_test_suite_cases(skip_known_bugs=True):
else: # fromRdf
func = runner.do_test_serializer
# func.description = "%s-%s-%s" % (group, case)
rdf_test_uri = URIRef("{0}{1}-manifest.jsonld#t{2}".format(
TC_BASE, cat, num
))
rdf_test_uri = URIRef("{0}{1}-manifest.jsonld#t{2}".format(TC_BASE, cat, num))
yield rdf_test_uri, func, TC_BASE, cat, num, inputpath, expectedpath, context, options


Expand All @@ -117,5 +113,15 @@ def global_state():
"rdf_test_uri, func, suite_base, cat, num, inputpath, expectedpath, context, options",
get_test_suite_cases(),
)
def test_suite(rdf_test_uri: URIRef, func, suite_base, cat, num, inputpath, expectedpath, context, options):
def test_suite(
rdf_test_uri: URIRef,
func,
suite_base,
cat,
num,
inputpath,
expectedpath,
context,
options,
):
func(suite_base, cat, num, inputpath, expectedpath, context, options)
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ def namespace(cls) -> "Namespace":
def constant_output(cls) -> Set[Tuple["Identifier", "Identifier", "Identifier"]]:
return {(cls.namespace().subj, cls.namespace().pred, cls.namespace().obj)}


from rdflib.namespace import Namespace
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@


timblcardn3 = open(
os.path.join(os.path.dirname(__file__), "..", "consistent_test_data", "timbl-card.n3")
os.path.join(
os.path.dirname(__file__), "..", "consistent_test_data", "timbl-card.n3"
)
).read()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
c2 = URIRef("urn:example:context-2")

sportquadstrig = open(
os.path.join(os.path.dirname(__file__), "..", "consistent_test_data", "sportquads.trig")
os.path.join(
os.path.dirname(__file__), "..", "consistent_test_data", "sportquads.trig"
)
).read()


Expand Down
28 changes: 23 additions & 5 deletions test/test_definednamespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ def test_definednamespace_creator_qb():
Tests basic use of DefinedNamespace creator script using QB
"""

definednamespace_script = Path(__file__).parent.parent / "rdflib" / "tools" / "defined_namespace_creator.py"
definednamespace_script = (
Path(__file__).parent.parent
/ "rdflib"
/ "tools"
/ "defined_namespace_creator.py"
)
qb_data_file = Path(__file__).parent / "defined_namespaces" / "qb.ttl"
print("\n")
print(f"Using {definednamespace_script}...")
Expand All @@ -35,7 +40,10 @@ def test_definednamespace_creator_qb():
for line in f.readlines():
if '_NS = Namespace("http://purl.org/linked-data/cube#")' in line:
has_ns = True
if 'Attachable: URIRef # Abstract superclass for everything that can have attributes and dimensions' in line:
if (
'Attachable: URIRef # Abstract superclass for everything that can have attributes and dimensions'
in line
):
has_test_class = True
assert has_ns, "_QB.py does not contain _NS"
assert has_test_class, "_QB.py does not class Attachable"
Expand All @@ -50,7 +58,12 @@ def test_definednamespace_creator_fake():
RDF file of unknonwn type
"""

definednamespace_script = Path(__file__).parent.parent / "rdflib" / "tools" / "defined_namespace_creator.py"
definednamespace_script = (
Path(__file__).parent.parent
/ "rdflib"
/ "tools"
/ "defined_namespace_creator.py"
)
qb_data_file = Path(__file__).parent / "defined_namespaces" / "fake.xxx"
print("\n")
print(f"Using {definednamespace_script}...")
Expand All @@ -76,7 +89,12 @@ def test_definednamespace_creator_bad_ns():
supplied namespace doesn't end in # or /
"""

definednamespace_script = Path(__file__).parent.parent / "rdflib" / "tools" / "defined_namespace_creator.py"
definednamespace_script = (
Path(__file__).parent.parent
/ "rdflib"
/ "tools"
/ "defined_namespace_creator.py"
)
qb_data_file = Path(__file__).parent / "defined_namespaces" / "fake.xxx"
print("\n")
print(f"Using {definednamespace_script}...")
Expand Down Expand Up @@ -165,7 +183,7 @@ def test_definednamespace_jsonld_context():
"Collection": "skos:Collection",
"Concept": "skos:Concept",
"ConceptScheme": "skos:ConceptScheme",
"OrderedCollection": "skos:OrderedCollection"
"OrderedCollection": "skos:OrderedCollection",
}
}
actual = SKOS.as_jsonld_context("skos")
Expand Down
1 change: 1 addition & 0 deletions test/test_extras_external_graph_libs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from rdflib import Graph, URIRef, Literal
import pytest


def test_rdflib_to_networkx():
try:
import networkx
Expand Down
1 change: 1 addition & 0 deletions test/test_graph/test_graph_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pytest
from rdflib import Graph, ConjunctiveGraph, URIRef, BNode, plugin


class ContextTestCase(unittest.TestCase):
store = "default"
slow = True
Expand Down
1 change: 1 addition & 0 deletions test/test_graph/test_graph_formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def get_formula_stores_tests():
continue
yield checkFormulaStore, s.name


@pytest.mark.parametrize("checker, name", get_formula_stores_tests())
def test_formula_stores(checker, name) -> None:
checker(name)
4 changes: 1 addition & 3 deletions test/test_graph/test_graph_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
)


timblcardn3 = open(
os.path.join(CONSISTENT_DATA_DIR, "timbl-card.n3")
).read()
timblcardn3 = open(os.path.join(CONSISTENT_DATA_DIR, "timbl-card.n3")).read()


def add_stuff(graph):
Expand Down
7 changes: 6 additions & 1 deletion test/test_graph/test_graph_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

from http.server import BaseHTTPRequestHandler
from urllib.error import HTTPError
from test.testutils import SimpleHTTPMock, MockHTTPResponse, ctx_http_server, GraphHelper
from test.testutils import (
SimpleHTTPMock,
MockHTTPResponse,
ctx_http_server,
GraphHelper,
)
import unittest


Expand Down
12 changes: 6 additions & 6 deletions test/test_graph/test_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from test.data import tarek, likes, pizza, cheese, michel, bob, hates


class TestGraphSlice():
class TestGraphSlice:
def test_slice(self):
"""
We pervert the slice object,
Expand Down Expand Up @@ -34,19 +34,19 @@ def soe(x, y):

# single slice slices by s,p,o, with : used to split
# tell me everything about "tarek" (same as above)
sl(g[tarek : :], 2)
sl(g[tarek::], 2)

# give me every "likes" relationship
sl(g[: likes :], 5)
sl(g[:likes:], 5)

# give me every relationship to pizza
sl(g[:: pizza], 3)
sl(g[::pizza], 3)

# give me everyone who likes pizza
sl(g[: likes : pizza], 2)
sl(g[:likes:pizza], 2)

# does tarek like pizza?
assert g[tarek : likes : pizza] is True
assert g[tarek:likes:pizza] is True

# More intesting is using paths

Expand Down
10 changes: 8 additions & 2 deletions test/test_graph/test_variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ class GraphAsserts:
quad_count: Optional[int] = None
exact_match: bool = False

def check(self, first_graph: Optional[ConjunctiveGraph], graph: ConjunctiveGraph) -> None:
def check(
self, first_graph: Optional[ConjunctiveGraph], graph: ConjunctiveGraph
) -> None:
if self.quad_count is not None:
assert self.quad_count == len(list(graph.quads()))
if first_graph is not None and self.exact_match:
Expand Down Expand Up @@ -209,4 +211,8 @@ def test_variants(graph_variant: GraphVariants) -> None:
first_path = variant_path
else:
assert first_path is not None
GraphHelper.assert_isomorphic(first_graph, graph, f"checking {variant_path.relative_to(VARIANTS_DIR)} against {first_path.relative_to(VARIANTS_DIR)}")
GraphHelper.assert_isomorphic(
first_graph,
graph,
f"checking {variant_path.relative_to(VARIANTS_DIR)} against {first_path.relative_to(VARIANTS_DIR)}",
)