Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

style: fix linting errors in test/test_graph #2556

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
76 changes: 38 additions & 38 deletions test/test_graph/test_aggregate_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from rdflib.store import Store
from rdflib.term import URIRef

testGraph1N3 = """
TEST_GRAPH_1N3 = """
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix : <http://test/> .
Expand All @@ -16,7 +16,7 @@
"""


testGraph2N3 = """
TEST_GRAPH_2N3 = """
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix : <http://test/> .
Expand All @@ -26,15 +26,15 @@
:a :d :e.
"""

testGraph3N3 = """
TEST_GRAPH_3N3 = """
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix : <http://test/> .
<> a log:N3Document.
"""

sparqlQ = """
SPARQL_Q = """
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT *
FROM NAMED <http://example.com/graph1>
Expand All @@ -44,71 +44,71 @@

WHERE {?sub ?pred rdfs:Class }"""

sparqlQ2 = """
SPARQL_Q2 = """
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?class
WHERE { GRAPH ?graph { ?member a ?class } }"""

sparqlQ3 = """
SPARQL_Q3 = """
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX log: <http://www.w3.org/2000/10/swap/log#>
SELECT ?n3Doc
WHERE {?n3Doc a log:N3Document }"""


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
Expand Down
34 changes: 17 additions & 17 deletions test/test_graph/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,64 +18,64 @@ 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"),
Literal("3"),
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
Loading