diff --git a/pyproject.toml b/pyproject.toml index c5fe61e34..174c31c18 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -155,12 +155,6 @@ line-length = 88 "N802", # Function name should be lowercase "N806", # Variable in function should be lowercase ] -"test/test_graph/test_{container,graph_context,aggregate_graphs}.py" = [ - "N802", # Function name should be lowercase - "N806", # Variable in function should be lowercase - "N816", # Variable in class scope should be mixedCase -] - [tool.black] required-version = "23.7.0" diff --git a/test/test_graph/test_aggregate_graphs.py b/test/test_graph/test_aggregate_graphs.py index 12309684c..fd45c4a14 100644 --- a/test/test_graph/test_aggregate_graphs.py +++ b/test/test_graph/test_aggregate_graphs.py @@ -6,7 +6,7 @@ from rdflib.store import Store from rdflib.term import URIRef -testGraph1N3 = """ +TEST_GRAPH_1N3 = """ @prefix rdf: . @prefix rdfs: . @prefix : . @@ -16,7 +16,7 @@ """ -testGraph2N3 = """ +TEST_GRAPH_2N3 = """ @prefix rdf: . @prefix rdfs: . @prefix : . @@ -26,7 +26,7 @@ :a :d :e. """ -testGraph3N3 = """ +TEST_GRAPH_3N3 = """ @prefix rdf: . @prefix rdfs: . @prefix log: . @@ -34,7 +34,7 @@ <> a log:N3Document. """ -sparqlQ = """ +SPARQL_Q = """ PREFIX rdfs: SELECT * FROM NAMED @@ -44,12 +44,12 @@ WHERE {?sub ?pred rdfs:Class }""" -sparqlQ2 = """ +SPARQL_Q2 = """ PREFIX rdfs: SELECT ?class WHERE { GRAPH ?graph { ?member a ?class } }""" -sparqlQ3 = """ +SPARQL_Q3 = """ PREFIX rdfs: PREFIX log: SELECT ?n3Doc @@ -57,58 +57,58 @@ def test_aggregate_raw(): - memStore = plugin.get("Memory", Store)() - graph1 = Graph(memStore) - graph2 = Graph(memStore) - graph3 = Graph(memStore) - - for n3Str, graph in [ - (testGraph1N3, graph1), - (testGraph2N3, graph2), - (testGraph3N3, graph3), + mem_store = plugin.get("Memory", Store)() + graph1 = Graph(mem_store) + graph2 = Graph(mem_store) + graph3 = Graph(mem_store) + + for n3_str, graph in [ + (TEST_GRAPH_1N3, graph1), + (TEST_GRAPH_2N3, graph2), + (TEST_GRAPH_3N3, graph3), ]: - graph.parse(StringIO(n3Str), format="n3") + graph.parse(StringIO(n3_str), format="n3") - G = ReadOnlyGraphAggregate([graph1, graph2, graph3]) + g = ReadOnlyGraphAggregate([graph1, graph2, graph3]) # Test triples - assert len(list(G.triples((None, RDF.type, None)))) == 4 - assert len(list(G.triples((URIRef("http://test/bar"), None, None)))) == 2 - assert len(list(G.triples((None, URIRef("http://test/d"), None)))) == 3 + assert len(list(g.triples((None, RDF.type, None)))) == 4 + assert len(list(g.triples((URIRef("http://test/bar"), None, None)))) == 2 + assert len(list(g.triples((None, URIRef("http://test/d"), None)))) == 3 # Test __len__ - assert len(G) == 8 + assert len(g) == 8 # assert context iteration - for g in G.contexts(): + for g in g.contexts(): assert isinstance(g, Graph) # Test __contains__ - assert (URIRef("http://test/foo"), RDF.type, RDFS.Resource) in G + assert (URIRef("http://test/foo"), RDF.type, RDFS.Resource) in g - barPredicates = [URIRef("http://test/d"), RDFS.isDefinedBy] + bar_predicates = [URIRef("http://test/d"), RDFS.isDefinedBy] assert ( - len(list(G.triples_choices((URIRef("http://test/bar"), barPredicates, None)))) + len(list(g.triples_choices((URIRef("http://test/bar"), bar_predicates, None)))) == 2 ) def test_aggregate2(): - memStore = plugin.get("Memory", Store)() - graph1 = Graph(memStore, URIRef("http://example.com/graph1")) - graph2 = Graph(memStore, URIRef("http://example.com/graph2")) - graph3 = Graph(memStore, URIRef("http://example.com/graph3")) - - for n3Str, graph in [ - (testGraph1N3, graph1), - (testGraph2N3, graph2), - (testGraph3N3, graph3), + mem_store = plugin.get("Memory", Store)() + graph1 = Graph(mem_store, URIRef("http://example.com/graph1")) + graph2 = Graph(mem_store, URIRef("http://example.com/graph2")) + graph3 = Graph(mem_store, URIRef("http://example.com/graph3")) + + for n3_str, graph in [ + (TEST_GRAPH_1N3, graph1), + (TEST_GRAPH_2N3, graph2), + (TEST_GRAPH_3N3, graph3), ]: - graph.parse(StringIO(n3Str), format="n3") + graph.parse(StringIO(n3_str), format="n3") - graph4 = Graph(memStore, RDFS) - graph4.parse(data=testGraph1N3, format="n3") - g = ConjunctiveGraph(memStore) + graph4 = Graph(mem_store, RDFS) + graph4.parse(data=TEST_GRAPH_1N3, format="n3") + g = ConjunctiveGraph(mem_store) assert g is not None assert len(list(g.quads((None, None, None, None)))) == 11 assert len(list(g.contexts())) == 4 diff --git a/test/test_graph/test_container.py b/test/test_graph/test_container.py index cfbace415..f50796ee0 100644 --- a/test/test_graph/test_container.py +++ b/test/test_graph/test_container.py @@ -18,45 +18,45 @@ def setup_class(cls): cls.g, BNode(), [Literal("1"), Literal("2"), Literal("3"), Literal("4")] ) - def testA(self): + def test_a(self): assert len(self.c1) == 0 - def testB(self): + def test_b(self): assert len(self.c2) == 4 - def testC(self): + def test_c(self): self.c2.append(Literal("5")) del self.c2[2] assert len(self.c2) == 4 - def testD(self): + def test_d(self): assert self.c2.index(Literal("5")) == 4 - def testE(self): + def test_e(self): assert self.c2[2] == Literal("3") - def testF(self): + def test_f(self): self.c2[2] = Literal("9") assert self.c2[2] == Literal("9") - def testG(self): + def test_g(self): self.c2.clear() assert len(self.c2) == 0 - def testH(self): + def test_h(self): self.c2.append_multiple([Literal("80"), Literal("90")]) assert self.c2[1] == Literal("80") - def testI(self): + def test_i(self): assert self.c2[2] == Literal("90") - def testJ(self): + def test_j(self): assert len(self.c2) == 2 - def testK(self): + def test_k(self): assert self.c2.end() == 2 - def testL(self): + def test_l(self): assert self.c3.anyone() in [ Literal("1"), Literal("2"), @@ -64,18 +64,18 @@ def testL(self): Literal("4"), ] - def testM(self): + def test_m(self): self.c4.add_at_position(3, Literal("60")) assert len(self.c4) == 5 - def testN(self): + def test_n(self): assert self.c4.index(Literal("60")) == 3 - def testO(self): + def test_o(self): assert self.c4.index(Literal("3")) == 4 - def testP(self): + def test_p(self): assert self.c4.index(Literal("4")) == 5 - def testQ(self): + def test_q(self): assert self.c2.index(Literal("1000")) != 3 diff --git a/test/test_graph/test_graph_context.py b/test/test_graph/test_graph_context.py index adb133826..7d0a90f7c 100644 --- a/test/test_graph/test_graph_context.py +++ b/test/test_graph/test_graph_context.py @@ -49,7 +49,7 @@ def tearDown(self): else: os.remove(self.tmppath) - def addStuff(self): + def add_stuff(self): tarek = self.tarek michel = self.michel bob = self.bob @@ -68,7 +68,7 @@ def addStuff(self): graph.add((bob, hates, pizza)) graph.add((bob, hates, michel)) # gasp! - def removeStuff(self): + def remove_stuff(self): tarek = self.tarek michel = self.michel bob = self.bob @@ -87,7 +87,7 @@ def removeStuff(self): graph.remove((bob, hates, pizza)) graph.remove((bob, hates, michel)) # gasp! - def addStuffInMultipleContexts(self): + def add_stuff_in_multiple_contexts(self): c1 = self.c1 c2 = self.c2 triple = (self.pizza, self.hates, self.tarek) # revenge! @@ -101,58 +101,58 @@ def addStuffInMultipleContexts(self): graph = Graph(self.graph.store, c2) graph.add(triple) - def testConjunction(self): + def test_conjunction(self): if self.store == "SQLite": pytest.skip("Skipping known issue with __len__") - self.addStuffInMultipleContexts() + self.add_stuff_in_multiple_contexts() triple = (self.pizza, self.likes, self.pizza) # add to context 1 graph = Graph(self.graph.store, self.c1) graph.add(triple) self.assertEqual(len(self.graph), len(graph)) - def testAdd(self): - self.addStuff() + def test_add(self): + self.add_stuff() - def testRemove(self): - self.addStuff() - self.removeStuff() + def test_remove(self): + self.add_stuff() + self.remove_stuff() - def testLenInOneContext(self): + def test_len_in_one_context(self): c1 = self.c1 # make sure context is empty self.graph.remove_context(self.graph.get_context(c1)) graph = Graph(self.graph.store, c1) - oldLen = len(self.graph) + old_len = len(self.graph) for i in range(0, 10): graph.add((BNode(), self.hates, self.hates)) - self.assertEqual(len(graph), oldLen + 10) - self.assertEqual(len(self.graph.get_context(c1)), oldLen + 10) + self.assertEqual(len(graph), old_len + 10) + self.assertEqual(len(self.graph.get_context(c1)), old_len + 10) self.graph.remove_context(self.graph.get_context(c1)) - self.assertEqual(len(self.graph), oldLen) + self.assertEqual(len(self.graph), old_len) self.assertEqual(len(graph), 0) - def testLenInMultipleContexts(self): + def test_len_in_multiple_contexts(self): if self.store == "SQLite": pytest.skip("Skipping known issue with __len__") - oldLen = len(self.graph) - self.addStuffInMultipleContexts() + old_len = len(self.graph) + self.add_stuff_in_multiple_contexts() - # addStuffInMultipleContexts is adding the same triple to + # add_stuff_in_multiple_contexts is adding the same triple to # three different contexts. So it's only + 1 - self.assertEqual(len(self.graph), oldLen + 1) + self.assertEqual(len(self.graph), old_len + 1) graph = Graph(self.graph.store, self.c1) - self.assertEqual(len(graph), oldLen + 1) + self.assertEqual(len(graph), old_len + 1) - def testRemoveInMultipleContexts(self): + def test_remove_in_multiple_contexts(self): c1 = self.c1 c2 = self.c2 triple = (self.pizza, self.hates, self.tarek) # revenge! - self.addStuffInMultipleContexts() + self.add_stuff_in_multiple_contexts() # triple should be still in store after removing it from c1 + c2 self.assertTrue(triple in self.graph) @@ -167,14 +167,14 @@ def testRemoveInMultipleContexts(self): self.assertTrue(triple not in self.graph) # add again and see if remove without context removes all triples! - self.addStuffInMultipleContexts() + self.add_stuff_in_multiple_contexts() self.graph.remove(triple) self.assertTrue(triple not in self.graph) - def testContexts(self): + def test_contexts(self): triple = (self.pizza, self.hates, self.tarek) # revenge! - self.addStuffInMultipleContexts() + self.add_stuff_in_multiple_contexts() def cid(c): return c.identifier @@ -182,27 +182,27 @@ def cid(c): self.assertTrue(self.c1 in map(cid, self.graph.contexts())) self.assertTrue(self.c2 in map(cid, self.graph.contexts())) - contextList = list(map(cid, list(self.graph.contexts(triple)))) - self.assertTrue(self.c1 in contextList, (self.c1, contextList)) - self.assertTrue(self.c2 in contextList, (self.c2, contextList)) + context_list = list(map(cid, list(self.graph.contexts(triple)))) + self.assertTrue(self.c1 in context_list, (self.c1, context_list)) + self.assertTrue(self.c2 in context_list, (self.c2, context_list)) - def testRemoveContext(self): + def test_remove_context(self): c1 = self.c1 - self.addStuffInMultipleContexts() + self.add_stuff_in_multiple_contexts() self.assertEqual(len(Graph(self.graph.store, c1)), 1) self.assertEqual(len(self.graph.get_context(c1)), 1) self.graph.remove_context(self.graph.get_context(c1)) self.assertTrue(self.c1 not in self.graph.contexts()) - def testRemoveAny(self): - Any = None - self.addStuffInMultipleContexts() - self.graph.remove((Any, Any, Any)) + def test_remove_any(self): + any = None + self.add_stuff_in_multiple_contexts() + self.graph.remove((any, any, any)) self.assertEqual(len(self.graph), 0) - def testTriples(self): + def test_triples(self): tarek = self.tarek michel = self.michel bob = self.bob @@ -216,78 +216,78 @@ def testTriples(self): graph = self.graph c1graph = Graph(self.graph.store, c1) c1triples = c1graph.triples - Any = None + any = None - self.addStuff() + self.add_stuff() # unbound subjects with context - asserte(len(list(c1triples((Any, likes, pizza)))), 2) - asserte(len(list(c1triples((Any, hates, pizza)))), 1) - asserte(len(list(c1triples((Any, likes, cheese)))), 3) - asserte(len(list(c1triples((Any, hates, cheese)))), 0) + asserte(len(list(c1triples((any, likes, pizza)))), 2) + asserte(len(list(c1triples((any, hates, pizza)))), 1) + asserte(len(list(c1triples((any, likes, cheese)))), 3) + asserte(len(list(c1triples((any, hates, cheese)))), 0) # unbound subjects without context, same results! - asserte(len(list(triples((Any, likes, pizza)))), 2) - asserte(len(list(triples((Any, hates, pizza)))), 1) - asserte(len(list(triples((Any, likes, cheese)))), 3) - asserte(len(list(triples((Any, hates, cheese)))), 0) + asserte(len(list(triples((any, likes, pizza)))), 2) + asserte(len(list(triples((any, hates, pizza)))), 1) + asserte(len(list(triples((any, likes, cheese)))), 3) + asserte(len(list(triples((any, hates, cheese)))), 0) # unbound objects with context - asserte(len(list(c1triples((michel, likes, Any)))), 2) - asserte(len(list(c1triples((tarek, likes, Any)))), 2) - asserte(len(list(c1triples((bob, hates, Any)))), 2) - asserte(len(list(c1triples((bob, likes, Any)))), 1) + asserte(len(list(c1triples((michel, likes, any)))), 2) + asserte(len(list(c1triples((tarek, likes, any)))), 2) + asserte(len(list(c1triples((bob, hates, any)))), 2) + asserte(len(list(c1triples((bob, likes, any)))), 1) # unbound objects without context, same results! - asserte(len(list(triples((michel, likes, Any)))), 2) - asserte(len(list(triples((tarek, likes, Any)))), 2) - asserte(len(list(triples((bob, hates, Any)))), 2) - asserte(len(list(triples((bob, likes, Any)))), 1) + asserte(len(list(triples((michel, likes, any)))), 2) + asserte(len(list(triples((tarek, likes, any)))), 2) + asserte(len(list(triples((bob, hates, any)))), 2) + asserte(len(list(triples((bob, likes, any)))), 1) # unbound predicates with context - asserte(len(list(c1triples((michel, Any, cheese)))), 1) - asserte(len(list(c1triples((tarek, Any, cheese)))), 1) - asserte(len(list(c1triples((bob, Any, pizza)))), 1) - asserte(len(list(c1triples((bob, Any, michel)))), 1) + asserte(len(list(c1triples((michel, any, cheese)))), 1) + asserte(len(list(c1triples((tarek, any, cheese)))), 1) + asserte(len(list(c1triples((bob, any, pizza)))), 1) + asserte(len(list(c1triples((bob, any, michel)))), 1) # unbound predicates without context, same results! - asserte(len(list(triples((michel, Any, cheese)))), 1) - asserte(len(list(triples((tarek, Any, cheese)))), 1) - asserte(len(list(triples((bob, Any, pizza)))), 1) - asserte(len(list(triples((bob, Any, michel)))), 1) + asserte(len(list(triples((michel, any, cheese)))), 1) + asserte(len(list(triples((tarek, any, cheese)))), 1) + asserte(len(list(triples((bob, any, pizza)))), 1) + asserte(len(list(triples((bob, any, michel)))), 1) # unbound subject, objects with context - asserte(len(list(c1triples((Any, hates, Any)))), 2) - asserte(len(list(c1triples((Any, likes, Any)))), 5) + asserte(len(list(c1triples((any, hates, any)))), 2) + asserte(len(list(c1triples((any, likes, any)))), 5) # unbound subject, objects without context, same results! - asserte(len(list(triples((Any, hates, Any)))), 2) - asserte(len(list(triples((Any, likes, Any)))), 5) + asserte(len(list(triples((any, hates, any)))), 2) + asserte(len(list(triples((any, likes, any)))), 5) # unbound predicates, objects with context - asserte(len(list(c1triples((michel, Any, Any)))), 2) - asserte(len(list(c1triples((bob, Any, Any)))), 3) - asserte(len(list(c1triples((tarek, Any, Any)))), 2) + asserte(len(list(c1triples((michel, any, any)))), 2) + asserte(len(list(c1triples((bob, any, any)))), 3) + asserte(len(list(c1triples((tarek, any, any)))), 2) # unbound predicates, objects without context, same results! - asserte(len(list(triples((michel, Any, Any)))), 2) - asserte(len(list(triples((bob, Any, Any)))), 3) - asserte(len(list(triples((tarek, Any, Any)))), 2) + asserte(len(list(triples((michel, any, any)))), 2) + asserte(len(list(triples((bob, any, any)))), 3) + asserte(len(list(triples((tarek, any, any)))), 2) # unbound subjects, predicates with context - asserte(len(list(c1triples((Any, Any, pizza)))), 3) - asserte(len(list(c1triples((Any, Any, cheese)))), 3) - asserte(len(list(c1triples((Any, Any, michel)))), 1) + asserte(len(list(c1triples((any, any, pizza)))), 3) + asserte(len(list(c1triples((any, any, cheese)))), 3) + asserte(len(list(c1triples((any, any, michel)))), 1) # unbound subjects, predicates without context, same results! - asserte(len(list(triples((Any, Any, pizza)))), 3) - asserte(len(list(triples((Any, Any, cheese)))), 3) - asserte(len(list(triples((Any, Any, michel)))), 1) + asserte(len(list(triples((any, any, pizza)))), 3) + asserte(len(list(triples((any, any, cheese)))), 3) + asserte(len(list(triples((any, any, michel)))), 1) # all unbound with context - asserte(len(list(c1triples((Any, Any, Any)))), 7) + asserte(len(list(c1triples((any, any, any)))), 7) # all unbound without context, same result! - asserte(len(list(triples((Any, Any, Any)))), 7) + asserte(len(list(triples((any, any, any)))), 7) for c in [graph, self.graph.get_context(c1)]: # unbound subjects @@ -359,9 +359,9 @@ def testTriples(self): ) # remove stuff and make sure the graph is empty again - self.removeStuff() - asserte(len(list(c1triples((Any, Any, Any)))), 0) - asserte(len(list(triples((Any, Any, Any)))), 0) + self.remove_stuff() + asserte(len(list(c1triples((any, any, any)))), 0) + asserte(len(list(triples((any, any, any)))), 0) # dynamically create classes for each registered Store