diff options
Diffstat (limited to 'test')
50 files changed, 1240 insertions, 660 deletions
diff --git a/test/helper.py b/test/helper.py index acecde3d..21c61bbe 100644 --- a/test/helper.py +++ b/test/helper.py @@ -23,7 +23,7 @@ def query_with_retry(graph: rdflib.Graph, query: str, **kwargs) -> rdflib.query. As fast feedback is important the retry should be done quickly. Therefor the first retry is done after 100ms. But if the issue is outside the server running the tests it we need to be good - citizenship of the internet and not hit servers of others at + citizenship of the internet and not hit servers of others at a constant rate. (Also it might get us banned) Therefor this function implements a backoff mechanism. @@ -41,13 +41,15 @@ def query_with_retry(graph: rdflib.Graph, query: str, **kwargs) -> rdflib.query. for i in range(MAX_RETRY): try: result = graph.query(query, **kwargs) - result.bindings # access bindings to ensure no lazy loading + result.bindings # access bindings to ensure no lazy loading return result except urllib.error.URLError as e: - if i == MAX_RETRY -1: - raise e + if i == MAX_RETRY - 1: + raise e backoff_s = (BACKOFF_FACTOR ** backoff) / 10 - print(f"Network error {e} during query, waiting for {backoff_s:.2f}s and retrying") + print( + f"Network error {e} during query, waiting for {backoff_s:.2f}s and retrying" + ) time.sleep(backoff_s) backoff += 1 diff --git a/test/jsonld/runner.py b/test/jsonld/runner.py index 402cdefc..ccdd6abf 100644 --- a/test/jsonld/runner.py +++ b/test/jsonld/runner.py @@ -19,8 +19,6 @@ def _preserving_nodeid(self, bnode_context=None): DEFAULT_PARSER_VERSION = 1.0 - - def do_test_json(suite_base, cat, num, inputpath, expectedpath, context, options): input_uri = suite_base + inputpath input_obj = _load_json(inputpath) diff --git a/test/jsonld/test_onedotone.py b/test/jsonld/test_onedotone.py index 9d3a1280..884e6f23 100644 --- a/test/jsonld/test_onedotone.py +++ b/test/jsonld/test_onedotone.py @@ -34,7 +34,9 @@ known_bugs = ( # TODO: RDFLib collapses http://ab//de to http://ab/de "toRdf/0128-in", # TODO: RDFLib does not allow arbitrary "urn:ex:s307" as a URI in predicate place - "toRdf/0130-in", "toRdf/0131-in", "toRdf/0132-in", + "toRdf/0130-in", + "toRdf/0131-in", + "toRdf/0132-in", # TODO: Odd context lookup bug with scoped context (v1.1 bug) "toRdf/c013-in", # Type with @context of null should fall back to @vocab (I think), not baseuri @@ -46,9 +48,13 @@ known_bugs = ( # TODO: Bug with resolving relative context url from top-level context which is not doc_root "toRdf/c031-in", # TODO: Nested Contexts don't quite work properly yet - "toRdf/c037-in", "toRdf/c038-in", + "toRdf/c037-in", + "toRdf/c038-in", # TODO: @direction doesn't quite work properly in this implementation - "toRdf/di09-in", "toRdf/di10-in", "toRdf/di11-in", "toRdf/di12-in", + "toRdf/di09-in", + "toRdf/di10-in", + "toRdf/di11-in", + "toRdf/di12-in", # TODO: empty list inside a list is represented wrong? "toRdf/e004-in", # Same problem as 0002-in @@ -58,17 +64,34 @@ known_bugs = ( # @id and @vocab in literal datatype expansion doesn't work "toRdf/e088-in", # TODO: relative-iri keeps . on end of IRI? - "toRdf/e076-in", "toRdf/e089-in", "toRdf/e090-in", "toRdf/e091-in", "toRdf/e110-in", "toRdf/e129-in", "toRdf/e130-in", + "toRdf/e076-in", + "toRdf/e089-in", + "toRdf/e090-in", + "toRdf/e091-in", + "toRdf/e110-in", + "toRdf/e129-in", + "toRdf/e130-in", # TODO: Just broken expansion... - "toRdf/e080-in", "toRdf/e092-in", "toRdf/e093-in", "toRdf/e094-in", "toRdf/e104-in", "toRdf/e108-in", + "toRdf/e080-in", + "toRdf/e092-in", + "toRdf/e093-in", + "toRdf/e094-in", + "toRdf/e104-in", + "toRdf/e108-in", # TODO: Odd result in list expansion - "toRdf/e105-in", "toRdf/e107-in", + "toRdf/e105-in", + "toRdf/e107-in", # no expandContent option? "toRdf/e077-in", # TODO: Investigate: - "toRdf/e111-in", "toRdf/e112-in", "toRdf/e119-in", "toRdf/e120-in", "toRdf/e122-in", + "toRdf/e111-in", + "toRdf/e112-in", + "toRdf/e119-in", + "toRdf/e120-in", + "toRdf/e122-in", # RDFLib cannot keep a colon on the end of a prefix uri - "toRdf/e117-in", "toRdf/e118-in", + "toRdf/e117-in", + "toRdf/e118-in", # <ex:ns/> doesn't expand to <http://example.org/ns/> "toRdf/e124-in", # Similar to above? @@ -76,17 +99,29 @@ known_bugs = ( # Recursive Inclusion triggered! "toRdf/e128-in", # JSON-native double representation - "toRdf/js04-in", "toRdf/js10-in", + "toRdf/js04-in", + "toRdf/js10-in", # JSON character escaping - "toRdf/js12-in", "toRdf/js13-in", + "toRdf/js12-in", + "toRdf/js13-in", # Broken list comprehension - "toRdf/li05-in", "toRdf/li06-in", "toRdf/li07-in", "toRdf/li08-in", "toRdf/li09-in", "toRdf/li10-in", "toRdf/li11-in", "toRdf/li14-in", + "toRdf/li05-in", + "toRdf/li06-in", + "toRdf/li07-in", + "toRdf/li08-in", + "toRdf/li09-in", + "toRdf/li10-in", + "toRdf/li11-in", + "toRdf/li14-in", # Bad URI? "toRdf/li12-in", # cannot use property-index to add property to graph object? - "toRdf/pi11-in", "toRdf/pr25-in", + "toRdf/pi11-in", + "toRdf/pr25-in", # Investigate property issues: - "toRdf/pr38-in", "toRdf/pr39-in", "toRdf/pr40-in", + "toRdf/pr38-in", + "toRdf/pr39-in", + "toRdf/pr40-in", # Negative zero representation? "toRdf/rt01-in", # Property scope with @propagate not working @@ -145,6 +180,7 @@ def read_manifest(skiptests): if expectedpath: yield category, testnum, inputpath, expectedpath, context, options + def test_suite(): skiptests = unsupported_tests if SKIP_KNOWN_BUGS: @@ -152,9 +188,15 @@ def test_suite(): old_cwd = getcwd() chdir(test_dir) try: - 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 and "specVersion" in options and str(options["specVersion"]).lower() == "json-ld-1.0": + if ( + SKIP_1_0_TESTS + and "specVersion" in options + and str(options["specVersion"]).lower() == "json-ld-1.0" + ): # Skip the JSON v1.0 tests continue if inputpath.endswith(".jsonld"): # toRdf @@ -167,4 +209,3 @@ def test_suite(): yield func, TC_BASE, cat, num, inputpath, expectedpath, context, options finally: chdir(old_cwd) - diff --git a/test/jsonld/test_testsuite.py b/test/jsonld/test_testsuite.py index f439d5ed..b33176e6 100644 --- a/test/jsonld/test_testsuite.py +++ b/test/jsonld/test_testsuite.py @@ -24,7 +24,7 @@ known_bugs = ( # # "toRdf-0091-in", # TODO: multiple aliases version? # # TODO: check that these are corrected in 1.1 testsuite (1.0-deprecated prefix forms) "toRdf-0088-in", - "toRdf-0118-in", # RDFLib cannot do generalized graphs + "toRdf-0118-in", # RDFLib cannot do generalized graphs ) TC_BASE = "https://w3c.github.io/json-ld-api/tests/" @@ -84,7 +84,9 @@ def test_suite(skip_known_bugs=True): chdir(test_dir) runner.DEFAULT_PARSER_VERSION = 1.0 try: - 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 diff --git a/test/test_auditable.py b/test/test_auditable.py index f8ab73c1..f5c1188c 100644 --- a/test/test_auditable.py +++ b/test/test_auditable.py @@ -28,19 +28,37 @@ class TestAuditableStore(BaseTestAuditableStore): self.t.add((EX.s1, EX.p1, EX.o1)) self.assert_graph_equal( self.t, - [(EX.s0, EX.p0, EX.o0), (EX.s0, EX.p0, EX.o0bis), (EX.s1, EX.p1, EX.o1),], + [ + (EX.s0, EX.p0, EX.o0), + (EX.s0, EX.p0, EX.o0bis), + (EX.s1, EX.p1, EX.o1), + ], ) self.t.commit() self.assert_graph_equal( self.g, - [(EX.s0, EX.p0, EX.o0), (EX.s0, EX.p0, EX.o0bis), (EX.s1, EX.p1, EX.o1),], + [ + (EX.s0, EX.p0, EX.o0), + (EX.s0, EX.p0, EX.o0bis), + (EX.s1, EX.p1, EX.o1), + ], ) def test_remove_commit(self): self.t.remove((EX.s0, EX.p0, EX.o0)) - self.assert_graph_equal(self.t, [(EX.s0, EX.p0, EX.o0bis),]) + self.assert_graph_equal( + self.t, + [ + (EX.s0, EX.p0, EX.o0bis), + ], + ) self.t.commit() - self.assert_graph_equal(self.g, [(EX.s0, EX.p0, EX.o0bis),]) + self.assert_graph_equal( + self.g, + [ + (EX.s0, EX.p0, EX.o0bis), + ], + ) def test_multiple_remove_commit(self): self.t.remove((EX.s0, EX.p0, None)) @@ -51,32 +69,56 @@ class TestAuditableStore(BaseTestAuditableStore): def test_noop_add_commit(self): self.t.add((EX.s0, EX.p0, EX.o0)) self.assert_graph_equal( - self.t, [(EX.s0, EX.p0, EX.o0), (EX.s0, EX.p0, EX.o0bis),] + self.t, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s0, EX.p0, EX.o0bis), + ], ) self.t.commit() self.assert_graph_equal( - self.g, [(EX.s0, EX.p0, EX.o0), (EX.s0, EX.p0, EX.o0bis),] + self.g, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s0, EX.p0, EX.o0bis), + ], ) def test_noop_remove_commit(self): self.t.add((EX.s0, EX.p0, EX.o0)) self.assert_graph_equal( - self.t, [(EX.s0, EX.p0, EX.o0), (EX.s0, EX.p0, EX.o0bis),] + self.t, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s0, EX.p0, EX.o0bis), + ], ) self.t.commit() self.assert_graph_equal( - self.g, [(EX.s0, EX.p0, EX.o0), (EX.s0, EX.p0, EX.o0bis),] + self.g, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s0, EX.p0, EX.o0bis), + ], ) def test_add_remove_commit(self): self.t.add((EX.s1, EX.p1, EX.o1)) self.t.remove((EX.s1, EX.p1, EX.o1)) self.assert_graph_equal( - self.t, [(EX.s0, EX.p0, EX.o0), (EX.s0, EX.p0, EX.o0bis),] + self.t, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s0, EX.p0, EX.o0bis), + ], ) self.t.commit() self.assert_graph_equal( - self.g, [(EX.s0, EX.p0, EX.o0), (EX.s0, EX.p0, EX.o0bis),] + self.g, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s0, EX.p0, EX.o0bis), + ], ) def test_remove_add_commit(self): @@ -84,47 +126,75 @@ class TestAuditableStore(BaseTestAuditableStore): self.t.add((EX.s1, EX.p1, EX.o1)) self.assert_graph_equal( self.t, - [(EX.s0, EX.p0, EX.o0), (EX.s0, EX.p0, EX.o0bis), (EX.s1, EX.p1, EX.o1),], + [ + (EX.s0, EX.p0, EX.o0), + (EX.s0, EX.p0, EX.o0bis), + (EX.s1, EX.p1, EX.o1), + ], ) self.t.commit() self.assert_graph_equal( self.g, - [(EX.s0, EX.p0, EX.o0), (EX.s0, EX.p0, EX.o0bis), (EX.s1, EX.p1, EX.o1),], + [ + (EX.s0, EX.p0, EX.o0), + (EX.s0, EX.p0, EX.o0bis), + (EX.s1, EX.p1, EX.o1), + ], ) def test_add_rollback(self): self.t.add((EX.s1, EX.p1, EX.o1)) self.t.rollback() self.assert_graph_equal( - self.g, [(EX.s0, EX.p0, EX.o0), (EX.s0, EX.p0, EX.o0bis),] + self.g, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s0, EX.p0, EX.o0bis), + ], ) def test_remove_rollback(self): self.t.remove((EX.s0, EX.p0, EX.o0)) self.t.rollback() self.assert_graph_equal( - self.g, [(EX.s0, EX.p0, EX.o0), (EX.s0, EX.p0, EX.o0bis),] + self.g, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s0, EX.p0, EX.o0bis), + ], ) def test_multiple_remove_rollback(self): self.t.remove((EX.s0, EX.p0, None)) self.t.rollback() self.assert_graph_equal( - self.g, [(EX.s0, EX.p0, EX.o0), (EX.s0, EX.p0, EX.o0bis),] + self.g, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s0, EX.p0, EX.o0bis), + ], ) def test_noop_add_rollback(self): self.t.add((EX.s0, EX.p0, EX.o0)) self.t.rollback() self.assert_graph_equal( - self.g, [(EX.s0, EX.p0, EX.o0), (EX.s0, EX.p0, EX.o0bis),] + self.g, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s0, EX.p0, EX.o0bis), + ], ) def test_noop_remove_rollback(self): self.t.add((EX.s0, EX.p0, EX.o0)) self.t.rollback() self.assert_graph_equal( - self.g, [(EX.s0, EX.p0, EX.o0), (EX.s0, EX.p0, EX.o0bis),] + self.g, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s0, EX.p0, EX.o0bis), + ], ) def test_add_remove_rollback(self): @@ -132,7 +202,11 @@ class TestAuditableStore(BaseTestAuditableStore): self.t.remove((EX.s1, EX.p1, EX.o1)) self.t.rollback() self.assert_graph_equal( - self.g, [(EX.s0, EX.p0, EX.o0), (EX.s0, EX.p0, EX.o0bis),] + self.g, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s0, EX.p0, EX.o0bis), + ], ) def test_remove_add_rollback(self): @@ -140,7 +214,11 @@ class TestAuditableStore(BaseTestAuditableStore): self.t.add((EX.s1, EX.p1, EX.o1)) self.t.rollback() self.assert_graph_equal( - self.g, [(EX.s0, EX.p0, EX.o0), (EX.s0, EX.p0, EX.o0bis),] + self.g, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s0, EX.p0, EX.o0bis), + ], ) @@ -151,9 +229,19 @@ class TestAuditableStoreEmptyGraph(BaseTestAuditableStore): def test_add_commit(self): self.t.add((EX.s1, EX.p1, EX.o1)) - self.assert_graph_equal(self.t, [(EX.s1, EX.p1, EX.o1),]) + self.assert_graph_equal( + self.t, + [ + (EX.s1, EX.p1, EX.o1), + ], + ) self.t.commit() - self.assert_graph_equal(self.g, [(EX.s1, EX.p1, EX.o1),]) + self.assert_graph_equal( + self.g, + [ + (EX.s1, EX.p1, EX.o1), + ], + ) def test_add_rollback(self): self.t.add((EX.s1, EX.p1, EX.o1)) @@ -176,25 +264,45 @@ class TestAuditableStoreConccurent(BaseTestAuditableStore): def test_commit_commit(self): self.t1.commit() self.t2.commit() - self.assert_graph_equal(self.g, [(EX.s1, EX.p1, EX.o1), (EX.s2, EX.p2, EX.o2),]) + self.assert_graph_equal( + self.g, + [ + (EX.s1, EX.p1, EX.o1), + (EX.s2, EX.p2, EX.o2), + ], + ) def test_commit_rollback(self): self.t1.commit() self.t2.rollback() self.assert_graph_equal( - self.g, [(EX.s1, EX.p1, EX.o1), (EX.s0, EX.p0, EX.o0bis),] + self.g, + [ + (EX.s1, EX.p1, EX.o1), + (EX.s0, EX.p0, EX.o0bis), + ], ) def test_rollback_commit(self): self.t1.rollback() self.t2.commit() - self.assert_graph_equal(self.g, [(EX.s0, EX.p0, EX.o0), (EX.s2, EX.p2, EX.o2),]) + self.assert_graph_equal( + self.g, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s2, EX.p2, EX.o2), + ], + ) def test_rollback_rollback(self): self.t1.rollback() self.t2.rollback() self.assert_graph_equal( - self.g, [(EX.s0, EX.p0, EX.o0), (EX.s0, EX.p0, EX.o0bis),] + self.g, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s0, EX.p0, EX.o0bis), + ], ) @@ -214,33 +322,65 @@ class TestAuditableStoreEmbeded(BaseTestAuditableStore): def test_commit_commit(self): self.assert_graph_equal( - self.t2, [(EX.s0, EX.p0, EX.o0), (EX.s2, EX.p2, EX.o2),] + self.t2, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s2, EX.p2, EX.o2), + ], ) self.t2.commit() self.assert_graph_equal( - self.t1, [(EX.s0, EX.p0, EX.o0), (EX.s2, EX.p2, EX.o2),] + self.t1, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s2, EX.p2, EX.o2), + ], ) self.t1.commit() - self.assert_graph_equal(self.g, [(EX.s0, EX.p0, EX.o0), (EX.s2, EX.p2, EX.o2),]) + self.assert_graph_equal( + self.g, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s2, EX.p2, EX.o2), + ], + ) def test_commit_rollback(self): self.t2.commit() self.t1.rollback() self.assert_graph_equal( - self.g, [(EX.s0, EX.p0, EX.o0), (EX.s0, EX.p0, EX.o0bis),] + self.g, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s0, EX.p0, EX.o0bis), + ], ) def test_rollback_commit(self): self.t2.rollback() self.assert_graph_equal( - self.t1, [(EX.s0, EX.p0, EX.o0), (EX.s1, EX.p1, EX.o1),] + self.t1, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s1, EX.p1, EX.o1), + ], ) self.t1.commit() - self.assert_graph_equal(self.g, [(EX.s0, EX.p0, EX.o0), (EX.s1, EX.p1, EX.o1),]) + self.assert_graph_equal( + self.g, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s1, EX.p1, EX.o1), + ], + ) def test_rollback_rollback(self): self.t2.rollback() self.t1.rollback() self.assert_graph_equal( - self.g, [(EX.s0, EX.p0, EX.o0), (EX.s0, EX.p0, EX.o0bis),] + self.g, + [ + (EX.s0, EX.p0, EX.o0), + (EX.s0, EX.p0, EX.o0bis), + ], ) diff --git a/test/test_b64_binary.py b/test/test_b64_binary.py index b512f29d..84d8db78 100644 --- a/test/test_b64_binary.py +++ b/test/test_b64_binary.py @@ -1,12 +1,11 @@ # -*- coding: utf-8 -*- import unittest -import base64 +import base64 from rdflib import Literal, XSD class B64BinaryTestCase(unittest.TestCase): - def test_unicode(self): str1 = "Test utf-8 string éàë" # u b64string diff --git a/test/test_container.py b/test/test_container.py index ab98114d..48946efc 100644 --- a/test/test_container.py +++ b/test/test_container.py @@ -1,77 +1,88 @@ from rdflib.term import BNode
from rdflib.term import Literal
from rdflib import Graph
-from rdflib.container import *
+from rdflib.container import *
import unittest
class TestContainer(unittest.TestCase):
+ @classmethod
+ def setUpClass(cls):
+ cls.g = Graph()
+ cls.c1 = Bag(cls.g, BNode())
+ cls.c2 = Bag(
+ cls.g, BNode(), [Literal("1"), Literal("2"), Literal("3"), Literal("4")]
+ )
+ cls.c3 = Alt(
+ cls.g, BNode(), [Literal("1"), Literal("2"), Literal("3"), Literal("4")]
+ )
+ cls.c4 = Seq(
+ cls.g, BNode(), [Literal("1"), Literal("2"), Literal("3"), Literal("4")]
+ )
- @classmethod
- def setUpClass(cls):
- cls.g = Graph()
- cls.c1 = Bag(cls.g, BNode())
- cls.c2 = Bag(cls.g, BNode(), [Literal("1"), Literal("2"), Literal("3"), Literal("4")])
- cls.c3 = Alt(cls.g, BNode(), [Literal("1"), Literal("2"), Literal("3"), Literal("4")])
- cls.c4 = Seq(cls.g, BNode(), [Literal("1"), Literal("2"), Literal("3"), Literal("4")])
-
- def testA(self):
- self.assertEqual(len(self.c1) == 0, True)
+ def testA(self):
+ self.assertEqual(len(self.c1) == 0, True)
- def testB(self):
- self.assertEqual(len(self.c2) == 4, True)
+ def testB(self):
+ self.assertEqual(len(self.c2) == 4, True)
- def testC(self):
- self.c2.append(Literal("5"))
- del self.c2[2]
- self.assertEqual(len(self.c2) == 4, True)
+ def testC(self):
+ self.c2.append(Literal("5"))
+ del self.c2[2]
+ self.assertEqual(len(self.c2) == 4, True)
- def testD(self):
- self.assertEqual(self.c2.index(Literal("5")) == 4, True)
+ def testD(self):
+ self.assertEqual(self.c2.index(Literal("5")) == 4, True)
- def testE(self):
- self.assertEqual(self.c2[2] == Literal("3"), True)
+ def testE(self):
+ self.assertEqual(self.c2[2] == Literal("3"), True)
- def testF(self):
- self.c2[2] = Literal("9")
- self.assertEqual(self.c2[2] == Literal("9"), True)
+ def testF(self):
+ self.c2[2] = Literal("9")
+ self.assertEqual(self.c2[2] == Literal("9"), True)
- def testG(self):
- self.c2.clear()
- self.assertEqual(len(self.c2) == 0, True)
+ def testG(self):
+ self.c2.clear()
+ self.assertEqual(len(self.c2) == 0, True)
- def testH(self):
- self.c2.append_multiple([Literal("80"), Literal("90")])
- self.assertEqual(self.c2[1] == Literal("80"), True)
+ def testH(self):
+ self.c2.append_multiple([Literal("80"), Literal("90")])
+ self.assertEqual(self.c2[1] == Literal("80"), True)
- def testI(self):
- self.assertEqual(self.c2[2] == Literal("90"), True)
+ def testI(self):
+ self.assertEqual(self.c2[2] == Literal("90"), True)
- def testJ(self):
- self.assertEqual(len(self.c2) == 2, True)
+ def testJ(self):
+ self.assertEqual(len(self.c2) == 2, True)
- def testK(self):
- self.assertEqual(self.c2.end() == 2, True)
+ def testK(self):
+ self.assertEqual(self.c2.end() == 2, True)
- def testL(self):
- self.assertEqual(self.c3.anyone() in [Literal("1"), Literal("2"), Literal("3"), Literal("4")], True)
+ def testL(self):
+ self.assertEqual(
+ self.c3.anyone()
+ in [Literal("1"), Literal("2"), Literal("3"), Literal("4")],
+ True,
+ )
- def testM(self):
- self.c4.add_at_position(3, Literal("60"))
- self.assertEqual(len(self.c4) == 5, True)
+ def testM(self):
+ self.c4.add_at_position(3, Literal("60"))
+ self.assertEqual(len(self.c4) == 5, True)
- def testN(self):
- self.assertEqual(self.c4.index(Literal("60")) == 3, True)
+ def testN(self):
+ self.assertEqual(self.c4.index(Literal("60")) == 3, True)
- def testO(self):
- self.assertEqual(self.c4.index(Literal("3")) == 4, True)
+ def testO(self):
+ self.assertEqual(self.c4.index(Literal("3")) == 4, True)
- def testP(self):
- self.assertEqual(self.c4.index(Literal("4")) == 5, True)
-
- def testQ(self):
- self.assertEqual(self.c2.index(Literal("1000")) == 3, False) # there is no Literal("1000") in the Bag
+ def testP(self):
+ self.assertEqual(self.c4.index(Literal("4")) == 5, True)
+
+ def testQ(self):
+ self.assertEqual(
+ self.c2.index(Literal("1000")) == 3, False
+ ) # there is no Literal("1000") in the Bag
if __name__ == "__main__":
- unittest.main()
+ unittest.main()
diff --git a/test/test_conventions.py b/test/test_conventions.py index cecb0358..84fb0801 100644 --- a/test/test_conventions.py +++ b/test/test_conventions.py @@ -12,8 +12,7 @@ modules should all be lower-case initial class A(unittest.TestCase): - - def module_names(self, path=None, names=None, parent=''): + def module_names(self, path=None, names=None, parent=""): skip_as_ignorably_private = ["embeddedRDF", "OpenID", "DublinCore", "RDFVOC"] @@ -30,12 +29,17 @@ class A(unittest.TestCase): for importer, name, ispkg in pkgutil.iter_modules([path]): if ispkg: - result = self.module_names(path=os.path.join(path, name), - names=names, parent=name) + result = self.module_names( + path=os.path.join(path, name), names=names, parent=name + ) names.union(result) else: # namespaces are an exception to this rule - if name != name.lower() and name not in skip_as_ignorably_private and parent != 'namespace': + if ( + name != name.lower() + and name not in skip_as_ignorably_private + and parent != "namespace" + ): names.add(name) return names diff --git a/test/test_create_input_source.py b/test/test_create_input_source.py index 6fc05f9f..8c96de28 100644 --- a/test/test_create_input_source.py +++ b/test/test_create_input_source.py @@ -16,8 +16,8 @@ class ParserTestCase(unittest.TestCase): self.assertRaises( ValueError, create_input_source, - source='a', - location='b', + source="a", + location="b", ) diff --git a/test/test_csv2rdf.py b/test/test_csv2rdf.py index fee10a31..16cf678c 100644 --- a/test/test_csv2rdf.py +++ b/test/test_csv2rdf.py @@ -24,7 +24,9 @@ class CSV2RDFTest(unittest.TestCase): def test_csv2rdf_cli_fileout(self): _, fname = mkstemp() - completed = subprocess.run(["csv2rdf", "-o", fname, str(self.REALESTATE_FILE_PATH)], ) + completed = subprocess.run( + ["csv2rdf", "-o", fname, str(self.REALESTATE_FILE_PATH)], + ) self.assertEqual(completed.returncode, 0) with open(fname) as f: self.assertGreater(len(f.readlines()), 0) diff --git a/test/test_dawg.py b/test/test_dawg.py index b413acd0..c8af206d 100644 --- a/test/test_dawg.py +++ b/test/test_dawg.py @@ -38,6 +38,7 @@ from io import BytesIO from nose.tools import nottest, eq_ from nose import SkipTest + def eq(a, b, msg): return eq_(a, b, msg + ": (%r!=%r)" % (a, b)) @@ -426,16 +427,11 @@ def query_test(t): set(res2.vars), "Vars do not match: %r != %r" % (set(res.vars), set(res2.vars)), ) - assert bindingsCompatible(set(res), set(res2)), ( - "Bindings do not match: \nexpected:\n%s\n!=\ngot:\n%s" - % ( - res.serialize( - format="txt", namespace_manager=g.namespace_manager - ), - res2.serialize( - format="txt", namespace_manager=g.namespace_manager - ), - ) + assert bindingsCompatible( + set(res), set(res2) + ), "Bindings do not match: \nexpected:\n%s\n!=\ngot:\n%s" % ( + res.serialize(format="txt", namespace_manager=g.namespace_manager), + res2.serialize(format="txt", namespace_manager=g.namespace_manager), ) elif res.type == "ASK": eq( @@ -629,8 +625,13 @@ if __name__ == "__main__": % (now, i, success, f_sum, e_sum, skip, 100.0 * success / i) ) - earl_report = os.path.join(TEST_DIR, "../test_reports/rdflib_sparql-%s.ttl" % now.replace(":", "")) + earl_report = os.path.join( + TEST_DIR, "../test_reports/rdflib_sparql-%s.ttl" % now.replace(":", "") + ) report.serialize(earl_report, format="n3") - report.serialize(os.path.join(TEST_DIR, "../test_reports/rdflib_sparql-latest.ttl"), format="n3") + report.serialize( + os.path.join(TEST_DIR, "../test_reports/rdflib_sparql-latest.ttl"), + format="n3", + ) print("Wrote EARL-report to '%s'" % earl_report) diff --git a/test/test_empty_xml_base.py b/test/test_empty_xml_base.py index 12fd46a4..c4dcc768 100644 --- a/test/test_empty_xml_base.py +++ b/test/test_empty_xml_base.py @@ -44,10 +44,13 @@ class TestEmptyBase(unittest.TestCase): self.graph.parse(StringIO(test_data), publicID=baseUri, format="xml") def test_base_ref(self): - self.assertTrue(len(list(self.graph)), - "There should be at least one statement in the graph") - self.assertTrue((baseUri, RDF.type, FOAF.Document) in self.graph, - "There should be a triple with %s as the subject" % baseUri) + self.assertTrue( + len(list(self.graph)), "There should be at least one statement in the graph" + ) + self.assertTrue( + (baseUri, RDF.type, FOAF.Document) in self.graph, + "There should be a triple with %s as the subject" % baseUri, + ) class TestRelativeBase(unittest.TestCase): @@ -56,11 +59,14 @@ class TestRelativeBase(unittest.TestCase): self.graph.parse(StringIO(test_data2), publicID=baseUri2, format="xml") def test_base_ref(self): - self.assertTrue(len(self.graph), - "There should be at least one statement in the graph") - resolvedBase = URIRef('http://example.com/baz') - self.assertTrue((resolvedBase, RDF.type, FOAF.Document) in self.graph, - "There should be a triple with %s as the subject" % resolvedBase) + self.assertTrue( + len(self.graph), "There should be at least one statement in the graph" + ) + resolvedBase = URIRef("http://example.com/baz") + self.assertTrue( + (resolvedBase, RDF.type, FOAF.Document) in self.graph, + "There should be a triple with %s as the subject" % resolvedBase, + ) if __name__ == "__main__": diff --git a/test/test_finalnewline.py b/test/test_finalnewline.py index 59d7970b..e0e79032 100644 --- a/test/test_finalnewline.py +++ b/test/test_finalnewline.py @@ -24,7 +24,7 @@ def testFinalNewline(): if b"\n" not in v or (lines[-1] != b""): failed.add(p.name) # JSON-LD does not require a final newline (because JSON doesn't) - failed = failed.difference({'json-ld', 'application/ld+json'}) + failed = failed.difference({"json-ld", "application/ld+json"}) assert len(failed) == 0, "No final newline for formats: '%s'" % failed diff --git a/test/test_graph.py b/test/test_graph.py index 9f6d5d9b..08c112a5 100644 --- a/test/test_graph.py +++ b/test/test_graph.py @@ -272,10 +272,15 @@ class GraphTestCase(unittest.TestCase): self.graph.parse(data="rubbish") # Turtle - default - self.graph.parse(data="<http://example.com/a> <http://example.com/a> <http://example.com/a> .") + self.graph.parse( + data="<http://example.com/a> <http://example.com/a> <http://example.com/a> ." + ) # Turtle - format given - self.graph.parse(data="<http://example.com/a> <http://example.com/a> <http://example.com/a> .", format="turtle") + self.graph.parse( + data="<http://example.com/a> <http://example.com/a> <http://example.com/a> .", + format="turtle", + ) # RDF/XML - format given rdf = """<rdf:RDF @@ -309,12 +314,14 @@ class GraphTestCase(unittest.TestCase): self.graph.parse(location="http://www.w3.org/ns/adms.ttl") self.graph.parse(location="http://www.w3.org/ns/adms.rdf") except (URLError, HTTPError): - #this endpoint is currently not available, ignore this test. + # this endpoint is currently not available, ignore this test. pass try: # persistent Australian Government online RDF resource without a file-like ending - self.graph.parse(location="https://linked.data.gov.au/def/agrif?_format=text/turtle") + self.graph.parse( + location="https://linked.data.gov.au/def/agrif?_format=text/turtle" + ) except (URLError, HTTPError): # this endpoint is currently not available, ignore this test. pass diff --git a/test/test_graph_formula.py b/test/test_graph_formula.py index 52764628..14073054 100644 --- a/test/test_graph_formula.py +++ b/test/test_graph_formula.py @@ -133,7 +133,12 @@ def testFormulaStores(): pluginname = sys.argv[1] for s in plugin.plugins(pluginname, plugin.Store): - if s.name in ("Auditable", "Concurrent", "SPARQLStore", "SPARQLUpdateStore",): + if s.name in ( + "Auditable", + "Concurrent", + "SPARQLStore", + "SPARQLUpdateStore", + ): continue if not s.getClass().formula_aware: continue diff --git a/test/test_issue1003.py b/test/test_issue1003.py index 752bb536..cb8f465f 100644 --- a/test/test_issue1003.py +++ b/test/test_issue1003.py @@ -48,31 +48,23 @@ assert "@base <http://one.org/> ." in g2.serialize(format="turtle") g3 = Graph() g3 += g # @base should be in output, from serialization (two) -assert "@base <http://two.org/> ." in g3.serialize( - format="turtle", base=base_two -) +assert "@base <http://two.org/> ." in g3.serialize(format="turtle", base=base_two) # 4. base one set for graph, base two set for serialization, Graph one overrides g4 = Graph(base=base_one) g4 += g # @base should be in output, from graph (one) -assert "@base <http://two.org/> ." in g4.serialize( - format="turtle", base=base_two -) +assert "@base <http://two.org/> ." in g4.serialize(format="turtle", base=base_two) # just checking that the serialization setting (two) hasn't snuck through -assert "@base <http://one.org/> ." not in g4.serialize( - format="turtle", base=base_two -) +assert "@base <http://one.org/> ." not in g4.serialize(format="turtle", base=base_two) # 5. multiple serialization side effect checking g5 = Graph() g5 += g # @base should be in output, from serialization (two) -assert "@base <http://two.org/> ." in g5.serialize( - format="turtle", base=base_two -) +assert "@base <http://two.org/> ." in g5.serialize(format="turtle", base=base_two) # checking for side affects - no base now set for this serialization # @base should not be in output diff --git a/test/test_issue1043.py b/test/test_issue1043.py index 03def8c4..143514e7 100644 --- a/test/test_issue1043.py +++ b/test/test_issue1043.py @@ -7,7 +7,6 @@ from rdflib import Graph, Namespace, XSD, RDFS, Literal class TestIssue1043(unittest.TestCase):
-
def test_issue_1043(self):
expected = """@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@@ -19,8 +18,8 @@ class TestIssue1043(unittest.TestCase): capturedOutput = io.StringIO()
sys.stdout = capturedOutput
g = Graph()
- g.bind('xsd', XSD)
- g.bind('rdfs', RDFS)
+ g.bind("xsd", XSD)
+ g.bind("rdfs", RDFS)
n = Namespace("http://example.org/")
g.add((n.number, RDFS.label, Literal(0.00000004, datatype=XSD.decimal)))
g.print()
@@ -28,6 +27,5 @@ class TestIssue1043(unittest.TestCase): self.assertEqual(capturedOutput.getvalue(), expected)
-
if __name__ == "__main__":
- unittest.main()
\ No newline at end of file + unittest.main()
diff --git a/test/test_issue1141.py b/test/test_issue1141.py index 4fd5f232..572ab395 100644 --- a/test/test_issue1141.py +++ b/test/test_issue1141.py @@ -9,6 +9,7 @@ class TestIssue1141(unittest.TestCase): """ Tests is Turtle and TriG parsing works with a store with or without formula support """ + def test_issue_1141_1(self): file = b"@prefix : <http://example.com/> . :s :p :o ." diff --git a/test/test_issue1160.py b/test/test_issue1160.py index 19258be7..3aba0ecc 100644 --- a/test/test_issue1160.py +++ b/test/test_issue1160.py @@ -6,7 +6,7 @@ import rdflib from rdflib import ConjunctiveGraph from rdflib.parser import URLInputSource -QUERY = ''' +QUERY = """ SELECT DISTINCT ?g FROM NAMED <http://ns.example.com/named#> WHERE { @@ -14,7 +14,7 @@ WHERE { ?s ?p ?o . } } -''' +""" class NamedGraphWithFragmentTest(unittest.TestCase): @@ -22,11 +22,11 @@ class NamedGraphWithFragmentTest(unittest.TestCase): """Test that fragment part of the URL is not erased.""" graph = ConjunctiveGraph() - with mock.patch('rdflib.parser.URLInputSource') as load_mock: + with mock.patch("rdflib.parser.URLInputSource") as load_mock: # We have to expect an exception here. self.assertRaises(Exception, graph.query, QUERY) load_mock.assert_called_with( - rdflib.URIRef('http://ns.example.com/named#'), - 'nt', + rdflib.URIRef("http://ns.example.com/named#"), + "nt", ) diff --git a/test/test_issue161.py b/test/test_issue161.py index 5375742c..db15c9b3 100644 --- a/test/test_issue161.py +++ b/test/test_issue161.py @@ -25,6 +25,6 @@ class EntityTest(TestCase): g = ConjunctiveGraph() g.parse(data=turtle, format="turtle") # Shouldn't have got to here - s = g.serialize(format="turtle", encoding='latin-1') + s = g.serialize(format="turtle", encoding="latin-1") self.assertTrue(b"@prefix _9" not in s) diff --git a/test/test_issue184.py b/test/test_issue184.py index 7693dd1c..c2a39b3f 100644 --- a/test/test_issue184.py +++ b/test/test_issue184.py @@ -6,8 +6,8 @@ from rdflib.graph import ConjunctiveGraph def test_escaping_of_triple_doublequotes(): """ Issue 186 - Check escaping of multiple doublequotes. - A serialization/deserialization roundtrip of a certain class of - Literals fails when there are both, newline characters and multiple subsequent + A serialization/deserialization roundtrip of a certain class of + Literals fails when there are both, newline characters and multiple subsequent quotation marks in the lexical form of the Literal. In this case invalid N3 is emitted by the serializer, which in turn cannot be parsed correctly. """ diff --git a/test/test_issue190.py b/test/test_issue190.py index 4f3e7f84..51191084 100644 --- a/test/test_issue190.py +++ b/test/test_issue190.py @@ -42,7 +42,6 @@ test_string1 = """\ Betriebsnummer der Einzugsstelle:\nKnappschaft\n980 0000 6\nWICHTIGES DOKUMENT - SORGFÄLTIG AUFBEWAHREN!\n """ - @unittest.skipIf(True, "Known issue with newlines in text") def test1(): meta1 = meta.encode("utf-8") % test_string1.encode("utf-8") @@ -59,6 +58,7 @@ Knappschaft WICHTIGES DOKUMENT - SORGFÄLTIG AUFBEWAHREN! """ + @unittest.skipIf(True, "Known issue with newlines in text") def test2(): meta2 = meta.encode("utf-8") % test_string2.encode("utf-8") diff --git a/test/test_issue200.py b/test/test_issue200.py index 8dc5433c..8104747d 100644 --- a/test/test_issue200.py +++ b/test/test_issue200.py @@ -34,9 +34,11 @@ class TestRandomSeedInFork(unittest.TestCase): w.write(cb) w.close() os._exit(0) - assert txt != str(pb1), ( - "Parent process BNode id: " - + "%s, child process BNode id: %s" % (txt, str(pb1)) + assert txt != str( + pb1 + ), "Parent process BNode id: " + "%s, child process BNode id: %s" % ( + txt, + str(pb1), ) diff --git a/test/test_issue209.py b/test/test_issue209.py index 083d763d..61fd6ff2 100644 --- a/test/test_issue209.py +++ b/test/test_issue209.py @@ -12,8 +12,7 @@ def makeNode(): class TestRandomSeedInThread(unittest.TestCase): def test_bnode_id_gen_in_thread(self): - """ - """ + """ """ th = threading.Thread(target=makeNode) th.daemon = True th.start() diff --git a/test/test_issue381.py b/test/test_issue381.py index a48cafe7..a5997515 100644 --- a/test/test_issue381.py +++ b/test/test_issue381.py @@ -13,7 +13,11 @@ def test_no_spurious_semicolon(): """ expected = Graph() expected.addN( - t + (expected,) for t in [(NS.a, NS.b, NS.c), (NS.a, NS.d, NS.e),] + t + (expected,) + for t in [ + (NS.a, NS.b, NS.c), + (NS.a, NS.d, NS.e), + ] ) got = Graph().query(sparql).graph assert isomorphic(got, expected), got.serialize(format="turtle") @@ -28,7 +32,11 @@ def test_one_spurious_semicolon(): """ expected = Graph() expected.addN( - t + (expected,) for t in [(NS.a, NS.b, NS.c), (NS.a, NS.d, NS.e),] + t + (expected,) + for t in [ + (NS.a, NS.b, NS.c), + (NS.a, NS.d, NS.e), + ] ) got = Graph().query(sparql).graph assert isomorphic(got, expected), got.serialize(format="turtle") @@ -43,7 +51,11 @@ def test_one_spurious_semicolon_no_perdiod(): """ expected = Graph() expected.addN( - t + (expected,) for t in [(NS.a, NS.b, NS.c), (NS.a, NS.d, NS.e),] + t + (expected,) + for t in [ + (NS.a, NS.b, NS.c), + (NS.a, NS.d, NS.e), + ] ) got = Graph().query(sparql).graph assert isomorphic(got, expected), got.serialize(format="turtle") @@ -58,7 +70,11 @@ def test_two_spurious_semicolons_no_period(): """ expected = Graph() expected.addN( - t + (expected,) for t in [(NS.a, NS.b, NS.c), (NS.a, NS.d, NS.e),] + t + (expected,) + for t in [ + (NS.a, NS.b, NS.c), + (NS.a, NS.d, NS.e), + ] ) got = Graph().query(sparql).graph assert isomorphic(got, expected), got.serialize(format="turtle") @@ -73,7 +89,11 @@ def test_one_spurious_semicolons_bnode(): """ expected = Graph() expected.addN( - t + (expected,) for t in [(BNode("a"), NS.b, NS.c), (BNode("a"), NS.d, NS.e),] + t + (expected,) + for t in [ + (BNode("a"), NS.b, NS.c), + (BNode("a"), NS.d, NS.e), + ] ) got = Graph().query(sparql).graph assert isomorphic(got, expected), got.serialize(format="turtle") @@ -95,7 +115,11 @@ def test_pathological(): expected = Graph() expected.addN( t + (expected,) - for t in [(NS.a, NS.b, NS.c), (NS.a, NS.d, NS.e), (NS.a, NS.f, NS.g),] + for t in [ + (NS.a, NS.b, NS.c), + (NS.a, NS.d, NS.e), + (NS.a, NS.f, NS.g), + ] ) got = Graph().query(sparql).graph assert isomorphic(got, expected), got.serialize(format="turtle") @@ -112,7 +136,11 @@ def test_mixing_spurious_semicolons_and_commas(): expected = Graph() expected.addN( t + (expected,) - for t in [(NS.a, NS.b, NS.c), (NS.a, NS.d, NS.e), (NS.a, NS.d, NS.f),] + for t in [ + (NS.a, NS.b, NS.c), + (NS.a, NS.d, NS.e), + (NS.a, NS.d, NS.f), + ] ) got = Graph().query(sparql).graph assert isomorphic(got, expected), got.serialize(format="turtle") diff --git a/test/test_issue801.py b/test/test_issue801.py index 69573352..431ddcb6 100644 --- a/test/test_issue801.py +++ b/test/test_issue801.py @@ -4,16 +4,18 @@ Issue 801 - Problem with prefixes created for URIs containing %20 from rdflib import Namespace, Graph, BNode, Literal import unittest -class TestIssue801(unittest.TestCase): +class TestIssue801(unittest.TestCase): def test_issue_801(self): g = Graph() - example = Namespace('http://example.org/') - g.bind('', example) + example = Namespace("http://example.org/") + g.bind("", example) node = BNode() - g.add((node, example['first%20name'], Literal('John'))) - self.assertEqual(g.serialize(format="turtle").split("\n")[-3], - '[] :first%20name "John" .') + g.add((node, example["first%20name"], Literal("John"))) + self.assertEqual( + g.serialize(format="turtle").split("\n")[-3], '[] :first%20name "John" .' + ) + if __name__ == "__main__": unittest.main() diff --git a/test/test_issue910.py b/test/test_issue910.py index ee82643c..bd0f9189 100644 --- a/test/test_issue910.py +++ b/test/test_issue910.py @@ -3,23 +3,23 @@ import unittest class TestIssue910(unittest.TestCase):
- def testA(self):
- g = Graph()
- q = g.query(
- """
+ def testA(self):
+ g = Graph()
+ q = g.query(
+ """
SELECT * {
{ BIND ("a" AS ?a) }
UNION
{ BIND ("a" AS ?a) }
}
"""
- )
- self.assertEqual(len(q) == 2, True)
+ )
+ self.assertEqual(len(q) == 2, True)
- def testB(self):
- g = Graph()
- q = g.query(
- """
+ def testB(self):
+ g = Graph()
+ q = g.query(
+ """
SELECT * {
{ BIND ("a" AS ?a) }
UNION
@@ -28,13 +28,13 @@ class TestIssue910(unittest.TestCase): { SELECT ("a" AS ?a) {} }
}
"""
- )
- self.assertEqual(len(q) == 3, True)
+ )
+ self.assertEqual(len(q) == 3, True)
- def testC(self):
- g = Graph()
- q = g.query(
- """
+ def testC(self):
+ g = Graph()
+ q = g.query(
+ """
SELECT * {
{ BIND ("a" AS ?a) }
UNION
@@ -43,13 +43,13 @@ class TestIssue910(unittest.TestCase): { SELECT ("b" AS ?a) {} }
}
"""
- )
- self.assertEqual(len(q) == 3, True)
+ )
+ self.assertEqual(len(q) == 3, True)
- def testD(self):
- g = Graph()
- q = g.query(
- """SELECT * {
+ def testD(self):
+ g = Graph()
+ q = g.query(
+ """SELECT * {
{ BIND ("a" AS ?a) }
UNION
{ VALUES ?a { "b" } }
@@ -57,9 +57,9 @@ class TestIssue910(unittest.TestCase): { SELECT ("c" AS ?a) {} }
}
"""
- )
- self.assertEqual(len(q) == 3, True)
+ )
+ self.assertEqual(len(q) == 3, True)
if __name__ == "__main__":
- unittest.main()
+ unittest.main()
diff --git a/test/test_issue977.py b/test/test_issue977.py index 26f61c5a..088f5ca0 100644 --- a/test/test_issue977.py +++ b/test/test_issue977.py @@ -4,27 +4,38 @@ from rdflib import Graph, XSD, RDF, RDFS, URIRef, Literal class TestIssue977(unittest.TestCase): - def setUp(self): self.graph = Graph() # Bind prefixes. - self.graph.bind('isbn', 'urn:isbn:') - self.graph.bind('webn', 'http://w3c.org/example/isbn/') + self.graph.bind("isbn", "urn:isbn:") + self.graph.bind("webn", "http://w3c.org/example/isbn/") # Populate graph. - self.graph.add((URIRef('urn:isbn:1503280780'), RDFS.label, Literal('Moby Dick'))) - self.graph.add((URIRef('http://w3c.org/example/isbn/1503280780'), RDFS.label, Literal('Moby Dick'))) + self.graph.add( + (URIRef("urn:isbn:1503280780"), RDFS.label, Literal("Moby Dick")) + ) + self.graph.add( + ( + URIRef("http://w3c.org/example/isbn/1503280780"), + RDFS.label, + Literal("Moby Dick"), + ) + ) def test_namespace_manager(self): - assert 'isbn', 'urn:isbn:' in tuple(self.graph.namespaces()) - assert 'webn', 'http://w3c.org/example/isbn/' in tuple(self.graph.namespaces()) + assert "isbn", "urn:isbn:" in tuple(self.graph.namespaces()) + assert "webn", "http://w3c.org/example/isbn/" in tuple(self.graph.namespaces()) def test_turtle_serialization(self): - serialization = self.graph.serialize(None, format='turtle') - print(f'Test Issue 977, serialization output:\n---\n{serialization}---') + serialization = self.graph.serialize(None, format="turtle") + print(f"Test Issue 977, serialization output:\n---\n{serialization}---") # Test serialization. - assert '@prefix webn:' in serialization, "Prefix webn not found in serialization!" - assert '@prefix isbn:' in serialization, "Prefix isbn not found in serialization!" + assert ( + "@prefix webn:" in serialization + ), "Prefix webn not found in serialization!" + assert ( + "@prefix isbn:" in serialization + ), "Prefix isbn not found in serialization!" if __name__ == "__main__": - unittest.main() + unittest.main() diff --git a/test/test_memory_store.py b/test/test_memory_store.py index ad46d6c0..41b60356 100644 --- a/test/test_memory_store.py +++ b/test/test_memory_store.py @@ -1,8 +1,13 @@ import unittest import rdflib -rdflib.plugin.register("SimpleMemory", rdflib.store.Store, "rdflib.plugins.stores.memory", "SimpleMemory") -rdflib.plugin.register("Memory", rdflib.store.Store, "rdflib.plugins.stores.memory", "Memory") +rdflib.plugin.register( + "SimpleMemory", rdflib.store.Store, "rdflib.plugins.stores.memory", "SimpleMemory" +) +rdflib.plugin.register( + "Memory", rdflib.store.Store, "rdflib.plugins.stores.memory", "Memory" +) + class SimpleStoreTestCase(unittest.TestCase): def test_memory_store(self): @@ -26,6 +31,7 @@ class SimpleStoreTestCase(unittest.TestCase): self.assertTrue(len(g) == 1) g.serialize() + class MemoryStoreTestCase(unittest.TestCase): def test_memory_store(self): g = rdflib.Graph("Memory") diff --git a/test/test_n3.py b/test/test_n3.py index 8df2c891..3632b0b6 100644 --- a/test/test_n3.py +++ b/test/test_n3.py @@ -165,7 +165,7 @@ foo-bar:Ex foo-bar:name "Test" . """ Make sure n3 parser does not choke on UTF-8 BOM """ g = Graph() - n3_path = os.path.relpath(os.path.join(TEST_DIR, 'n3/issue156.n3', os.curdir)) + n3_path = os.path.relpath(os.path.join(TEST_DIR, "n3/issue156.n3", os.curdir)) g.parse(n3_path, format="n3") def testIssue999(self): diff --git a/test/test_namespace.py b/test/test_namespace.py index 9f0b98b9..23fdb1e2 100644 --- a/test/test_namespace.py +++ b/test/test_namespace.py @@ -5,8 +5,16 @@ from warnings import warn from rdflib import DCTERMS from rdflib.graph import Graph -from rdflib.namespace import FOAF, RDF, RDFS, SH, DefinedNamespaceMeta, Namespace, \ - ClosedNamespace, URIPattern +from rdflib.namespace import ( + FOAF, + RDF, + RDFS, + SH, + DefinedNamespaceMeta, + Namespace, + ClosedNamespace, + URIPattern, +) from rdflib.term import URIRef @@ -27,13 +35,13 @@ class NamespaceTest(unittest.TestCase): self.assertEqual(f"{self.ns_str}a", f"{self.ns.a}") def test_dcterms_title(self): - self.assertEqual(DCTERMS.title, URIRef(DCTERMS + 'title')) + self.assertEqual(DCTERMS.title, URIRef(DCTERMS + "title")) def test_iri(self): - prefix = u'http://jörn.loves.encoding.problems/' + prefix = "http://jörn.loves.encoding.problems/" ns = Namespace(prefix) self.assertEqual(ns, str(prefix)) - self.assert_(ns[u'jörn'].startswith(ns)) + self.assert_(ns["jörn"].startswith(ns)) class ClosedNamespaceTest(unittest.TestCase): @@ -164,7 +172,7 @@ class NamespacePrefixTest(unittest.TestCase): URIRef("http://example.com/baz"), ) ) - n3 = g.serialize(format="n3", encoding='latin-1') + n3 = g.serialize(format="n3", encoding="latin-1") # Gunnar disagrees that this is right: # self.assertTrue("<http://example.com/foo> ns1:bar <http://example.com/baz> ." in n3) # as this is much prettier, and ns1 is already defined: @@ -183,8 +191,7 @@ class NamespacePrefixTest(unittest.TestCase): n3 = g.serialize(format="n3", encoding="latin-1") self.assertTrue( - b"<http://example1.com/foo> ns1:bar <http://example3.com/baz> ." - in n3 + b"<http://example1.com/foo> ns1:bar <http://example3.com/baz> ." in n3 ) def test_closed_namespace(self): @@ -217,14 +224,21 @@ class NamespacePrefixTest(unittest.TestCase): def test_contains_method(self): """Tests for Namespace.__contains__() methods.""" - ref = URIRef('http://www.w3.org/ns/shacl#Info') - self.assertTrue(type(SH) == DefinedNamespaceMeta, f"SH no longer a DefinedNamespaceMeta (instead it is now {type(SH)}, update test.") + ref = URIRef("http://www.w3.org/ns/shacl#Info") + self.assertTrue( + type(SH) == DefinedNamespaceMeta, + f"SH no longer a DefinedNamespaceMeta (instead it is now {type(SH)}, update test.", + ) self.assertTrue(ref in SH, "sh:Info not in SH") - ref = URIRef('http://www.w3.org/2000/01/rdf-schema#label') - self.assertTrue(ref in RDFS, "ClosedNamespace(RDFS) does not include rdfs:label") - ref = URIRef('http://www.w3.org/2000/01/rdf-schema#example') - self.assertFalse(ref in RDFS, "ClosedNamespace(RDFS) includes out-of-ns member rdfs:example") + ref = URIRef("http://www.w3.org/2000/01/rdf-schema#label") + self.assertTrue( + ref in RDFS, "ClosedNamespace(RDFS) does not include rdfs:label" + ) + ref = URIRef("http://www.w3.org/2000/01/rdf-schema#example") + self.assertFalse( + ref in RDFS, "ClosedNamespace(RDFS) includes out-of-ns member rdfs:example" + ) - ref = URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type') + ref = URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type") self.assertTrue(ref in RDF, "_RDFNamespace does not include rdf:type") diff --git a/test/test_normalizedString.py b/test/test_normalizedString.py index 759df09a..5c11c107 100644 --- a/test/test_normalizedString.py +++ b/test/test_normalizedString.py @@ -5,24 +5,29 @@ from rdflib.namespace import XSD class NormalizedStringTest(unittest.TestCase): - def test1(self): lit2 = Literal("\two\nw", datatype=XSD.normalizedString) lit = Literal("\two\nw", datatype=XSD.string) self.assertFalse(str(lit) == str(lit2)) def test2(self): - lit = Literal("\tBeing a Doctor Is\n\ta Full-Time Job\r", datatype=XSD.normalizedString) + lit = Literal( + "\tBeing a Doctor Is\n\ta Full-Time Job\r", datatype=XSD.normalizedString + ) st = Literal(" Being a Doctor Is a Full-Time Job ", datatype=XSD.string) self.assertFalse(Literal.eq(st, lit)) self.assertEqual(str(lit), str(st)) def test3(self): lit = Literal("hey\nthere", datatype=XSD.normalizedString).n3() - self.assertTrue(lit == "\"hey there\"^^<http://www.w3.org/2001/XMLSchema#normalizedString>") + self.assertTrue( + lit == '"hey there"^^<http://www.w3.org/2001/XMLSchema#normalizedString>' + ) def test4(self): - lit = Literal("hey\nthere\ta tab\rcarriage return", datatype=XSD.normalizedString) + lit = Literal( + "hey\nthere\ta tab\rcarriage return", datatype=XSD.normalizedString + ) expected = Literal("""hey there a tab carriage return""", datatype=XSD.string) self.assertEqual(str(lit), str(expected)) diff --git a/test/test_nquads.py b/test/test_nquads.py index 5dae133c..bb3234d6 100644 --- a/test/test_nquads.py +++ b/test/test_nquads.py @@ -9,7 +9,9 @@ TEST_BASE = "test/nquads.rdflib" class NQuadsParserTest(unittest.TestCase): def _load_example(self): g = ConjunctiveGraph() - nq_path = os.path.relpath(os.path.join(TEST_DIR, 'nquads.rdflib/example.nquads'), os.curdir) + nq_path = os.path.relpath( + os.path.join(TEST_DIR, "nquads.rdflib/example.nquads"), os.curdir + ) with open(nq_path, "rb") as data: g.parse(data, format="nquads") return g @@ -39,7 +41,9 @@ class NQuadsParserTest(unittest.TestCase): def test_context_is_optional(self): g = ConjunctiveGraph() - nq_path = os.path.relpath(os.path.join(TEST_DIR, 'nquads.rdflib/test6.nq'), os.curdir) + nq_path = os.path.relpath( + os.path.join(TEST_DIR, "nquads.rdflib/test6.nq"), os.curdir + ) with open(nq_path, "rb") as data: g.parse(data, format="nquads") assert len(g) > 0 @@ -57,9 +61,7 @@ class NQuadsParserTest(unittest.TestCase): g.get_context(uri2).add((bob, likes, pizza)) s = g.serialize(format="nquads", encoding="latin-1") - self.assertEqual( - len([x for x in s.split(b"\n") if x.strip()]), 2 - ) + self.assertEqual(len([x for x in s.split(b"\n") if x.strip()]), 2) g2 = ConjunctiveGraph() g2.parse(data=s, format="nquads") @@ -74,7 +76,9 @@ class NQuadsParserTest(unittest.TestCase): class BnodeContextTest(unittest.TestCase): def setUp(self): self.data = open("test/nquads.rdflib/bnode_context.nquads", "rb") - self.data_obnodes = open("test/nquads.rdflib/bnode_context_obj_bnodes.nquads", "rb") + self.data_obnodes = open( + "test/nquads.rdflib/bnode_context_obj_bnodes.nquads", "rb" + ) def tearDown(self): self.data.close() diff --git a/test/test_nt_misc.py b/test/test_nt_misc.py index 2158ced4..9e34be2d 100644 --- a/test/test_nt_misc.py +++ b/test/test_nt_misc.py @@ -10,7 +10,7 @@ from test import TEST_DIR log = logging.getLogger(__name__) -NT_PATH = os.path.relpath(os.path.join(TEST_DIR, 'nt'), os.curdir) +NT_PATH = os.path.relpath(os.path.join(TEST_DIR, "nt"), os.curdir) def nt_file(fn): @@ -21,8 +21,8 @@ class NTTestCase(unittest.TestCase): def testIssue859(self): graphA = Graph() graphB = Graph() - graphA.parse(nt_file('quote-01.nt'), format="ntriples") - graphB.parse(nt_file('quote-02.nt'), format="ntriples") + graphA.parse(nt_file("quote-01.nt"), format="ntriples") + graphB.parse(nt_file("quote-02.nt"), format="ntriples") for subjectA, predicateA, objA in graphA: for subjectB, predicateB, objB in graphB: self.assertEqual(subjectA, subjectB) @@ -46,14 +46,13 @@ class NTTestCase(unittest.TestCase): fname = "test/nt/lists-02.nt" g1 = Graph() with open(fname, "r") as f: - g1.parse(f, format='nt') + g1.parse(f, format="nt") self.assertEqual(14, len(g1)) g2 = Graph() with open(fname, "rb") as fb: - g2.parse(fb, format='nt') + g2.parse(fb, format="nt") self.assertEqual(14, len(g2)) - def testIssue1144_w3c(self): fname = "test/nt/lists-02.nt" sink1 = ntriples.NTGraphSink(Graph()) @@ -67,7 +66,6 @@ class NTTestCase(unittest.TestCase): p2.parse(f) self.assertEqual(14, len(sink2.g)) - def test_sink(self): s = ntriples.DummySink() self.assertTrue(s.length == 0) @@ -120,7 +118,7 @@ class NTTestCase(unittest.TestCase): p = ntriples.W3CNTriplesParser() data = 3 self.assertRaises(ntriples.ParseError, p.parsestring, data) - with open(nt_file('lists-02.nt'), "r") as f: + with open(nt_file("lists-02.nt"), "r") as f: data = f.read() p = ntriples.W3CNTriplesParser() res = p.parsestring(data) @@ -168,28 +166,36 @@ class BNodeContextTestCase(unittest.TestCase): my_sink = FakeSink() bnode_context = dict() p = ntriples.W3CNTriplesParser(my_sink, bnode_context=bnode_context) - p.parsestring(''' + p.parsestring( + """ _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000001> . - ''') + """ + ) q = ntriples.W3CNTriplesParser(my_sink, bnode_context=bnode_context) - q.parsestring(''' + q.parsestring( + """ _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000002> . - ''') + """ + ) self.assertEqual(len(my_sink.subs), 1) def test_bnode_distinct_across_instances(self): my_sink = FakeSink() p = ntriples.W3CNTriplesParser(my_sink) - p.parsestring(''' + p.parsestring( + """ _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000001> . - ''') + """ + ) q = ntriples.W3CNTriplesParser(my_sink) - q.parsestring(''' + q.parsestring( + """ _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000002> . - ''') + """ + ) self.assertEqual(len(my_sink.subs), 2) @@ -197,13 +203,19 @@ class BNodeContextTestCase(unittest.TestCase): my_sink = FakeSink() p = ntriples.W3CNTriplesParser(my_sink) - p.parsestring(''' + p.parsestring( + """ _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000001> . - ''', bnode_context=dict()) + """, + bnode_context=dict(), + ) - p.parsestring(''' + p.parsestring( + """ _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000002> . - ''', bnode_context=dict()) + """, + bnode_context=dict(), + ) self.assertEqual(len(my_sink.subs), 2) @@ -211,13 +223,17 @@ class BNodeContextTestCase(unittest.TestCase): my_sink = FakeSink() p = ntriples.W3CNTriplesParser(my_sink) - p.parsestring(''' + p.parsestring( + """ _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000001> . - ''') + """ + ) - p.parsestring(''' + p.parsestring( + """ _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000002> . - ''') + """ + ) self.assertEqual(len(my_sink.subs), 1) @@ -226,14 +242,20 @@ class BNodeContextTestCase(unittest.TestCase): bnode_ctx = dict() p = ntriples.W3CNTriplesParser(my_sink) - p.parsestring(''' + p.parsestring( + """ _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000001> . - ''', bnode_context=bnode_ctx) + """, + bnode_context=bnode_ctx, + ) q = ntriples.W3CNTriplesParser(my_sink) - q.parsestring(''' + q.parsestring( + """ _:0 <http://purl.obolibrary.org/obo/RO_0002350> <http://www.gbif.org/species/0000002> . - ''', bnode_context=bnode_ctx) + """, + bnode_context=bnode_ctx, + ) self.assertEqual(len(my_sink.subs), 1) diff --git a/test/test_parse_file_guess_format.py b/test/test_parse_file_guess_format.py index b4085376..b086ade7 100644 --- a/test/test_parse_file_guess_format.py +++ b/test/test_parse_file_guess_format.py @@ -30,5 +30,5 @@ class FileParserGuessFormatTest(unittest.TestCase): g.parse(str(newpath)) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/test/test_parser_reads_from_pathlike_object.py b/test/test_parser_reads_from_pathlike_object.py index 2d2114ca..3a671073 100644 --- a/test/test_parser_reads_from_pathlike_object.py +++ b/test/test_parser_reads_from_pathlike_object.py @@ -14,7 +14,7 @@ def test_reading_from_path_object(): with tempfile.TemporaryDirectory() as td: sample_file = Path(td) / "sample.xml" - open(str(sample_file), 'w').write(xml_sample) + open(str(sample_file), "w").write(xml_sample) g = rdflib.Graph() g.parse(sample_file, publicID="") diff --git a/test/test_roundtrip.py b/test/test_roundtrip.py index 5edda39c..2928eacd 100644 --- a/test/test_roundtrip.py +++ b/test/test_roundtrip.py @@ -38,14 +38,14 @@ SKIP = [ ("trix", "test/n3/strquot.n3"), # contains charachters forbidden by the xml spec ("xml", "test/n3/strquot.n3"), # contains charachters forbidden by the xml spec ("json-ld", "test/nt/keywords-04.nt"), # known NT->JSONLD problem - ('json-ld', 'test/n3/example-misc.n3'), # known N3->JSONLD problem - ('json-ld', 'test/n3/n3-writer-test-16.n3'), # known N3->JSONLD problem - ('json-ld', 'test/n3/rdf-test-11.n3'), # known N3->JSONLD problem - ('json-ld', 'test/n3/rdf-test-28.n3'), # known N3->JSONLD problem - ('json-ld', 'test/n3/n3-writer-test-26.n3'), # known N3->JSONLD problem - ('json-ld', 'test/n3/n3-writer-test-28.n3'), # known N3->JSONLD problem - ('json-ld', 'test/n3/n3-writer-test-22.n3'), # known N3->JSONLD problem - ('json-ld', 'test/n3/rdf-test-21.n3'), # known N3->JSONLD problem + ("json-ld", "test/n3/example-misc.n3"), # known N3->JSONLD problem + ("json-ld", "test/n3/n3-writer-test-16.n3"), # known N3->JSONLD problem + ("json-ld", "test/n3/rdf-test-11.n3"), # known N3->JSONLD problem + ("json-ld", "test/n3/rdf-test-28.n3"), # known N3->JSONLD problem + ("json-ld", "test/n3/n3-writer-test-26.n3"), # known N3->JSONLD problem + ("json-ld", "test/n3/n3-writer-test-28.n3"), # known N3->JSONLD problem + ("json-ld", "test/n3/n3-writer-test-22.n3"), # known N3->JSONLD problem + ("json-ld", "test/n3/rdf-test-21.n3"), # known N3->JSONLD problem ] diff --git a/test/test_slice.py b/test/test_slice.py index 887791ed..7d2ebef3 100644 --- a/test/test_slice.py +++ b/test/test_slice.py @@ -5,10 +5,10 @@ import unittest class GraphSlice(unittest.TestCase): def testSlice(self): """ - We pervert the slice object, - and use start, stop, step as subject, predicate, object + We pervert the slice object, + and use start, stop, step as subject, predicate, object - all operations return generators over full triples + all operations return generators over full triples """ def sl(x, y): diff --git a/test/test_sparql.py b/test/test_sparql.py index 6454e7ef..d6e541e1 100644 --- a/test/test_sparql.py +++ b/test/test_sparql.py @@ -118,7 +118,6 @@ def test_bindings(): layer_0 = sparql.Bindings(d={"v": 1, "bar": 2}) layer_1 = sparql.Bindings(outer=layer_0, d={"v": 3}) - assert layer_0["v"] == 1 assert layer_1["v"] == 3 assert layer_1["bar"] == 2 @@ -131,36 +130,84 @@ def test_bindings(): # but is kept for compatibility for now. assert len(layer_1) == 3 - + def test_named_filter_graph_query(): g = ConjunctiveGraph() - g.namespace_manager.bind('rdf', RDF) - g.namespace_manager.bind('rdfs', RDFS) - ex = Namespace('https://ex.com/') - g.namespace_manager.bind('ex', ex) - g.get_context(ex.g1).parse(format="turtle", data=f""" + g.namespace_manager.bind("rdf", RDF) + g.namespace_manager.bind("rdfs", RDFS) + ex = Namespace("https://ex.com/") + g.namespace_manager.bind("ex", ex) + g.get_context(ex.g1).parse( + format="turtle", + data=f""" PREFIX ex: <{str(ex)}> PREFIX rdfs: <{str(RDFS)}> ex:Boris rdfs:label "Boris" . ex:Susan rdfs:label "Susan" . - """) - g.get_context(ex.g2).parse(format="turtle", data=f""" + """, + ) + g.get_context(ex.g2).parse( + format="turtle", + data=f""" PREFIX ex: <{str(ex)}> ex:Boris a ex:Person . - """) - - 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 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('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('Susan'),)] + """, + ) + + 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 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("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("Susan"),)] + ) def test_txtresult(): diff --git a/test/test_sparql_agg_distinct.py b/test/test_sparql_agg_distinct.py index 39d6eb95..7c11bf6e 100644 --- a/test/test_sparql_agg_distinct.py +++ b/test/test_sparql_agg_distinct.py @@ -20,7 +20,10 @@ def test_group_concat_distinct(): assert results[0][2] == "1", results[0][2] # still check the whole result, to be on the safe side - assert results == [["x1", 10, "1"], ["x2", 20, "2"],], results + assert results == [ + ["x1", 10, "1"], + ["x2", 20, "2"], + ], results def test_sum_distinct(): @@ -32,7 +35,10 @@ def test_sum_distinct(): assert results[0][2] == 1, results[0][2] # still check the whole result, to be on the safe side - assert results == [["x1", 10, 1], ["x2", 20, 2],], results + assert results == [ + ["x1", 10, 1], + ["x2", 20, 2], + ], results def test_avg_distinct(): @@ -55,7 +61,10 @@ def test_avg_distinct(): assert results[0][2] == 2, results[0][2] # still check the whole result, to be on the safe side - assert results == [["x1", 10, 2], ["x2", 20, 2],], results + assert results == [ + ["x1", 10, 2], + ["x2", 20, 2], + ], results def test_count_distinct(): diff --git a/test/test_sparql_datetime.py b/test/test_sparql_datetime.py index d4b2b676..a771b63a 100644 --- a/test/test_sparql_datetime.py +++ b/test/test_sparql_datetime.py @@ -1,4 +1,4 @@ -from rdflib import Graph, URIRef, Literal, BNode,XSD +from rdflib import Graph, URIRef, Literal, BNode, XSD from rdflib.plugins.sparql import prepareQuery from rdflib.compare import isomorphic import rdflib @@ -6,10 +6,11 @@ from nose.tools import eq_ from pprint import pprint import io + def test_dateTime_dateTime_subs_issue(): """ - Test for query mentioned in the Issue #629 - https://github.com/RDFLib/rdflib/issues/629 + Test for query mentioned in the Issue #629 + https://github.com/RDFLib/rdflib/issues/629 """ @@ -40,34 +41,41 @@ def test_dateTime_dateTime_subs_issue(): graph1 = Graph() f = io.StringIO(data1) - graph1.parse(f, format='n3') + graph1.parse(f, format="n3") - result = graph1.query(""" + result = graph1.query( + """ SELECT ?c ?duration WHERE { ?c :start ?start; :end ?end. BIND(?end - ?start AS ?duration) } - """) + """ + ) - answer=list(result) - answer=sorted(answer) + answer = list(result) + answer = sorted(answer) # expected result will be a list of 2 tuples - # FirstElement of these tuples will be a node with a path of directory of saved project - # Second Element while represent the actual durations + # FirstElement of these tuples will be a node with a path of directory of saved project + # Second Element while represent the actual durations - expectedFirstDuration=rdflib.term.Literal('P1DT1M', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#duration')) - expectedSecondDuration=rdflib.term.Literal('PT25M', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#duration')) + expectedFirstDuration = rdflib.term.Literal( + "P1DT1M", + datatype=rdflib.term.URIRef("http://www.w3.org/2001/XMLSchema#duration"), + ) + expectedSecondDuration = rdflib.term.Literal( + "PT25M", + datatype=rdflib.term.URIRef("http://www.w3.org/2001/XMLSchema#duration"), + ) - - eq_(answer[0][1],expectedFirstDuration) - eq_(answer[1][1],expectedSecondDuration) + eq_(answer[0][1], expectedFirstDuration) + eq_(answer[1][1], expectedSecondDuration) def test_dateTime_duration_subs(): """ - Test cases for subtraction operation between dateTime and duration + Test cases for subtraction operation between dateTime and duration """ data = """ @@ -78,11 +86,12 @@ def test_dateTime_duration_subs(): """ graph = Graph() f = io.StringIO(data) - graph.parse(f, format='n3') + graph.parse(f, format="n3") - ## 1st Test Case + ## 1st Test Case - result1 = graph.query(""" + result1 = graph.query( + """ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT (?d - ?duration AS ?next_year) WHERE { @@ -91,17 +100,29 @@ def test_dateTime_duration_subs(): ("P1Y"^^xsd:yearMonthDuration"2019-05-28"^^xsd:date) } } - """) - expected=[] - expected.append(rdflib.term.Literal('2018-05-28T12:14:45+00:00', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#dateTime'))) - expected.append(rdflib.term.Literal('2018-05-28', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#date'))) - - eq_(list(result1)[0][0],expected[0]) - eq_(list(result1)[1][0],expected[1]) - - ## 2nd Test Case - - result2 = graph.query(""" + """ + ) + expected = [] + expected.append( + rdflib.term.Literal( + "2018-05-28T12:14:45+00:00", + datatype=rdflib.term.URIRef("http://www.w3.org/2001/XMLSchema#dateTime"), + ) + ) + expected.append( + rdflib.term.Literal( + "2018-05-28", + datatype=rdflib.term.URIRef("http://www.w3.org/2001/XMLSchema#date"), + ) + ) + + eq_(list(result1)[0][0], expected[0]) + eq_(list(result1)[1][0], expected[1]) + + ## 2nd Test Case + + result2 = graph.query( + """ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT (?d - ?duration AS ?next_year) WHERE { @@ -110,20 +131,30 @@ def test_dateTime_duration_subs(): ("P3DT1H15M"^^xsd:dayTimeDuration "2000-10-30"^^xsd:date) } } - """) - - expected=[] - expected.append(rdflib.term.Literal('2000-10-27T09:57:00', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#dateTime'))) - expected.append(rdflib.term.Literal('2000-10-27', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#date'))) - - eq_(list(result2)[0][0],expected[0]) - eq_(list(result2)[1][0],expected[1]) + """ + ) + + expected = [] + expected.append( + rdflib.term.Literal( + "2000-10-27T09:57:00", + datatype=rdflib.term.URIRef("http://www.w3.org/2001/XMLSchema#dateTime"), + ) + ) + expected.append( + rdflib.term.Literal( + "2000-10-27", + datatype=rdflib.term.URIRef("http://www.w3.org/2001/XMLSchema#date"), + ) + ) + + eq_(list(result2)[0][0], expected[0]) + eq_(list(result2)[1][0], expected[1]) - def test_dateTime_duration_add(): """ - Test cases for addition operation between dateTime and duration + Test cases for addition operation between dateTime and duration """ data = """ @@ -134,11 +165,12 @@ def test_dateTime_duration_add(): """ graph = Graph() f = io.StringIO(data) - graph.parse(f, format='n3') + graph.parse(f, format="n3") ## 1st Test case - result1 = graph.query(""" + result1 = graph.query( + """ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT (?d + ?duration AS ?next_year) WHERE { @@ -147,19 +179,31 @@ def test_dateTime_duration_add(): ("P1Y"^^xsd:yearMonthDuration"2019-05-28"^^xsd:date) } } - """) + """ + ) # print(list(result1)) - expected=[] - expected.append(rdflib.term.Literal('2020-05-28T12:14:45+00:00', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#dateTime'))) - expected.append(rdflib.term.Literal('2020-05-28', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#date'))) - - eq_(list(result1)[0][0],expected[0]) - eq_(list(result1)[1][0],expected[1]) + expected = [] + expected.append( + rdflib.term.Literal( + "2020-05-28T12:14:45+00:00", + datatype=rdflib.term.URIRef("http://www.w3.org/2001/XMLSchema#dateTime"), + ) + ) + expected.append( + rdflib.term.Literal( + "2020-05-28", + datatype=rdflib.term.URIRef("http://www.w3.org/2001/XMLSchema#date"), + ) + ) + + eq_(list(result1)[0][0], expected[0]) + eq_(list(result1)[1][0], expected[1]) ## 2nd Test case - result2 = graph.query(""" + result2 = graph.query( + """ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT (?d + ?duration AS ?next_year) WHERE { @@ -168,19 +212,31 @@ def test_dateTime_duration_add(): ("P3DT1H15M"^^xsd:dayTimeDuration "2000-10-30"^^xsd:date) } } - """) + """ + ) # print(list(result2)) - expected=[] - expected.append(rdflib.term.Literal('2000-11-02T12:27:00', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#dateTime'))) - expected.append(rdflib.term.Literal('2000-11-02', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#date'))) - - eq_(list(result2)[0][0],expected[0]) - eq_(list(result2)[1][0],expected[1]) + expected = [] + expected.append( + rdflib.term.Literal( + "2000-11-02T12:27:00", + datatype=rdflib.term.URIRef("http://www.w3.org/2001/XMLSchema#dateTime"), + ) + ) + expected.append( + rdflib.term.Literal( + "2000-11-02", + datatype=rdflib.term.URIRef("http://www.w3.org/2001/XMLSchema#date"), + ) + ) + + eq_(list(result2)[0][0], expected[0]) + eq_(list(result2)[1][0], expected[1]) + def test_dateTime_dateTime_subs(): """ - Test cases for subtraction operation between dateTime and dateTime + Test cases for subtraction operation between dateTime and dateTime """ data = """ @@ -192,9 +248,10 @@ def test_dateTime_dateTime_subs(): graph = Graph() f = io.StringIO(data) - graph.parse(f, format='n3') + graph.parse(f, format="n3") - result1 = graph.query(""" + result1 = graph.query( + """ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT (?l - ?r AS ?duration) WHERE { @@ -203,17 +260,23 @@ def test_dateTime_dateTime_subs(): ("2000-10-30"^^xsd:date"1999-11-28"^^xsd:date) } } - """) + """ + ) - expected1=rdflib.term.Literal('P337DT2H12M', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#duration')) - expected2=rdflib.term.Literal('P337D', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#duration')) - - eq_(list(result1)[0][0],expected1) - eq_(list(result1)[1][0],expected2) + expected1 = rdflib.term.Literal( + "P337DT2H12M", + datatype=rdflib.term.URIRef("http://www.w3.org/2001/XMLSchema#duration"), + ) + expected2 = rdflib.term.Literal( + "P337D", + datatype=rdflib.term.URIRef("http://www.w3.org/2001/XMLSchema#duration"), + ) + eq_(list(result1)[0][0], expected1) + eq_(list(result1)[1][0], expected2) -if __name__ == '__main__': + +if __name__ == "__main__": import nose - nose.main(defaultTest=__name__) - + nose.main(defaultTest=__name__) diff --git a/test/test_store_berkeleydb.py b/test/test_store_berkeleydb.py index 634b7221..e5e8e66d 100644 --- a/test/test_store_berkeleydb.py +++ b/test/test_store_berkeleydb.py @@ -11,7 +11,9 @@ class BerkeleyDBTestCase(unittest.TestCase): self.g = ConjunctiveGraph(store=self.store_name) self.rt = self.g.open(self.path, create=True) assert self.rt == VALID_STORE, "The underlying store is corrupt" - assert len(self.g) == 0, "There must be zero triples in the graph just after store (file) creation" + assert ( + len(self.g) == 0 + ), "There must be zero triples in the graph just after store (file) creation" data = """ PREFIX : <https://example.org/> @@ -25,25 +27,34 @@ class BerkeleyDBTestCase(unittest.TestCase): self.g.close() def test_write(self): - assert len(self.g) == 3, "There must be three triples in the graph after the first data chunk parse" + assert ( + len(self.g) == 3 + ), "There must be three triples in the graph after the first data chunk parse" data2 = """ PREFIX : <https://example.org/> :d :i :j . """ self.g.parse(data=data2, format="ttl") - assert len(self.g) == 4, "There must be four triples in the graph after the second data chunk parse" + assert ( + len(self.g) == 4 + ), "There must be four triples in the graph after the second data chunk parse" data3 = """ PREFIX : <https://example.org/> :d :i :j . """ self.g.parse(data=data3, format="ttl") - assert len(self.g) == 4, "There must still be four triples in the graph after the thrd data chunk parse" + assert ( + len(self.g) == 4 + ), "There must still be four triples in the graph after the thrd data chunk parse" def test_read(self): sx = None - for s in self.g.subjects(predicate=URIRef("https://example.org/e"), object=URIRef("https://example.org/f")): + for s in self.g.subjects( + predicate=URIRef("https://example.org/e"), + object=URIRef("https://example.org/f"), + ): sx = s assert sx == URIRef("https://example.org/d") @@ -111,4 +122,6 @@ class BerkeleyDBTestCase(unittest.TestCase): # reopen the graph self.g = ConjunctiveGraph("BerkeleyDB") self.g.open(self.path, create=False) - assert len(self.g) == 3, "After close and reopen, we should still have the 3 originally added triples" + assert ( + len(self.g) == 3 + ), "After close and reopen, we should still have the 3 originally added triples" diff --git a/test/test_tokendatatype.py b/test/test_tokendatatype.py index 26ac2ad2..565f5972 100644 --- a/test/test_tokendatatype.py +++ b/test/test_tokendatatype.py @@ -4,7 +4,6 @@ from rdflib import Literal, XSD class TokenDatatypeTest(unittest.TestCase): - def test1(self): lit2 = Literal("\two\nw", datatype=XSD.normalizedString) lit = Literal("\two\nw", datatype=XSD.string) @@ -18,7 +17,7 @@ class TokenDatatypeTest(unittest.TestCase): def test3(self): lit = Literal(" hey\nthere ", datatype=XSD.token).n3() - self.assertTrue(lit == "\"hey there\"^^<http://www.w3.org/2001/XMLSchema#token>") + self.assertTrue(lit == '"hey there"^^<http://www.w3.org/2001/XMLSchema#token>') def test4(self): lit = Literal("hey\nthere\ta tab\rcarriage return", datatype=XSD.token) @@ -26,10 +25,16 @@ class TokenDatatypeTest(unittest.TestCase): self.assertEqual(str(lit), str(expected)) def test_whitespace_is_collapsed_and_trailing_whitespace_is_stripped(self): - lit = Literal("\n hey - white space is collapsed for xsd:token and preceding and trailing whitespace is stripped ", datatype=XSD.token) - expected = Literal("hey - white space is collapsed for xsd:token and preceding and trailing whitespace is stripped", datatype=XSD.string) + lit = Literal( + "\n hey - white space is collapsed for xsd:token and preceding and trailing whitespace is stripped ", + datatype=XSD.token, + ) + expected = Literal( + "hey - white space is collapsed for xsd:token and preceding and trailing whitespace is stripped", + datatype=XSD.string, + ) self.assertEqual(str(lit), str(expected)) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/test/test_trig.py b/test/test_trig.py index 5c91b0a0..9dcd0ecc 100644 --- a/test/test_trig.py +++ b/test/test_trig.py @@ -80,7 +80,7 @@ class TestTrig(unittest.TestCase): def testBlankGraphIdentifier(self): g = rdflib.ConjunctiveGraph() g.add(TRIPLE + (rdflib.BNode(),)) - out = g.serialize(format="trig", encoding='latin-1') + out = g.serialize(format="trig", encoding="latin-1") graph_label_line = out.splitlines()[-4] self.assertTrue(re.match(br"^_:[a-zA-Z0-9]+ \{", graph_label_line)) @@ -118,7 +118,9 @@ class TestTrig(unittest.TestCase): g.parse(data=data, format="trig") self.assertEqual(len(list(g.contexts())), 2) - @unittest.skipIf(True, "Iterative serialization currently produces 16 copies of everything") + @unittest.skipIf( + True, "Iterative serialization currently produces 16 copies of everything" + ) def testRoundTrips(self): data = """ diff --git a/test/test_trix_parse.py b/test/test_trix_parse.py index 6f5a5c55..d845322e 100644 --- a/test/test_trix_parse.py +++ b/test/test_trix_parse.py @@ -18,7 +18,9 @@ class TestTrixParse(unittest.TestCase): g = ConjunctiveGraph() - trix_path = os.path.relpath(os.path.join(TEST_DIR, 'trix/aperture.trix'), os.curdir) + trix_path = os.path.relpath( + os.path.join(TEST_DIR, "trix/aperture.trix"), os.curdir + ) g.parse(trix_path, format="trix") c = list(g.contexts()) @@ -34,7 +36,9 @@ class TestTrixParse(unittest.TestCase): g = ConjunctiveGraph() - trix_path = os.path.relpath(os.path.join(TEST_DIR, 'trix/nokia_example.trix'), os.curdir) + trix_path = os.path.relpath( + os.path.join(TEST_DIR, "trix/nokia_example.trix"), os.curdir + ) g.parse(trix_path, format="trix") # print "Parsed %d triples"%len(g) @@ -43,7 +47,9 @@ class TestTrixParse(unittest.TestCase): g = ConjunctiveGraph() - trix_path = os.path.relpath(os.path.join(TEST_DIR, 'trix/ng4jtest.trix'), os.curdir) + trix_path = os.path.relpath( + os.path.join(TEST_DIR, "trix/ng4jtest.trix"), os.curdir + ) g.parse(trix_path, format="trix") # print "Parsed %d triples"%len(g) diff --git a/test/test_util.py b/test/test_util.py index 62cb52db..76b6c51a 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -244,22 +244,22 @@ class TestUtilTermConvert(unittest.TestCase): def test_util_from_n3_expectpartialidempotencewithn3(self): for n3 in ( - '<http://ex.com/foo>', + "<http://ex.com/foo>", '"foo"@de', - '<http://ex.com/漢字>', - '<http://ex.com/a#あ>', + "<http://ex.com/漢字>", + "<http://ex.com/a#あ>", # '"\\""', # exception as '\\"' --> '"' by orig parser as well '"""multi\n"line"\nstring"""@en', ): self.assertEqual( - util.from_n3(n3).n3(), + util.from_n3(n3).n3(), n3, - 'from_n3(%(n3e)r).n3() != %(n3e)r' % {'n3e': n3}, + "from_n3(%(n3e)r).n3() != %(n3e)r" % {"n3e": n3}, ) def test_util_from_n3_expectsameasn3parser(self): def parse_n3(term_n3): - """ Disclaimer: Quick and dirty hack using the n3 parser. """ + """Disclaimer: Quick and dirty hack using the n3 parser.""" prepstr = ( "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n" "<urn:no_use> <urn:no_use> %s.\n" % term_n3 diff --git a/test/test_wide_python.py b/test/test_wide_python.py index f4eeab32..ad5421d4 100644 --- a/test/test_wide_python.py +++ b/test/test_wide_python.py @@ -3,11 +3,11 @@ def test_wide_python_build(): See https://github.com/RDFLib/rdflib/issues/456 for more information. """ - assert len('\U0010FFFF') == 1, ( - 'You are using a narrow Python build!\n' - 'This means that your Python does not properly support chars > 16bit.\n' + assert len("\U0010FFFF") == 1, ( + "You are using a narrow Python build!\n" + "This means that your Python does not properly support chars > 16bit.\n" 'On your system chars like c=u"\\U0010FFFF" will have a len(c)==2.\n' - 'As this can cause hard to debug problems with string processing\n' - '(slicing, regexp, ...) later on, we strongly advise to use a wide\n' - 'Python build in production systems.' + "As this can cause hard to debug problems with string processing\n" + "(slicing, regexp, ...) later on, we strongly advise to use a wide\n" + "Python build in production systems." ) diff --git a/test/testutils.py b/test/testutils.py index 7211ff60..05ddf907 100644 --- a/test/testutils.py +++ b/test/testutils.py @@ -134,13 +134,20 @@ def nose_tst_earl_report(generator, earl_report_name=None): ) if earl_report_name: now = isodate.datetime_isoformat(datetime.datetime.utcnow()) - earl_report = os.path.join(TEST_DIR, "../test_reports/%s-%s.ttl" % ( - earl_report_name, - now.replace(":", ""), - )) + earl_report = os.path.join( + TEST_DIR, + "../test_reports/%s-%s.ttl" + % ( + earl_report_name, + now.replace(":", ""), + ), + ) report.serialize(earl_report, format="n3") - report.serialize(os.path.join(TEST_DIR, "../test_reports/%s-latest.ttl" % earl_report_name), format="n3") + report.serialize( + os.path.join(TEST_DIR, "../test_reports/%s-latest.ttl" % earl_report_name), + format="n3", + ) print("Wrote EARL-report to '%s'" % earl_report) diff --git a/test/translate_algebra/main.py b/test/translate_algebra/main.py index b11a6e88..72d955cd 100644 --- a/test/translate_algebra/main.py +++ b/test/translate_algebra/main.py @@ -7,7 +7,7 @@ import logging def _pprint_query(query: str): - p = '{' + p = "{" q = "}" i = 0 f = 1 @@ -15,21 +15,20 @@ def _pprint_query(query: str): for e in query: if e in p: f or print() - print(' ' * i + e) + print(" " * i + e) i += 4 f = 1 elif e in q: f or print() i -= 4 f = 1 - print(' ' * i + e) + print(" " * i + e) else: - not f or print(' ' * i, end='') - f = print(e, end='') + not f or print(" " * i, end="") + f = print(e, end="") class TestAlgebraToTest(TestExecution): - def __init__(self, annotated_tests: bool = False): super().__init__(annotated_tests) self.rdf_engine = None @@ -60,19 +59,27 @@ class TestAlgebraToTest(TestExecution): query_algebra_2 = algebra.translateQuery(query_tree_2) self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) - test = Test(test_number=1, - tc_desc='Test if functional forms are properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=1, + tc_desc="Test if functional forms are properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) try: - self.rdf_engine.get_data(self.query_from_query_from_algebra, yn_timestamp_query=False) + self.rdf_engine.get_data( + self.query_from_query_from_algebra, yn_timestamp_query=False + ) except Exception as e: print(e) print("The query must be executable. Otherwise, the test has failed.") - return Test(test_number=test.test_number, tc_desc=test.tc_desc, expected_result="0", - actual_result="not_executable") + return Test( + test_number=test.test_number, + tc_desc=test.tc_desc, + expected_result="0", + actual_result="not_executable", + ) return test @@ -86,11 +93,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=2, - tc_desc='Test if the not exists form is properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=2, + tc_desc="Test if the not exists form is properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -104,11 +113,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=3, - tc_desc='Test if functions on rdf terms are properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=3, + tc_desc="Test if functions on rdf terms are properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -122,11 +133,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=4, - tc_desc='Test if functions on strings are properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=4, + tc_desc="Test if functions on strings are properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -140,11 +153,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=5, - tc_desc='Test if functions on numerics are properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=5, + tc_desc="Test if functions on numerics are properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -158,11 +173,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=6, - tc_desc='Test if hash functions are properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=6, + tc_desc="Test if hash functions are properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -176,11 +193,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=7, - tc_desc='Test if functions on dates and time are properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=7, + tc_desc="Test if functions on dates and time are properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -194,12 +213,14 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=8, - tc_desc='Test if aggregate join including all aggregation functions ' - 'are properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=8, + tc_desc="Test if aggregate join including all aggregation functions " + "are properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -213,11 +234,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=9, - tc_desc='Test if basic graph patterns are properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=9, + tc_desc="Test if basic graph patterns are properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -231,12 +254,14 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=10, - tc_desc='Test if "extend" (=Bind explicitly or implicitly in projection) ' - 'gets properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=10, + tc_desc='Test if "extend" (=Bind explicitly or implicitly in projection) ' + "gets properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -250,11 +275,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=11, - tc_desc='Test if filter gets properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=11, + tc_desc="Test if filter gets properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -268,11 +295,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=12, - tc_desc='Test if "graph" gets properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=12, + tc_desc='Test if "graph" gets properly translated into the query text. ' + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -286,11 +315,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=13, - tc_desc='Test if "group" gets properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=13, + tc_desc='Test if "group" gets properly translated into the query text. ' + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -304,11 +335,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=14, - tc_desc='Test if "having" gets properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=14, + tc_desc='Test if "having" gets properly translated into the query text. ' + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -322,11 +355,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=15, - tc_desc='Test if "join" gets properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=15, + tc_desc='Test if "join" gets properly translated into the query text. ' + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -340,11 +375,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=16, - tc_desc='Test if "left join" gets properly translated into "OPTIONAL {...}" in the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=16, + tc_desc='Test if "left join" gets properly translated into "OPTIONAL {...}" in the query text. ' + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -358,11 +395,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=17, - tc_desc='Test if "minus" gets properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=17, + tc_desc='Test if "minus" gets properly translated into the query text. ' + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -376,11 +415,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=18, - tc_desc='Test if "union" gets properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=18, + tc_desc='Test if "union" gets properly translated into the query text. ' + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -394,11 +435,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=19, - tc_desc='Test if arithmetics are properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=19, + tc_desc="Test if arithmetics are properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -412,11 +455,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=20, - tc_desc='Test if "conditional ands (&&)" are properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=20, + tc_desc='Test if "conditional ands (&&)" are properly translated into the query text. ' + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -430,11 +475,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=21, - tc_desc='Test if "conditional ors (||)" are properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=21, + tc_desc='Test if "conditional ors (||)" are properly translated into the query text. ' + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -448,11 +495,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=22, - tc_desc='Test if relational expressions are properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=22, + tc_desc="Test if relational expressions are properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -466,24 +515,32 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=23, - tc_desc='Test if unary expressions are properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=23, + tc_desc="Test if unary expressions are properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test def test_other__service1(self): - tc_desc = 'Test if a nested service pattern is properly translated ' \ - 'into the query text. ' \ - 'The query must also be executable and shall not violate any SPARQL query syntax.' + tc_desc = ( + "Test if a nested service pattern is properly translated " + "into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax." + ) try: query_tree = parser.parseQuery(self.query_text) except Exception as e: print(e) - return Test(test_number=24, tc_desc=tc_desc, expected_result="0", - actual_result="Not executable. Error returned from parseQuery") + return Test( + test_number=24, + tc_desc=tc_desc, + expected_result="0", + actual_result="Not executable. Error returned from parseQuery", + ) query_algebra = algebra.translateQuery(query_tree) self.query_from_algebra = translateAlgebra(query_algebra) @@ -492,23 +549,31 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=24, - tc_desc=tc_desc, - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=24, + tc_desc=tc_desc, + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test def test_other__service2(self): - tc_desc = 'Test if "service" along with its service string is properly translated ' \ - 'into the query text. ' \ - 'The query must also be executable and shall not violate any SPARQL query syntax.' + tc_desc = ( + 'Test if "service" along with its service string is properly translated ' + "into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax." + ) try: query_tree = parser.parseQuery(self.query_text) except Exception as e: print(e) - return Test(test_number=25, tc_desc=tc_desc, expected_result="0", - actual_result="Not executable. Error returned from parseQuery().") + return Test( + test_number=25, + tc_desc=tc_desc, + expected_result="0", + actual_result="Not executable. Error returned from parseQuery().", + ) query_algebra = algebra.translateQuery(query_tree) self.query_from_algebra = translateAlgebra(query_algebra) @@ -517,10 +582,12 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=25, - tc_desc=tc_desc, - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=25, + tc_desc=tc_desc, + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -534,11 +601,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=26, - tc_desc='Test if "values" gets properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=26, + tc_desc='Test if "values" gets properly translated into the query text. ' + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -552,11 +621,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=27, - tc_desc='Test if an alternative path gets properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=27, + tc_desc="Test if an alternative path gets properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -570,35 +641,45 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=28, - tc_desc='Test if an inverse path gets properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=28, + tc_desc="Test if an inverse path gets properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test def test_property_path__negated_property_set(self): - tc_desc = 'Test if a negated property set gets properly translated into the query text. ' \ - 'The query must also be executable and shall not violate any SPARQL query syntax.' + tc_desc = ( + "Test if a negated property set gets properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax." + ) query_tree = parser.parseQuery(self.query_text) query_algebra = algebra.translateQuery(query_tree) try: self.query_from_algebra = translateAlgebra(query_algebra) except TypeError as e: print(e) - return Test(test_number=29, tc_desc=tc_desc, expected_result="0", - actual_result="Not executable. n3() method of NegatedPath class should be fixed. ") + return Test( + test_number=29, + tc_desc=tc_desc, + expected_result="0", + actual_result="Not executable. n3() method of NegatedPath class should be fixed. ", + ) query_tree_2 = parser.parseQuery(self.query_from_algebra) query_algebra_2 = algebra.translateQuery(query_tree_2) self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=29, - tc_desc=tc_desc, - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=29, + tc_desc=tc_desc, + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -612,11 +693,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=30, - tc_desc='Test if a oneOrMore path gets properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=30, + tc_desc="Test if a oneOrMore path gets properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -630,11 +713,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=31, - tc_desc='Test if a sequence path gets properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=31, + tc_desc="Test if a sequence path gets properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -648,11 +733,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=32, - tc_desc='Test if a zeroOrMore path gets properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=32, + tc_desc="Test if a zeroOrMore path gets properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -666,11 +753,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=33, - tc_desc='Test if a zeroOrOne path gets properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=33, + tc_desc="Test if a zeroOrOne path gets properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -684,11 +773,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=34, - tc_desc='Test if "distinct" gets properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=34, + tc_desc='Test if "distinct" gets properly translated into the query text. ' + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -702,11 +793,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=35, - tc_desc='Test if "order by" gets properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=35, + tc_desc='Test if "order by" gets properly translated into the query text. ' + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -720,11 +813,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=36, - tc_desc='Test if "reduced" gets properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=36, + tc_desc='Test if "reduced" gets properly translated into the query text. ' + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -738,11 +833,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=37, - tc_desc='Test if slice get properly translated into the limit and offset. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=37, + tc_desc="Test if slice get properly translated into the limit and offset. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -756,11 +853,13 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=38, - tc_desc='Test if subqueries get properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=38, + tc_desc="Test if subqueries get properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test @@ -774,12 +873,14 @@ class TestAlgebraToTest(TestExecution): self.query_from_query_from_algebra = translateAlgebra(query_algebra_2) _pprint_query(self.query_from_query_from_algebra) - test = Test(test_number=39, - tc_desc='Test a query with multiple graph patterns and solution modifiers ' - 'gets properly translated into the query text. ' - 'The query must also be executable and shall not violate any SPARQL query syntax.', - expected_result=self.query_from_algebra, - actual_result=self.query_from_query_from_algebra) + test = Test( + test_number=39, + tc_desc="Test a query with multiple graph patterns and solution modifiers " + "gets properly translated into the query text. " + "The query must also be executable and shall not violate any SPARQL query syntax.", + expected_result=self.query_from_algebra, + actual_result=self.query_from_query_from_algebra, + ) return test diff --git a/test/translate_algebra/test_base.py b/test/translate_algebra/test_base.py index f341b43a..21bdc9bf 100644 --- a/test/translate_algebra/test_base.py +++ b/test/translate_algebra/test_base.py @@ -27,9 +27,14 @@ def format_text(comment, max_line_length): class Test: - - def __init__(self, tc_desc: str, expected_result: str = None, actual_result: str = None, test_number: int = None, - test_name: str = None): + def __init__( + self, + tc_desc: str, + expected_result: str = None, + actual_result: str = None, + test_number: int = None, + test_name: str = None, + ): self.test_number = test_number self.test_name = test_name self.tc_desc = tc_desc @@ -49,7 +54,6 @@ class Test: class TestExecution: - def __init__(self, annotated_tests: bool = False): """ @@ -100,13 +104,17 @@ class TestExecution: :return: """ print("Executing tests ...") - logging.getLogger().setLevel(int(self.test_config.get('TEST', 'log_level'))) + logging.getLogger().setLevel(int(self.test_config.get("TEST", "log_level"))) self.before_all_tests() - test_prefix = 'test_' + test_prefix = "test_" if self.annotated_tests: - test_prefix = 'x_test_' - test_functions = [func for func in dir(self) if callable(getattr(self, func)) and func.startswith(test_prefix)] + test_prefix = "x_test_" + test_functions = [ + func + for func in dir(self) + if callable(getattr(self, func)) and func.startswith(test_prefix) + ] try: test_number = 1 for func in test_functions: @@ -130,21 +138,38 @@ class TestExecution: :return: """ - tests_df = pd.DataFrame(columns=['test_number', 'test_passed', 'test_name', 'test_case_description', - 'expected_result', 'actual_result']) + tests_df = pd.DataFrame( + columns=[ + "test_number", + "test_passed", + "test_name", + "test_case_description", + "expected_result", + "actual_result", + ] + ) for test in self.tests: if isinstance(test, Test): formatted_tc_desc = format_text(test.tc_desc, 100) formatted_expected_result = format_text(test.expected_result, 50) formatted_actual_result = format_text(test.actual_result, 50) - tests_df = tests_df.append({'test_number': test.test_number, - 'test_passed': test.yn_passed, - 'test_name': test.test_name, - 'test_case_description': formatted_tc_desc, - 'expected_result': formatted_expected_result, - 'actual_result': formatted_actual_result}, ignore_index=True) - - tests_df.sort_values('test_number', inplace=True) - pdtabulate = lambda df: tabulate(df, headers='keys', tablefmt='grid', ) + tests_df = tests_df.append( + { + "test_number": test.test_number, + "test_passed": test.yn_passed, + "test_name": test.test_name, + "test_case_description": formatted_tc_desc, + "expected_result": formatted_expected_result, + "actual_result": formatted_actual_result, + }, + ignore_index=True, + ) + + tests_df.sort_values("test_number", inplace=True) + pdtabulate = lambda df: tabulate( + df, + headers="keys", + tablefmt="grid", + ) print(pdtabulate(tests_df)) |