From 28701db69890f283355a30ef37c8b95a5431e60a Mon Sep 17 00:00:00 2001 From: Iwan Aucamp Date: Sat, 9 Apr 2022 15:43:36 +0200 Subject: [PATCH 1/2] Black tests This changes black config to not exclude tests, once we are ready to merge this we can use pre-commit.ci autofix to actually apply black, thereby not having to worry if something more slipped in. --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8341c9c69..a1feb7dd9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 From 30e6e27eaf1a62ac9db853a971e603c6b9c6b22e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 14 Apr 2022 17:24:50 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- test/helper.py | 2 +- test/jsonld/runner.py | 31 ++- test/jsonld/test_localsuite.py | 16 +- test/jsonld/test_onedotone.py | 22 +- test/jsonld/test_testsuite.py | 20 +- .../example/rdflib/plugin/parser/__init__.py | 1 + .../test_conjunctivegraph_generators.py | 4 +- ..._conjunctivegraph_operator_combinations.py | 4 +- test/test_definednamespace.py | 28 +- test/test_extras_external_graph_libs.py | 1 + test/test_graph/test_graph_context.py | 1 + test/test_graph/test_graph_formula.py | 1 + test/test_graph/test_graph_generators.py | 4 +- test/test_graph/test_graph_http.py | 7 +- test/test_graph/test_slice.py | 12 +- test/test_graph/test_variants.py | 10 +- test/test_infixowl.py | 3 +- test/test_issues/test_issue1404.py | 5 +- test/test_issues/test_issue1484.py | 4 +- test/test_literal/test_normalized_string.py | 1 - test/test_literal/test_term.py | 1 + test/test_literal/test_tokendatatype.py | 1 - test/test_misc/test_b64_binary.py | 1 - test/test_misc/test_create_input_source.py | 1 - .../test_misc/test_parse_file_guess_format.py | 1 - test/test_misc/test_prefix_types.py | 7 +- .../test_definednamespace_creator.py | 26 +- test/test_parsers/test_empty_xml_base.py | 9 +- test/test_parsers/test_parser_hext.py | 23 +- test/test_rdfxml.py | 2 +- test/test_serializers/test_serializer_hext.py | 243 ++++++++++++++---- test/test_sparql/test_construct_bindings.py | 1 + test/test_sparql/test_evaluate_bind.py | 1 + test/test_sparql/test_operators.py | 1 + test/test_sparql/test_prepare.py | 4 +- test/test_sparql/test_sparql.py | 78 +++--- test/test_tools/test_csv2rdf.py | 1 + test/test_typing.py | 4 +- test/testutils.py | 13 +- 39 files changed, 417 insertions(+), 178 deletions(-) diff --git a/test/helper.py b/test/helper.py index 21c61bbe3..ef4a23144 100644 --- a/test/helper.py +++ b/test/helper.py @@ -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" ) diff --git a/test/jsonld/runner.py b/test/jsonld/runner.py index 651e6e73d..1f84f7fe0 100644 --- a/test/jsonld/runner.py +++ b/test/jsonld/runner.py @@ -18,8 +18,6 @@ def _preserving_nodeid(self, bnode_context=None): return bNode(self.eat(r_nodeid).group(1)) - - DEFAULT_PARSER_VERSION = 1.0 @@ -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: @@ -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( @@ -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, diff --git a/test/jsonld/test_localsuite.py b/test/jsonld/test_localsuite.py index fd51586af..820b44f97 100644 --- a/test/jsonld/test_localsuite.py +++ b/test/jsonld/test_localsuite.py @@ -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 @@ -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) diff --git a/test/jsonld/test_onedotone.py b/test/jsonld/test_onedotone.py index 0fb21e736..698c65ee5 100644 --- a/test/jsonld/test_onedotone.py +++ b/test/jsonld/test_onedotone.py @@ -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 @@ -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 @@ -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 @@ -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) diff --git a/test/jsonld/test_testsuite.py b/test/jsonld/test_testsuite.py index 200db054b..d64711a37 100644 --- a/test/jsonld/test_testsuite.py +++ b/test/jsonld/test_testsuite.py @@ -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 @@ -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 @@ -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) diff --git a/test/plugins/parser/example/rdflib/plugin/parser/__init__.py b/test/plugins/parser/example/rdflib/plugin/parser/__init__.py index 8554ceed3..d2df6d262 100644 --- a/test/plugins/parser/example/rdflib/plugin/parser/__init__.py +++ b/test/plugins/parser/example/rdflib/plugin/parser/__init__.py @@ -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 diff --git a/test/test_conjunctivegraph/test_conjunctivegraph_generators.py b/test/test_conjunctivegraph/test_conjunctivegraph_generators.py index 7642c2361..339e93f8e 100644 --- a/test/test_conjunctivegraph/test_conjunctivegraph_generators.py +++ b/test/test_conjunctivegraph/test_conjunctivegraph_generators.py @@ -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() diff --git a/test/test_conjunctivegraph/test_conjunctivegraph_operator_combinations.py b/test/test_conjunctivegraph/test_conjunctivegraph_operator_combinations.py index 13d204211..aa371c9a3 100644 --- a/test/test_conjunctivegraph/test_conjunctivegraph_operator_combinations.py +++ b/test/test_conjunctivegraph/test_conjunctivegraph_operator_combinations.py @@ -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() diff --git a/test/test_definednamespace.py b/test/test_definednamespace.py index 3bf335751..126fa5a6f 100644 --- a/test/test_definednamespace.py +++ b/test/test_definednamespace.py @@ -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}...") @@ -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" @@ -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}...") @@ -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}...") @@ -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") diff --git a/test/test_extras_external_graph_libs.py b/test/test_extras_external_graph_libs.py index 6b1c942a7..892480603 100644 --- a/test/test_extras_external_graph_libs.py +++ b/test/test_extras_external_graph_libs.py @@ -1,6 +1,7 @@ from rdflib import Graph, URIRef, Literal import pytest + def test_rdflib_to_networkx(): try: import networkx diff --git a/test/test_graph/test_graph_context.py b/test/test_graph/test_graph_context.py index ab4df544f..489702d64 100644 --- a/test/test_graph/test_graph_context.py +++ b/test/test_graph/test_graph_context.py @@ -8,6 +8,7 @@ import pytest from rdflib import Graph, ConjunctiveGraph, URIRef, BNode, plugin + class ContextTestCase(unittest.TestCase): store = "default" slow = True diff --git a/test/test_graph/test_graph_formula.py b/test/test_graph/test_graph_formula.py index c8ee9d897..d901771b5 100644 --- a/test/test_graph/test_graph_formula.py +++ b/test/test_graph/test_graph_formula.py @@ -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) diff --git a/test/test_graph/test_graph_generators.py b/test/test_graph/test_graph_generators.py index b0b0077d7..288bb2fc0 100644 --- a/test/test_graph/test_graph_generators.py +++ b/test/test_graph/test_graph_generators.py @@ -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): diff --git a/test/test_graph/test_graph_http.py b/test/test_graph/test_graph_http.py index f9e1b1701..4bfe6f276 100644 --- a/test/test_graph/test_graph_http.py +++ b/test/test_graph/test_graph_http.py @@ -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 diff --git a/test/test_graph/test_slice.py b/test/test_graph/test_slice.py index 845c658b5..7e3cae8e4 100644 --- a/test/test_graph/test_slice.py +++ b/test/test_graph/test_slice.py @@ -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, @@ -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 diff --git a/test/test_graph/test_variants.py b/test/test_graph/test_variants.py index 57221d5bb..dd0f02b27 100644 --- a/test/test_graph/test_variants.py +++ b/test/test_graph/test_variants.py @@ -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: @@ -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)}", + ) diff --git a/test/test_infixowl.py b/test/test_infixowl.py index 80f956a7e..96ed8d37d 100644 --- a/test/test_infixowl.py +++ b/test/test_infixowl.py @@ -51,8 +51,7 @@ def test_infix_owl_example1(): namespace_manager.bind("owl", OWL, override=False) owlGraph.namespace_manager = namespace_manager assert ( - str(list(Class(OWL.Class, graph=owlGraph).subClassOf)) - == "[Class: rdfs:Class ]" + str(list(Class(OWL.Class, graph=owlGraph).subClassOf)) == "[Class: rdfs:Class ]" ) # Operators are also available. For instance we can add ex:Opera to the extension diff --git a/test/test_issues/test_issue1404.py b/test/test_issues/test_issue1404.py index 469f713e2..2d40204a9 100644 --- a/test/test_issues/test_issue1404.py +++ b/test/test_issues/test_issue1404.py @@ -20,7 +20,10 @@ def test_skolem_de_skolem_roundtrip(): graph = Graph() graph.parse(data=ttl, format='turtle') - query = {"subject": URIRef("http://www.wikidata.org/entity/Q1203"), "predicate": FOAF.knows} + query = { + "subject": URIRef("http://www.wikidata.org/entity/Q1203"), + "predicate": FOAF.knows, + } # Save the original bnode id. bnode_id = graph.value(**query) diff --git a/test/test_issues/test_issue1484.py b/test/test_issues/test_issue1484.py index edccca12a..c86702bb8 100644 --- a/test/test_issues/test_issue1484.py +++ b/test/test_issues/test_issue1484.py @@ -57,8 +57,8 @@ def test_issue_1484_str(self): g.bind("rdfs", RDFS) g.parse(data=jsonstr, publicID=b, format="json-ld") - assert((n.s, RDF.type, n.t) in g) - assert((n.s, n.p, n.o) in g) + assert (n.s, RDF.type, n.t) in g + assert (n.s, n.p, n.o) in g if __name__ == "__main__": diff --git a/test/test_literal/test_normalized_string.py b/test/test_literal/test_normalized_string.py index 4aa979f04..735191915 100644 --- a/test/test_literal/test_normalized_string.py +++ b/test/test_literal/test_normalized_string.py @@ -26,4 +26,3 @@ def test4(self): ) expected = Literal("""hey there a tab carriage return""", datatype=XSD.string) assert str(lit) == str(expected) - diff --git a/test/test_literal/test_term.py b/test/test_literal/test_term.py index 6e0db8279..e70fb5918 100644 --- a/test/test_literal/test_term.py +++ b/test/test_literal/test_term.py @@ -43,6 +43,7 @@ class MyBNode(BNode): x = MyBNode() assert repr(x).startswith("MyBNode(") + class TestLiteral: def test_base64_values(self): b64msg = "cmRmbGliIGlzIGNvb2whIGFsc28gaGVyZSdzIHNvbWUgYmluYXJ5IAAR83UC" diff --git a/test/test_literal/test_tokendatatype.py b/test/test_literal/test_tokendatatype.py index 83fe339ed..13e4b3608 100644 --- a/test/test_literal/test_tokendatatype.py +++ b/test/test_literal/test_tokendatatype.py @@ -32,4 +32,3 @@ def test_whitespace_is_collapsed_and_trailing_whitespace_is_stripped(self): datatype=XSD.string, ) assert str(lit) == str(expected) - diff --git a/test/test_misc/test_b64_binary.py b/test/test_misc/test_b64_binary.py index c4fe1b6ea..a64a76742 100644 --- a/test/test_misc/test_b64_binary.py +++ b/test/test_misc/test_b64_binary.py @@ -21,4 +21,3 @@ def test_unicode(self): assert b_str1 == b_str1b assert b_str1b.decode("utf-8") == str1 assert str(l1b) == b64_str1 - diff --git a/test/test_misc/test_create_input_source.py b/test/test_misc/test_create_input_source.py index 501e9d31b..86bd214e5 100644 --- a/test/test_misc/test_create_input_source.py +++ b/test/test_misc/test_create_input_source.py @@ -12,4 +12,3 @@ def test_too_many_arguments(self): """create_input_source() function has a few conflicting arguments.""" with pytest.raises(ValueError): create_input_source(source="a", location="b") - diff --git a/test/test_misc/test_parse_file_guess_format.py b/test/test_misc/test_parse_file_guess_format.py index 147a357a6..c1c3ec041 100644 --- a/test/test_misc/test_parse_file_guess_format.py +++ b/test/test_misc/test_parse_file_guess_format.py @@ -63,4 +63,3 @@ def test_warning(self) -> None: match="does not look like a valid URI, trying to serialize this will break.", ) as logwarning: g.parse(str(newpath)) - diff --git a/test/test_misc/test_prefix_types.py b/test/test_misc/test_prefix_types.py index 42bd72821..b168eef80 100644 --- a/test/test_misc/test_prefix_types.py +++ b/test/test_misc/test_prefix_types.py @@ -21,7 +21,8 @@ class TestPrefixTypes: This is issue 161 http://code.google.com/p/rdflib/issues/detail?id=161 """ + def test(self): - s = graph.serialize(format="n3") - assert "foaf:Document" in s - assert "xsd:date" in s + s = graph.serialize(format="n3") + assert "foaf:Document" in s + assert "xsd:date" in s diff --git a/test/test_namespace/test_definednamespace_creator.py b/test/test_namespace/test_definednamespace_creator.py index 6d857154d..70293c9ac 100644 --- a/test/test_namespace/test_definednamespace_creator.py +++ b/test/test_namespace/test_definednamespace_creator.py @@ -8,7 +8,12 @@ def test_definednamespace_creator_qb(): Tests basic use of DefinedNamespace creator script using QB """ - definednamespace_script = Path(__file__).parent.parent.parent / "rdflib" / "tools" / "defined_namespace_creator.py" + definednamespace_script = ( + Path(__file__).parent.parent.parent + / "rdflib" + / "tools" + / "defined_namespace_creator.py" + ) qb_data_file = Path(__file__).parent.parent / "defined_namespaces" / "qb.ttl" print("\n") print(f"Using {definednamespace_script}...") @@ -33,7 +38,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" @@ -48,7 +56,12 @@ def test_definednamespace_creator_fake(): RDF file of unknonwn type """ - definednamespace_script = Path(__file__).parent.parent.parent / "rdflib" / "tools" / "defined_namespace_creator.py" + definednamespace_script = ( + Path(__file__).parent.parent.parent + / "rdflib" + / "tools" + / "defined_namespace_creator.py" + ) qb_data_file = Path(__file__).parent.parent / "defined_namespaces" / "fake.xxx" print("\n") print(f"Using {definednamespace_script}...") @@ -74,7 +87,12 @@ def test_definednamespace_creator_bad_ns(): supplied namespace doesn't end in # or / """ - definednamespace_script = Path(__file__).parent.parent.parent / "rdflib" / "tools" / "defined_namespace_creator.py" + definednamespace_script = ( + Path(__file__).parent.parent.parent + / "rdflib" + / "tools" + / "defined_namespace_creator.py" + ) qb_data_file = Path(__file__).parent.parent / "defined_namespaces" / "fake.xxx" print("\n") print(f"Using {definednamespace_script}...") diff --git a/test/test_parsers/test_empty_xml_base.py b/test/test_parsers/test_empty_xml_base.py index 38abbbe27..1c245b3e5 100644 --- a/test/test_parsers/test_empty_xml_base.py +++ b/test/test_parsers/test_empty_xml_base.py @@ -33,11 +33,14 @@ baseUri = URIRef("http://example.com/") baseUri2 = URIRef("http://example.com/foo/bar") + class TestEmptyBase: def test_empty_base_ref(self): self.graph = ConjunctiveGraph() self.graph.parse(data=test_data, publicID=baseUri, format="xml") - assert len(list(self.graph)) > 0, "There should be at least one statement in the graph" + assert ( + len(list(self.graph)) > 0 + ), "There should be at least one statement in the graph" assert ( baseUri, RDF.type, @@ -49,7 +52,9 @@ class TestRelativeBase: def test_relative_base_ref(self): self.graph = ConjunctiveGraph() self.graph.parse(data=test_data2, publicID=baseUri2, format="xml") - assert len(self.graph) > 0, "There should be at least one statement in the graph" + assert ( + len(self.graph) > 0 + ), "There should be at least one statement in the graph" resolvedBase = URIRef("http://example.com/baz") assert ( resolvedBase, diff --git a/test/test_parsers/test_parser_hext.py b/test/test_parsers/test_parser_hext.py index d4b595c10..4af94c792 100644 --- a/test/test_parsers/test_parser_hext.py +++ b/test/test_parsers/test_parser_hext.py @@ -1,5 +1,6 @@ import sys from pathlib import Path + sys.path.append(str(Path(__file__).parent.parent.absolute())) from rdflib import Dataset, ConjunctiveGraph, Literal from rdflib.namespace import XSD @@ -40,7 +41,11 @@ def test_small_string_cg(): def test_small_file_singlegraph(): - d = Dataset().parse(Path(__file__).parent.parent / "consistent_test_data/test_parser_hext_singlegraph.ndjson", format="hext") + d = Dataset().parse( + Path(__file__).parent.parent + / "consistent_test_data/test_parser_hext_singlegraph.ndjson", + format="hext", + ) assert len(d) == 10 @@ -48,9 +53,10 @@ def test_small_file_multigraph(): d = Dataset() assert len(d) == 0 d.parse( - Path(__file__).parent.parent / "consistent_test_data/test_parser_hext_multigraph.ndjson", + Path(__file__).parent.parent + / "consistent_test_data/test_parser_hext_multigraph.ndjson", format="hext", - publicID=d.default_context.identifier + publicID=d.default_context.identifier, ) """There are 22 lines in the file test_parser_hext_multigraph.ndjson. When loaded @@ -68,9 +74,10 @@ def test_small_file_multigraph_cg(): d = ConjunctiveGraph() assert len(d) == 0 d.parse( - Path(__file__).parent.parent / "consistent_test_data/test_parser_hext_multigraph.ndjson", + Path(__file__).parent.parent + / "consistent_test_data/test_parser_hext_multigraph.ndjson", format="hext", - publicID=d.default_context.identifier + publicID=d.default_context.identifier, ) """There are 22 lines in the file test_parser_hext_multigraph.ndjson. When loaded @@ -121,7 +128,7 @@ def test_roundtrip(): cg2.parse( data=cg.serialize(format="hext"), format="hext", - publicID=cg2.default_context.identifier + publicID=cg2.default_context.identifier, ) if cg2.context_aware: for context in cg2.contexts(): @@ -129,7 +136,9 @@ def test_roundtrip(): if type(triple[2]) == Literal: if triple[2].datatype == XSD.string: context.remove((triple[0], triple[1], triple[2])) - context.add((triple[0], triple[1], Literal(str(triple[2])))) + context.add( + (triple[0], triple[1], Literal(str(triple[2]))) + ) else: for triple in cg2.triples((None, None, None)): if type(triple[2]) == Literal: diff --git a/test/test_rdfxml.py b/test/test_rdfxml.py index 697fc3368..4e53c3c79 100644 --- a/test/test_rdfxml.py +++ b/test/test_rdfxml.py @@ -85,7 +85,7 @@ def cached_file(url): def relative(url): - return url[len(RDFCOREBASE):] + return url[len(RDFCOREBASE) :] def resolve(rel): diff --git a/test/test_serializers/test_serializer_hext.py b/test/test_serializers/test_serializer_hext.py index dfba25332..f2c7867ff 100644 --- a/test/test_serializers/test_serializer_hext.py +++ b/test/test_serializers/test_serializer_hext.py @@ -1,5 +1,6 @@ import sys from pathlib import Path + sys.path.append(str(Path(__file__).parent.parent.absolute())) from rdflib import Dataset, Graph, ConjunctiveGraph import json @@ -33,18 +34,51 @@ def test_hext_graph(): out = g.serialize(format="hext") # note: can't test for BNs in result as they will be different every time testing_lines = [ - [False, '["http://example.com/s1", "http://example.com/p1", "http://example.com/o2", "globalId", "", ""]'], - [False, '["http://example.com/s1", "http://example.com/p3", "Object 3", "http://www.w3.org/2001/XMLSchema#string", "", ""]'], - [False, '["http://example.com/s1", "http://example.com/p3", "Object 4 - English", "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString", "en", ""]'], - [False, '["http://example.com/s1", "http://example.com/p1", "http://example.com/o1", "globalId", "", ""]'], - [False, '["http://example.com/s1", "http://example.com/p4", "2021-12-03", "http://www.w3.org/2001/XMLSchema#date", "", ""]'], - [False, '["http://example.com/s1", "http://example.com/p6", "42", "http://www.w3.org/2001/XMLSchema#string", "", ""]'], - [False, '["http://example.com/s1", "http://example.com/p7", "true", "http://www.w3.org/2001/XMLSchema#boolean", "", ""]'], - [False, '"http://www.w3.org/1999/02/22-rdf-syntax-ns#value", "thingy", "http://www.w3.org/2001/XMLSchema#string", "", ""]'], + [ + False, + '["http://example.com/s1", "http://example.com/p1", "http://example.com/o2", "globalId", "", ""]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p3", "Object 3", "http://www.w3.org/2001/XMLSchema#string", "", ""]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p3", "Object 4 - English", "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString", "en", ""]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p1", "http://example.com/o1", "globalId", "", ""]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p4", "2021-12-03", "http://www.w3.org/2001/XMLSchema#date", "", ""]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p6", "42", "http://www.w3.org/2001/XMLSchema#string", "", ""]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p7", "true", "http://www.w3.org/2001/XMLSchema#boolean", "", ""]', + ], + [ + False, + '"http://www.w3.org/1999/02/22-rdf-syntax-ns#value", "thingy", "http://www.w3.org/2001/XMLSchema#string", "", ""]', + ], [False, '["http://example.com/s1", "http://example.com/p2"'], - [False, '["http://example.com/s1", "http://example.com/p5", "42", "http://www.w3.org/2001/XMLSchema#integer", "", ""]'], - [False, '"http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "http://www.w3.org/2002/07/owl#Thing", "globalId", "", ""]'], - [False, '["http://example.com/s1", "http://example.com/p8", "false", "http://www.w3.org/2001/XMLSchema#boolean", "", ""]'], + [ + False, + '["http://example.com/s1", "http://example.com/p5", "42", "http://www.w3.org/2001/XMLSchema#integer", "", ""]', + ], + [ + False, + '"http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "http://www.w3.org/2002/07/owl#Thing", "globalId", "", ""]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p8", "false", "http://www.w3.org/2001/XMLSchema#boolean", "", ""]', + ], ] for line in out.splitlines(): for test in testing_lines: @@ -97,24 +131,75 @@ def test_hext_cg(): out = d.serialize(format="hext") # note: cant' test for BNs in result as they will be different ever time testing_lines = [ - [False, '["http://example.com/s21", "http://example.com/p21", "http://example.com/o21", "globalId", "", ""]'], - [False, '["http://example.com/s21", "http://example.com/p21", "http://example.com/o22", "globalId", "", ""]'], - [False, '["http://example.com/s1", "http://example.com/p1", "http://example.com/o2", "globalId", "", ""]'], - [False, '["http://example.com/s1", "http://example.com/p1", "http://example.com/o1", "globalId", "", ""]'], - [False, '["http://example.com/s11", "http://example.com/p11", "http://example.com/o12", "globalId", "", "http://example.com/g2"]'], - [False, '["http://example.com/s1", "http://example.com/p1", "http://example.com/o2", "globalId", "", "http://example.com/g2"]'], - [False, '["http://example.com/s11", "http://example.com/p11", "http://example.com/o11", "globalId", "", "http://example.com/g2"]'], - [False, '["http://example.com/s1", "http://example.com/p1", "http://example.com/o1", "globalId", "", "http://example.com/g2"]'], - [False, '["http://example.com/s1", "http://example.com/p1", "http://example.com/o2", "globalId", "", "http://example.com/g1"]'], + [ + False, + '["http://example.com/s21", "http://example.com/p21", "http://example.com/o21", "globalId", "", ""]', + ], + [ + False, + '["http://example.com/s21", "http://example.com/p21", "http://example.com/o22", "globalId", "", ""]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p1", "http://example.com/o2", "globalId", "", ""]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p1", "http://example.com/o1", "globalId", "", ""]', + ], + [ + False, + '["http://example.com/s11", "http://example.com/p11", "http://example.com/o12", "globalId", "", "http://example.com/g2"]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p1", "http://example.com/o2", "globalId", "", "http://example.com/g2"]', + ], + [ + False, + '["http://example.com/s11", "http://example.com/p11", "http://example.com/o11", "globalId", "", "http://example.com/g2"]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p1", "http://example.com/o1", "globalId", "", "http://example.com/g2"]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p1", "http://example.com/o2", "globalId", "", "http://example.com/g1"]', + ], [False, '["http://example.com/s1", "http://example.com/p2"'], - [False, '"http://www.w3.org/1999/02/22-rdf-syntax-ns#value", "thingy", "http://www.w3.org/2001/XMLSchema#string", "", "http://example.com/g1"]'], - [False, '"http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "http://www.w3.org/2002/07/owl#Thing", "globalId", "", "http://example.com/g1"]'], - [False, '["http://example.com/s1", "http://example.com/p3", "Object 4 - English", "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString", "en", "http://example.com/g1"]'], - [False, '["http://example.com/s1", "http://example.com/p6", "42", "http://www.w3.org/2001/XMLSchema#string", "", "http://example.com/g1"]'], - [False, '["http://example.com/s1", "http://example.com/p4", "2021-12-03", "http://www.w3.org/2001/XMLSchema#date", "", "http://example.com/g1"]'], - [False, '["http://example.com/s1", "http://example.com/p1", "http://example.com/o1", "globalId", "", "http://example.com/g1"]'], - [False, '["http://example.com/s1", "http://example.com/p5", "42", "http://www.w3.org/2001/XMLSchema#integer", "", "http://example.com/g1"]'], - [False, '["http://example.com/s1", "http://example.com/p3", "Object 3", "http://www.w3.org/2001/XMLSchema#string", "", "http://example.com/g1"]'], + [ + False, + '"http://www.w3.org/1999/02/22-rdf-syntax-ns#value", "thingy", "http://www.w3.org/2001/XMLSchema#string", "", "http://example.com/g1"]', + ], + [ + False, + '"http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "http://www.w3.org/2002/07/owl#Thing", "globalId", "", "http://example.com/g1"]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p3", "Object 4 - English", "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString", "en", "http://example.com/g1"]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p6", "42", "http://www.w3.org/2001/XMLSchema#string", "", "http://example.com/g1"]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p4", "2021-12-03", "http://www.w3.org/2001/XMLSchema#date", "", "http://example.com/g1"]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p1", "http://example.com/o1", "globalId", "", "http://example.com/g1"]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p5", "42", "http://www.w3.org/2001/XMLSchema#integer", "", "http://example.com/g1"]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p3", "Object 3", "http://www.w3.org/2001/XMLSchema#string", "", "http://example.com/g1"]', + ], ] for line in out.splitlines(): for test in testing_lines: @@ -162,24 +247,75 @@ def test_hext_dataset(): out = d.serialize(format="hext") # note: cant' test for BNs in result as they will be different ever time testing_lines = [ - [False, '["http://example.com/s21", "http://example.com/p21", "http://example.com/o21", "globalId", "", ""]'], - [False, '["http://example.com/s21", "http://example.com/p21", "http://example.com/o22", "globalId", "", ""]'], - [False, '["http://example.com/s1", "http://example.com/p1", "http://example.com/o2", "globalId", "", ""]'], - [False, '["http://example.com/s1", "http://example.com/p1", "http://example.com/o1", "globalId", "", ""]'], - [False, '["http://example.com/s11", "http://example.com/p11", "http://example.com/o12", "globalId", "", "http://example.com/g2"]'], - [False, '["http://example.com/s1", "http://example.com/p1", "http://example.com/o2", "globalId", "", "http://example.com/g2"]'], - [False, '["http://example.com/s11", "http://example.com/p11", "http://example.com/o11", "globalId", "", "http://example.com/g2"]'], - [False, '["http://example.com/s1", "http://example.com/p1", "http://example.com/o1", "globalId", "", "http://example.com/g2"]'], - [False, '["http://example.com/s1", "http://example.com/p1", "http://example.com/o2", "globalId", "", "http://example.com/g1"]'], + [ + False, + '["http://example.com/s21", "http://example.com/p21", "http://example.com/o21", "globalId", "", ""]', + ], + [ + False, + '["http://example.com/s21", "http://example.com/p21", "http://example.com/o22", "globalId", "", ""]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p1", "http://example.com/o2", "globalId", "", ""]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p1", "http://example.com/o1", "globalId", "", ""]', + ], + [ + False, + '["http://example.com/s11", "http://example.com/p11", "http://example.com/o12", "globalId", "", "http://example.com/g2"]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p1", "http://example.com/o2", "globalId", "", "http://example.com/g2"]', + ], + [ + False, + '["http://example.com/s11", "http://example.com/p11", "http://example.com/o11", "globalId", "", "http://example.com/g2"]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p1", "http://example.com/o1", "globalId", "", "http://example.com/g2"]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p1", "http://example.com/o2", "globalId", "", "http://example.com/g1"]', + ], [False, '["http://example.com/s1", "http://example.com/p2"'], - [False, '"http://www.w3.org/1999/02/22-rdf-syntax-ns#value", "thingy", "http://www.w3.org/2001/XMLSchema#string", "", "http://example.com/g1"]'], - [False, '"http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "http://www.w3.org/2002/07/owl#Thing", "globalId", "", "http://example.com/g1"]'], - [False, '["http://example.com/s1", "http://example.com/p3", "Object 4 - English", "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString", "en", "http://example.com/g1"]'], - [False, '["http://example.com/s1", "http://example.com/p6", "42", "http://www.w3.org/2001/XMLSchema#string", "", "http://example.com/g1"]'], - [False, '["http://example.com/s1", "http://example.com/p4", "2021-12-03", "http://www.w3.org/2001/XMLSchema#date", "", "http://example.com/g1"]'], - [False, '["http://example.com/s1", "http://example.com/p1", "http://example.com/o1", "globalId", "", "http://example.com/g1"]'], - [False, '["http://example.com/s1", "http://example.com/p5", "42", "http://www.w3.org/2001/XMLSchema#integer", "", "http://example.com/g1"]'], - [False, '["http://example.com/s1", "http://example.com/p3", "Object 3", "http://www.w3.org/2001/XMLSchema#string", "", "http://example.com/g1"]'], + [ + False, + '"http://www.w3.org/1999/02/22-rdf-syntax-ns#value", "thingy", "http://www.w3.org/2001/XMLSchema#string", "", "http://example.com/g1"]', + ], + [ + False, + '"http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "http://www.w3.org/2002/07/owl#Thing", "globalId", "", "http://example.com/g1"]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p3", "Object 4 - English", "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString", "en", "http://example.com/g1"]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p6", "42", "http://www.w3.org/2001/XMLSchema#string", "", "http://example.com/g1"]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p4", "2021-12-03", "http://www.w3.org/2001/XMLSchema#date", "", "http://example.com/g1"]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p1", "http://example.com/o1", "globalId", "", "http://example.com/g1"]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p5", "42", "http://www.w3.org/2001/XMLSchema#integer", "", "http://example.com/g1"]', + ], + [ + False, + '["http://example.com/s1", "http://example.com/p3", "Object 3", "http://www.w3.org/2001/XMLSchema#string", "", "http://example.com/g1"]', + ], ] for line in out.splitlines(): for test in testing_lines: @@ -234,9 +370,10 @@ def test_hext_dataset_linecount(): d = Dataset() assert len(d) == 0 d.parse( - Path(__file__).parent.parent / "consistent_test_data/test_parser_hext_multigraph.ndjson", + Path(__file__).parent.parent + / "consistent_test_data/test_parser_hext_multigraph.ndjson", format="hext", - publicID=d.default_context.identifier + publicID=d.default_context.identifier, ) total_triples = 0 # count all the triples in the Dataset @@ -253,12 +390,18 @@ def test_hext_dataset_linecount(): def test_roundtrip(): d = Dataset() d.parse( - Path(__file__).parent.parent / "consistent_test_data/test_parser_hext_multigraph.ndjson", + Path(__file__).parent.parent + / "consistent_test_data/test_parser_hext_multigraph.ndjson", format="hext", - publicID=d.default_context.identifier + publicID=d.default_context.identifier, ) d.default_union = True - with open(str(Path(__file__).parent.parent / "consistent_test_data/test_parser_hext_multigraph.ndjson")) as i: + with open( + str( + Path(__file__).parent.parent + / "consistent_test_data/test_parser_hext_multigraph.ndjson" + ) + ) as i: ordered_input = "".join(sorted(i.readlines())).strip() ordered_output = "\n".join(sorted(d.serialize(format="hext").split("\n"))).strip() diff --git a/test/test_sparql/test_construct_bindings.py b/test/test_sparql/test_construct_bindings.py index bf62d11d7..3b21e87d6 100644 --- a/test/test_sparql/test_construct_bindings.py +++ b/test/test_sparql/test_construct_bindings.py @@ -5,6 +5,7 @@ import unittest from test.testutils import eq_ + class TestConstructInitBindings(unittest.TestCase): def test_construct_init_bindings(self): """ diff --git a/test/test_sparql/test_evaluate_bind.py b/test/test_sparql/test_evaluate_bind.py index 928acbb33..91f704a3d 100644 --- a/test/test_sparql/test_evaluate_bind.py +++ b/test/test_sparql/test_evaluate_bind.py @@ -37,6 +37,7 @@ def check(expr, var, obj): URIRef("http://example.org/ns#Thing"), ) + @pytest.mark.parametrize("checker, expr, var, obj", get_bind_tests()) def test_bind(checker, expr, var, obj) -> None: checker(expr, var, obj) diff --git a/test/test_sparql/test_operators.py b/test/test_sparql/test_operators.py index 2c122eb4b..80a5aaf0c 100644 --- a/test/test_sparql/test_operators.py +++ b/test/test_sparql/test_operators.py @@ -5,6 +5,7 @@ from rdflib.plugins.sparql import sparql import pytest + def test_date_cast(): now = datetime.datetime.now() today = now.date() diff --git a/test/test_sparql/test_prepare.py b/test/test_sparql/test_prepare.py index 89edf2c23..ae1496d4e 100644 --- a/test/test_sparql/test_prepare.py +++ b/test/test_sparql/test_prepare.py @@ -34,7 +34,9 @@ def test_prepare_query(): g = Graph() g.parse( - location=os.path.join(os.path.dirname(__file__), "..", "..", "examples", "foaf.n3"), + location=os.path.join( + os.path.dirname(__file__), "..", "..", "examples", "foaf.n3" + ), format="n3", ) diff --git a/test/test_sparql/test_sparql.py b/test/test_sparql/test_sparql.py index 09a0ab24b..3c90da9de 100644 --- a/test/test_sparql/test_sparql.py +++ b/test/test_sparql/test_sparql.py @@ -164,60 +164,42 @@ def test_named_filter_graph_query(): """, ) - assert ( - list( - g.query( - "SELECT ?l WHERE { GRAPH ex:g1 { ?a rdfs:label ?l } ?a a ?type }", - initNs={"ex": ex}, - ) + assert list( + g.query( + "SELECT ?l WHERE { GRAPH ex:g1 { ?a rdfs:label ?l } ?a a ?type }", + initNs={"ex": ex}, ) - == [(Literal("Boris"),)] - ) - assert ( - list( - g.query( - "SELECT ?l WHERE { GRAPH ex:g1 { ?a rdfs:label ?l } FILTER EXISTS { ?a a ?type }}", - initNs={"ex": ex}, - ) + ) == [(Literal("Boris"),)] + assert list( + g.query( + "SELECT ?l WHERE { GRAPH ex:g1 { ?a rdfs:label ?l } FILTER EXISTS { ?a a ?type }}", + initNs={"ex": ex}, ) - == [(Literal("Boris"),)] - ) - assert ( - list( - g.query( - "SELECT ?l WHERE { GRAPH ex:g1 { ?a rdfs:label ?l } FILTER NOT EXISTS { ?a a ?type }}", - initNs={"ex": ex}, - ) + ) == [(Literal("Boris"),)] + assert list( + g.query( + "SELECT ?l WHERE { GRAPH ex:g1 { ?a rdfs:label ?l } FILTER NOT EXISTS { ?a a ?type }}", + initNs={"ex": ex}, ) - == [(Literal("Susan"),)] - ) - assert ( - list( - g.query( - "SELECT ?l WHERE { GRAPH ?g { ?a rdfs:label ?l } ?a a ?type }", - initNs={"ex": ex}, - ) + ) == [(Literal("Susan"),)] + assert list( + g.query( + "SELECT ?l WHERE { GRAPH ?g { ?a rdfs:label ?l } ?a a ?type }", + initNs={"ex": ex}, ) - == [(Literal("Boris"),)] - ) - assert ( - list( - g.query( - "SELECT ?l WHERE { GRAPH ?g { ?a rdfs:label ?l } FILTER EXISTS { ?a a ?type }}", - initNs={"ex": ex}, - ) + ) == [(Literal("Boris"),)] + assert list( + g.query( + "SELECT ?l WHERE { GRAPH ?g { ?a rdfs:label ?l } FILTER EXISTS { ?a a ?type }}", + initNs={"ex": ex}, ) - == [(Literal("Boris"),)] - ) - assert ( - list( - g.query( - "SELECT ?l WHERE { GRAPH ?g { ?a rdfs:label ?l } FILTER NOT EXISTS { ?a a ?type }}", - initNs={"ex": ex}, - ) + ) == [(Literal("Boris"),)] + assert list( + g.query( + "SELECT ?l WHERE { GRAPH ?g { ?a rdfs:label ?l } FILTER NOT EXISTS { ?a a ?type }}", + initNs={"ex": ex}, ) - == [(Literal("Susan"),)] - ) + ) == [(Literal("Susan"),)] def test_txtresult(): diff --git a/test/test_tools/test_csv2rdf.py b/test/test_tools/test_csv2rdf.py index 504cf44f4..e98e71edd 100644 --- a/test/test_tools/test_csv2rdf.py +++ b/test/test_tools/test_csv2rdf.py @@ -7,6 +7,7 @@ REALESTATE_FILE_PATH = os.path.join(CONSISTENT_DATA_DIR, "csv", "realestate.csv") + class TestCSV2RDF: def test_csv2rdf_cli(self): completed = subprocess.run( diff --git a/test/test_typing.py b/test/test_typing.py index c3295ed44..5a1695bc4 100644 --- a/test/test_typing.py +++ b/test/test_typing.py @@ -56,9 +56,7 @@ def test_rdflib_query_exercise() -> None: graph.add((kb_https_uriref, predicate_q, literal_two)) graph.add((kb_bnode, predicate_p, literal_one)) - expected_nodes_using_predicate_q: Set[rdflib.IdentifiedNode] = { - kb_https_uriref - } + expected_nodes_using_predicate_q: Set[rdflib.IdentifiedNode] = {kb_https_uriref} computed_nodes_using_predicate_q: Set[rdflib.IdentifiedNode] = set() for triple in graph.triples((None, predicate_q, None)): computed_nodes_using_predicate_q.add(triple[0]) diff --git a/test/testutils.py b/test/testutils.py index ec8324121..93e20851d 100644 --- a/test/testutils.py +++ b/test/testutils.py @@ -191,7 +191,10 @@ def assert_sets_equals( @classmethod def format_set( - cls, item_set: Union[IdentifierQuadSet, IdentifierTripleSet], prefix: str = " ", sort: bool = False + cls, + item_set: Union[IdentifierQuadSet, IdentifierTripleSet], + prefix: str = " ", + sort: bool = False, ) -> str: items = [] use_item_set = sorted(item_set) if sort else item_set @@ -200,11 +203,15 @@ def format_set( return "\n".join(items) @classmethod - def format_graph_set(cls, graph: Graph, prefix: str = " ", sort: bool = False) -> str: + def format_graph_set( + cls, graph: Graph, prefix: str = " ", sort: bool = False + ) -> str: return cls.format_set(cls.triple_or_quad_set(graph), prefix, sort) @classmethod - def assert_isomorphic(cls, lhs: Graph, rhs: Graph, message: Optional[str] = None) -> None: + def assert_isomorphic( + cls, lhs: Graph, rhs: Graph, message: Optional[str] = None + ) -> None: """ This asserts that the two graphs are isomorphic, providing a nicely formatted error message if they are not.