Skip to content

Commit

Permalink
style: fix the naming of test data constants (#2561)
Browse files Browse the repository at this point in the history
This makes them PEP-8 compliant.
  • Loading branch information
aucampia authored Aug 31, 2023
1 parent bbb9880 commit 8ee2d2f
Show file tree
Hide file tree
Showing 13 changed files with 273 additions and 256 deletions.
43 changes: 30 additions & 13 deletions test/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,37 @@
TEST_DIR = Path(__file__).parent
TEST_DATA_DIR = TEST_DIR / "data"

alice_uri = URIRef("http://example.org/alice")
bob_uri = URIRef("http://example.org/bob")
ALICE_URI = URIRef("http://example.org/alice")
BOB_URI = URIRef("http://example.org/bob")

michel = URIRef("urn:example:michel")
tarek = URIRef("urn:example:tarek")
bob = URIRef("urn:example:bob")
likes = URIRef("urn:example:likes")
hates = URIRef("urn:example:hates")
pizza = URIRef("urn:example:pizza")
cheese = URIRef("urn:example:cheese")

context0 = URIRef("urn:example:context-0")
context1 = URIRef("urn:example:context-1")
context2 = URIRef("urn:example:context-2")
MICHEL = URIRef("urn:example:michel")
TAREK = URIRef("urn:example:tarek")
BOB = URIRef("urn:example:bob")
LIKES = URIRef("urn:example:likes")
HATES = URIRef("urn:example:hates")
PIZZA = URIRef("urn:example:pizza")
CHEESE = URIRef("urn:example:cheese")
CONTEXT0 = URIRef("urn:example:context-0")
CONTEXT1 = URIRef("urn:example:context-1")
CONTEXT2 = URIRef("urn:example:context-2")


SIMPLE_TRIPLE_GRAPH = cached_graph((TEST_DATA_DIR / "variants" / "simple_triple.py",))

__all__ = [
"TEST_DIR",
"TEST_DATA_DIR",
"SIMPLE_TRIPLE_GRAPH",
"ALICE_URI",
"BOB_URI",
"MICHEL",
"TAREK",
"BOB",
"LIKES",
"HATES",
"PIZZA",
"CHEESE",
"CONTEXT0",
"CONTEXT1",
"CONTEXT2",
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from test.data import TEST_DATA_DIR, cheese, likes, michel, pizza, tarek
from test.data import CHEESE, LIKES, MICHEL, PIZZA, TAREK, TEST_DATA_DIR

from rdflib import ConjunctiveGraph, Graph

Expand All @@ -8,98 +8,98 @@

def test_operators_with_conjunctivegraph_and_graph():
cg = ConjunctiveGraph()
cg.add((tarek, likes, pizza))
cg.add((tarek, likes, michel))
cg.add((TAREK, LIKES, PIZZA))
cg.add((TAREK, LIKES, MICHEL))

g = Graph()
g.add([tarek, likes, pizza])
g.add([tarek, likes, cheese])
g.add([TAREK, LIKES, PIZZA])
g.add([TAREK, LIKES, CHEESE])

assert len(cg + g) == 3 # adds cheese as liking
assert len(cg + g) == 3 # adds CHEESE as liking

assert len(cg - g) == 1 # removes pizza
assert len(cg - g) == 1 # removes PIZZA

assert len(cg * g) == 1 # only pizza
assert len(cg * g) == 1 # only PIZZA

assert len(cg ^ g) == 2 # removes pizza, adds cheese
assert len(cg ^ g) == 2 # removes PIZZA, adds CHEESE


def test_reversed_operators_with_conjunctivegraph_and_graph():
cg = ConjunctiveGraph()
cg.add((tarek, likes, pizza))
cg.add((tarek, likes, michel))
cg.add((TAREK, LIKES, PIZZA))
cg.add((TAREK, LIKES, MICHEL))

g = Graph()
g.add([tarek, likes, pizza])
g.add([tarek, likes, cheese])
g.add([TAREK, LIKES, PIZZA])
g.add([TAREK, LIKES, CHEESE])

assert len(g + cg) == 3 # adds cheese as liking
assert len(g + cg) == 3 # adds CHEESE as liking

assert len(g - cg) == 1 # removes pizza
assert len(g - cg) == 1 # removes PIZZA

assert len(g * cg) == 1 # only pizza
assert len(g * cg) == 1 # only PIZZA

assert len(g ^ cg) == 2 # removes pizza, adds cheese
assert len(g ^ cg) == 2 # removes PIZZA, adds CHEESE


def test_reversed_operators_with_conjunctivegraph_with_contexts_and_graph():
cg = ConjunctiveGraph()
cg.add((tarek, likes, pizza))
cg.add((tarek, likes, michel))
cg.add((TAREK, LIKES, PIZZA))
cg.add((TAREK, LIKES, MICHEL))
cg.parse(data=sportquadstrig, format="trig")

g = Graph()
g.add([tarek, likes, pizza])
g.add([tarek, likes, cheese])
g.add([TAREK, LIKES, PIZZA])
g.add([TAREK, LIKES, CHEESE])

assert len(g + cg) == 10 # adds cheese as liking plus sevenquads
assert len(g + cg) == 10 # adds CHEESE as liking plus sevenquads

assert len(list((g + cg).triples((None, None, None)))) == 10

assert len(g - cg) == 1 # removes pizza
assert len(g - cg) == 1 # removes PIZZA

assert len(g * cg) == 1 # only pizza
assert len(g * cg) == 1 # only PIZZA

assert len(g ^ cg) == 9 # removes pizza, adds cheese and sevenquads
assert len(g ^ cg) == 9 # removes PIZZA, adds CHEESE and sevenquads


def test_operators_with_two_conjunctivegraphs():
cg1 = ConjunctiveGraph()
cg1.add([tarek, likes, pizza])
cg1.add([tarek, likes, michel])
cg1.add([TAREK, LIKES, PIZZA])
cg1.add([TAREK, LIKES, MICHEL])

cg2 = ConjunctiveGraph()
cg2.add([tarek, likes, pizza])
cg2.add([tarek, likes, cheese])
cg2.add([TAREK, LIKES, PIZZA])
cg2.add([TAREK, LIKES, CHEESE])

assert len(cg1 + cg2) == 3 # adds cheese as liking
assert len(cg1 + cg2) == 3 # adds CHEESE as liking

assert len(cg1 - cg2) == 1 # removes pizza from cg1
assert len(cg1 - cg2) == 1 # removes PIZZA from cg1

assert len(cg1 * cg2) == 1 # only pizza
assert len(cg1 * cg2) == 1 # only PIZZA

assert len(cg1 + cg2) == 3 # adds cheese as liking
assert len(cg1 + cg2) == 3 # adds CHEESE as liking

assert len(cg1 ^ cg2) == 2 # removes pizza, adds cheese
assert len(cg1 ^ cg2) == 2 # removes PIZZA, adds CHEESE


def test_operators_with_two_conjunctivegraphs_one_with_contexts():
cg1 = ConjunctiveGraph()
cg1.add([tarek, likes, pizza])
cg1.add([tarek, likes, michel])
cg1.add([TAREK, LIKES, PIZZA])
cg1.add([TAREK, LIKES, MICHEL])

cg2 = ConjunctiveGraph()
cg2.add([tarek, likes, pizza])
cg2.add([tarek, likes, cheese])
cg2.add([TAREK, LIKES, PIZZA])
cg2.add([TAREK, LIKES, CHEESE])
cg2.parse(data=sportquadstrig, format="trig")

assert len(cg1 + cg2) == 10 # adds cheese as liking and all seven quads
assert len(cg1 + cg2) == 10 # adds CHEESE as liking and all seven quads

assert len(cg1 - cg2) == 1 # removes pizza
assert len(cg1 - cg2) == 1 # removes PIZZA

assert len(cg1 * cg2) == 1 # only pizza
assert len(cg1 * cg2) == 1 # only PIZZA

assert len(cg1 ^ cg2) == 9 # removes pizza
assert len(cg1 ^ cg2) == 9 # removes PIZZA


def test_operators_returning_correct_type():
Expand Down
26 changes: 13 additions & 13 deletions test/test_dataset/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import shutil
import tempfile
from test.data import context1, likes, pizza, tarek
from test.data import CONTEXT1, LIKES, PIZZA, TAREK
from test.utils.namespace import EGSCHEME

import pytest
Expand Down Expand Up @@ -115,30 +115,30 @@ def test_graph_aware(get_dataset):
if not dataset.store.graph_aware:
return

g1 = dataset.graph(context1)
g1 = dataset.graph(CONTEXT1)

# Some SPARQL endpoint backends (e.g. TDB) do not consider
# empty named graphs
if store != "SPARQLUpdateStore":
# added graph exists
assert set(x.identifier for x in dataset.contexts()) == set(
[context1, DATASET_DEFAULT_GRAPH_ID]
[CONTEXT1, DATASET_DEFAULT_GRAPH_ID]
)

# added graph is empty
assert len(g1) == 0

g1.add((tarek, likes, pizza))
g1.add((TAREK, LIKES, PIZZA))

# added graph still exists
assert set(x.identifier for x in dataset.contexts()) == set(
[context1, DATASET_DEFAULT_GRAPH_ID]
[CONTEXT1, DATASET_DEFAULT_GRAPH_ID]
)

# added graph contains one triple
assert len(g1) == 1

g1.remove((tarek, likes, pizza))
g1.remove((TAREK, LIKES, PIZZA))

# added graph is empty
assert len(g1) == 0
Expand All @@ -148,10 +148,10 @@ def test_graph_aware(get_dataset):
if store != "SPARQLUpdateStore":
# graph still exists, although empty
assert set(x.identifier for x in dataset.contexts()) == set(
[context1, DATASET_DEFAULT_GRAPH_ID]
[CONTEXT1, DATASET_DEFAULT_GRAPH_ID]
)

dataset.remove_graph(context1)
dataset.remove_graph(CONTEXT1)

# graph is gone
assert set(x.identifier for x in dataset.contexts()) == set(
Expand All @@ -170,7 +170,7 @@ def test_default_graph(get_dataset):
"is supported by your SPARQL endpoint"
)

dataset.add((tarek, likes, pizza))
dataset.add((TAREK, LIKES, PIZZA))
assert len(dataset) == 1
# only default exists
assert list(dataset.contexts()) == [dataset.default_context]
Expand All @@ -193,11 +193,11 @@ def test_not_union(get_dataset):
"its default graph as the union of the named graphs"
)

subgraph1 = dataset.graph(context1)
subgraph1.add((tarek, likes, pizza))
subgraph1 = dataset.graph(CONTEXT1)
subgraph1.add((TAREK, LIKES, PIZZA))

assert list(dataset.objects(tarek, None)) == []
assert list(subgraph1.objects(tarek, None)) == [pizza]
assert list(dataset.objects(TAREK, None)) == []
assert list(subgraph1.objects(TAREK, None)) == [PIZZA]


def test_iter(get_dataset):
Expand Down
24 changes: 12 additions & 12 deletions test/test_dataset/test_dataset_generators.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import os
from test.data import TEST_DATA_DIR, bob, cheese, hates, likes, michel, pizza, tarek
from test.data import BOB, CHEESE, HATES, LIKES, MICHEL, PIZZA, TAREK, TEST_DATA_DIR

from rdflib import Dataset, URIRef

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


def add_stuff(graph):
graph.add((tarek, likes, pizza))
graph.add((tarek, likes, cheese))
graph.add((tarek, likes, bob))
graph.add((tarek, likes, michel))
graph.add((michel, likes, pizza))
graph.add((michel, likes, cheese))
graph.add((michel, likes, tarek))
graph.add((bob, likes, cheese))
graph.add((bob, hates, pizza))
graph.add((bob, hates, michel))
graph.add((bob, likes, tarek))
graph.add((TAREK, LIKES, PIZZA))
graph.add((TAREK, LIKES, CHEESE))
graph.add((TAREK, LIKES, BOB))
graph.add((TAREK, LIKES, MICHEL))
graph.add((MICHEL, LIKES, PIZZA))
graph.add((MICHEL, LIKES, CHEESE))
graph.add((MICHEL, LIKES, TAREK))
graph.add((BOB, LIKES, CHEESE))
graph.add((BOB, HATES, PIZZA))
graph.add((BOB, HATES, MICHEL))
graph.add((BOB, LIKES, TAREK))


def test_unique_subjects():
Expand Down
8 changes: 4 additions & 4 deletions test/test_extras/test_infixowl/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from test.data import context0
from test.data import CONTEXT0

import pytest

Expand All @@ -17,7 +17,7 @@


def test_lshift_rlshift_delimiters():
g = Graph(identifier=context0)
g = Graph(identifier=CONTEXT0)
g.bind("ex", EXNS)

Individual.factoryGraph = g
Expand All @@ -40,7 +40,7 @@ def test_lshift_rlshift_delimiters():


def test_matmul_rmatmul_delimiters():
g = Graph(identifier=context0)
g = Graph(identifier=CONTEXT0)
g.bind("ex", EXNS)

Individual.factoryGraph = g
Expand Down Expand Up @@ -83,7 +83,7 @@ def test_infixowl_serialization():

@pytest.mark.webtest
def test_infix_owl_example1():
g = Graph(identifier=context0)
g = Graph(identifier=CONTEXT0)
g.bind("ex", EXNS)

Individual.factoryGraph = g
Expand Down
12 changes: 6 additions & 6 deletions test/test_extras/test_infixowl/test_class.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from test.data import context0, context1
from test.data import CONTEXT0, CONTEXT1

import pytest

Expand Down Expand Up @@ -216,7 +216,7 @@ def test_class_serialize(graph):
nameIsLabel=True,
)

g1 = Graph(identifier=context1)
g1 = Graph(identifier=CONTEXT1)

owlc.serialize(g1)

Expand All @@ -228,9 +228,9 @@ def test_class_serialize(graph):

owlc.extent = None

owlc.extent = [context1]
owlc.extent = [CONTEXT1]

assert list(owlc.extent) == [context1]
assert list(owlc.extent) == [CONTEXT1]

pred = RDFS.comment

Expand Down Expand Up @@ -273,7 +273,7 @@ def test_class_serialize(graph):


def test_class_nameislabel():
g = Graph(identifier=context0)
g = Graph(identifier=CONTEXT0)
g.bind("ex", EXNS)

Individual.factoryGraph = g
Expand Down Expand Up @@ -316,7 +316,7 @@ def test_class_nameislabel():


def test_class_nameisnotlabel():
g = Graph(identifier=context0)
g = Graph(identifier=CONTEXT0)
g.bind("ex", EXNS)

Individual.factoryGraph = g
Expand Down
Loading

0 comments on commit 8ee2d2f

Please sign in to comment.