Skip to content

Commit a7b3a53

Browse files
committed
wip
1 parent b9d6c70 commit a7b3a53

File tree

8 files changed

+27
-42
lines changed

8 files changed

+27
-42
lines changed

test/test_w3c_spec/test_nquads_w3c_new.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
test suite."""
33
import logging
44
from contextlib import ExitStack
5-
from pathlib import Path
65
from test.data import TEST_DATA_DIR
76
from test.utils import BNodeHandling, GraphHelper, ensure_suffix
8-
from test.utils.iri import URIMapper, file_uri_to_path
7+
from test.utils.iri import URIMapper
98
from test.utils.namespace import RDFT
109
from test.utils.rdftest import ManifestEntry, params_from_sources
1110
from typing import Optional
@@ -30,27 +29,27 @@
3029
def check_entry(entry: ManifestEntry) -> None:
3130
assert entry.action is not None
3231
assert entry.type in VALID_TYPES
33-
action_local = MAPPER.to_local(
32+
action_path = MAPPER.to_local_path(
3433
entry.action
3534
) # rebase_url(entry.mf_action, REMOTE_BASE_IRI, LOCAL_BASE_DIR.as_uri())
3635
if logger.isEnabledFor(logging.DEBUG):
37-
action_path = file_uri_to_path(action_local, Path)
36+
# action_path = file_uri_to_path(action_local, Path)
3837
logger.debug("action = %s\n%s", action_path, action_path.read_text())
3938
catcher: Optional[pytest.ExceptionInfo[Exception]] = None
4039
dataset = Dataset()
4140

4241
with ExitStack() as xstack:
4342
if entry.type == RDFT.TestNQuadsNegativeSyntax:
4443
catcher = xstack.enter_context(pytest.raises(Exception))
45-
dataset.parse(action_local, publicID=entry.action, format="nquads")
44+
dataset.parse(action_path, publicID=entry.action, format="nquads")
4645
if catcher is not None:
4746
assert catcher.value is not None
4847

4948
if entry.type == RDFT.TestNQuadsPositiveSyntax:
5049
graph_data = dataset.serialize(format="nquads")
5150
result_dataset = Dataset()
5251
result_dataset.parse(data=graph_data, publicID=entry.action, format="nquads")
53-
GraphHelper.assert_datasets_isomorphic(
52+
GraphHelper.assert_cgraph_isomorphic(
5453
dataset, result_dataset, exclude_bnodes=True
5554
)
5655
GraphHelper.assert_sets_equals(

test/test_w3c_spec/test_ntriples_w3c_new.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
test suite."""
33
import logging
44
from contextlib import ExitStack
5-
from pathlib import Path
65
from test.data import TEST_DATA_DIR
76
from test.utils import BNodeHandling, GraphHelper, ensure_suffix
8-
from test.utils.iri import URIMapper, file_uri_to_path
7+
from test.utils.iri import URIMapper
98
from test.utils.namespace import RDFT
109
from test.utils.rdftest import ManifestEntry, params_from_sources
1110
from typing import Optional
@@ -29,18 +28,17 @@
2928
def check_entry(entry: ManifestEntry) -> None:
3029
assert entry.action is not None
3130
assert entry.type in VALID_TYPES
32-
action_local = MAPPER.to_local(
31+
action_path = MAPPER.to_local_path(
3332
entry.action
3433
) # rebase_url(entry.mf_action, REMOTE_BASE_IRI, LOCAL_BASE_DIR.as_uri())
3534
if logger.isEnabledFor(logging.DEBUG):
36-
action_path = file_uri_to_path(action_local, Path)
3735
logger.debug("action = %s\n%s", action_path, action_path.read_text())
3836
catcher: Optional[pytest.ExceptionInfo[Exception]] = None
3937
graph = Graph()
4038
with ExitStack() as xstack:
4139
if entry.type == RDFT.TestNTriplesNegativeSyntax:
4240
catcher = xstack.enter_context(pytest.raises(Exception))
43-
graph.parse(action_local, publicID=entry.action, format="ntriples")
41+
graph.parse(action_path, publicID=entry.action, format="ntriples")
4442
if catcher is not None:
4543
assert catcher.value is not None
4644

test/test_w3c_spec/test_rdfxml_w3c_new.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import logging
22
from contextlib import ExitStack
3-
from pathlib import Path
43
from test.data import TEST_DATA_DIR
54
from test.utils import BNodeHandling, GraphHelper, ensure_suffix
6-
from test.utils.iri import URIMapper, file_uri_to_path, rebase_url
5+
from test.utils.iri import URIMapper, rebase_url
76
from test.utils.namespace import RDFT
87
from test.utils.rdftest import ManifestEntry, params_from_sources
98
from typing import Optional
@@ -27,18 +26,17 @@
2726
def check_entry(entry: ManifestEntry) -> None:
2827
assert entry.action is not None
2928
assert entry.type in VALID_TYPES
30-
action_local = MAPPER.to_local(
29+
action_path = MAPPER.to_local_path(
3130
entry.action
3231
) # rebase_url(entry.mf_action, REMOTE_BASE_IRI, LOCAL_BASE_DIR.as_uri())
3332
if logger.isEnabledFor(logging.DEBUG):
34-
action_path = file_uri_to_path(action_local, Path)
3533
logger.debug("action = %s\n%s", action_path, action_path.read_text())
3634
catcher: Optional[pytest.ExceptionInfo[Exception]] = None
3735
graph = Graph()
3836
with ExitStack() as xstack:
3937
if entry.type == RDFT.TestXMLNegativeSyntax:
4038
catcher = xstack.enter_context(pytest.raises(Exception))
41-
graph.parse(action_local, publicID=entry.action, format="xml")
39+
graph.parse(action_path, publicID=entry.action, format="xml")
4240

4341
if catcher is not None:
4442
assert catcher.value is not None

test/test_w3c_spec/test_sparql_w3c_new.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from rdflib.plugins.sparql.algebra import translateQuery, translateUpdate
2525
from rdflib.plugins.sparql.parser import parseQuery, parseUpdate
2626
from rdflib.plugins.sparql.results.rdfresults import RDFResultParser
27-
from rdflib.plugins.sparql.update import evalUpdate
2827
from rdflib.query import Result
2928
from rdflib.term import BNode, IdentifiedNode, Identifier, Literal, Node, URIRef
3029
from rdflib.util import guess_format
@@ -351,7 +350,7 @@ def check_update(entry: SPARQLEntry) -> None:
351350
"dataset before = \n%s",
352351
dataset.serialize(format="trig"),
353352
)
354-
result = dataset.update(query_text)
353+
dataset.update(query_text)
355354
# update = translateUpdate(parseUpdate(query_text))
356355
# evalUpdate(dataset, update)
357356

@@ -369,7 +368,7 @@ def check_update(entry: SPARQLEntry) -> None:
369368
expected_result.serialize(format="trig"),
370369
)
371370

372-
GraphHelper.assert_datasets_isomorphic(
371+
GraphHelper.assert_cgraph_isomorphic(
373372
expected_result, dataset, exclude_bnodes=True
374373
)
375374
GraphHelper.assert_sets_equals(expected_result, dataset, BNodeHandling.COLLAPSE)

test/test_w3c_spec/test_trig_w3c_new.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import logging
22
from contextlib import ExitStack
3-
from pathlib import Path
43
from test.data import TEST_DATA_DIR
54
from test.utils import BNodeHandling, GraphHelper, ensure_suffix
6-
from test.utils.iri import URIMapper, file_uri_to_path, rebase_url
5+
from test.utils.iri import URIMapper, rebase_url
76
from test.utils.namespace import RDFT
87
from test.utils.rdftest import ManifestEntry, params_from_sources
98
from typing import Optional
@@ -37,16 +36,15 @@
3736
def check_entry(entry: ManifestEntry) -> None:
3837
assert entry.action is not None
3938
assert entry.type in VALID_TYPES
40-
action_local = MAPPER.to_local(entry.action)
39+
action_path = MAPPER.to_local_path(entry.action)
4140
if logger.isEnabledFor(logging.DEBUG):
42-
action_path = file_uri_to_path(action_local, Path)
4341
logger.debug("action = %s\n%s", action_path, action_path.read_text())
4442
catcher: Optional[pytest.ExceptionInfo[Exception]] = None
4543
dataset = Dataset()
4644
with ExitStack() as xstack:
4745
if entry.type in (RDFT.TestTrigNegativeSyntax, RDFT.TestTrigNegativeEval):
4846
catcher = xstack.enter_context(pytest.raises(Exception))
49-
dataset.parse(action_local, publicID=entry.action, format="trig")
47+
dataset.parse(action_path, publicID=entry.action, format="trig")
5048

5149
if catcher is not None:
5250
assert catcher.value is not None
@@ -58,7 +56,7 @@ def check_entry(entry: ManifestEntry) -> None:
5856
)
5957
result_dataset = Dataset()
6058
result_dataset.parse(result_source, publicID=entry.action, format="nquads")
61-
GraphHelper.assert_datasets_isomorphic(
59+
GraphHelper.assert_cgraph_isomorphic(
6260
dataset, result_dataset, exclude_bnodes=True
6361
)
6462
GraphHelper.assert_sets_equals(

test/test_w3c_spec/test_turtle_w3c_new.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import logging
22
from contextlib import ExitStack
3-
from pathlib import Path
43
from test.data import TEST_DATA_DIR
54
from test.utils import BNodeHandling, GraphHelper, ensure_suffix
6-
from test.utils.iri import URIMapper, file_uri_to_path, rebase_url
5+
from test.utils.iri import URIMapper, rebase_url
76
from test.utils.namespace import RDFT
87
from test.utils.rdftest import ManifestEntry, params_from_sources
98
from typing import Optional
@@ -37,16 +36,15 @@
3736
def check_entry(entry: ManifestEntry) -> None:
3837
assert entry.action is not None
3938
assert entry.type in VALID_TYPES
40-
action_local = MAPPER.to_local(entry.action)
39+
action_path = MAPPER.to_local_path(entry.action)
4140
if logger.isEnabledFor(logging.DEBUG):
42-
action_path = file_uri_to_path(action_local, Path)
4341
logger.debug("action = %s\n%s", action_path, action_path.read_text())
4442
catcher: Optional[pytest.ExceptionInfo[Exception]] = None
4543
graph = Graph()
4644
with ExitStack() as xstack:
4745
if entry.type in (RDFT.TestTurtleNegativeSyntax, RDFT.TestTurtleNegativeEval):
4846
catcher = xstack.enter_context(pytest.raises(Exception))
49-
graph.parse(action_local, publicID=entry.action, format="turtle")
47+
graph.parse(action_path, publicID=entry.action, format="turtle")
5048

5149
if catcher is not None:
5250
assert catcher.value is not None

test/utils/__init__.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,7 @@ def assert_isomorphic(
337337
This asserts that the two graphs are isomorphic, providing a nicely
338338
formatted error message if they are not.
339339
"""
340-
assert not isinstance(
341-
lhs, ConjunctiveGraph
342-
), "cannot operate on ConjunctiveGraph"
343-
assert not isinstance(
344-
rhs, ConjunctiveGraph
345-
), "cannot operate on ConjunctiveGraph"
346-
340+
# TODO FIXME: This should possibly raise an error when use on ConjunctiveGraph
347341
def format_report(message: Optional[str] = None) -> str:
348342
in_both, in_lhs, in_rhs = rdflib.compare.graph_diff(lhs, rhs)
349343
preamle = "" if message is None else f"{message}\n"
@@ -359,16 +353,16 @@ def format_report(message: Optional[str] = None) -> str:
359353
assert rdflib.compare.isomorphic(lhs, rhs), format_report(message)
360354

361355
@classmethod
362-
def assert_datasets_isomorphic(
356+
def assert_cgraph_isomorphic(
363357
cls,
364-
lhs: Dataset,
365-
rhs: Dataset,
358+
lhs: ConjunctiveGraph,
359+
rhs: ConjunctiveGraph,
366360
exclude_bnodes: bool,
367361
message: Optional[str] = None,
368362
) -> None:
369-
def get_contexts(dataset: Dataset) -> Dict[URIRef, Graph]:
363+
def get_contexts(cgraph: ConjunctiveGraph) -> Dict[URIRef, Graph]:
370364
result = {}
371-
for context in dataset.contexts():
365+
for context in cgraph.contexts():
372366
if isinstance(context.identifier, BNode):
373367
if exclude_bnodes:
374368
continue

test/utils/rdftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def from_graph(
131131
# public_id: Optional[str] = None,
132132
) -> Generator["Manifest", None, None]:
133133
for identifier in graph.subjects(RDF.type, MF.Manifest):
134+
assert isinstance(identifier, IdentifiedNode)
134135
manifest = Manifest(
135136
uri_mapper,
136137
graph,

0 commit comments

Comments
 (0)