Fix for issue1769 · Pull Request #1771 · RDFLib/rdflib (original) (raw)

@gjhiggins would you be okay if I integrate the tests here into https://github.com/RDFLib/rdflib/blob/8a309774665182df135be9f2707303571764320a/test/test_parsers/test_parser_turtlelike.py ?

Oh, absolutely. I have zero sense of "ownership" - except perhaps for stuff other people wouldn't touch with a bargepole 😄 but thanks for asking.

Would prefer that as they should pass for many formats, and we likely have many other tests we want to perform on both from_n3 and on the other formats.

There's more to come in the general context of the test matrices area w.r.t. the dataset rework, I've been handling it thusly:

example2_root = os.path.join( CONSISTENT_DATA_DIR, "example-2-default-and-two-named-graphs." )

@pytest.fixture def example2(request): d = Dataset() d.bind("ex", Namespace("http://example.org/"))

alice = BNode()  # Alice
bob = BNode()  # Bob

alice_graph = d.graph(alice_uri)
bob_graph = d.graph(bob_uri)

d.add((alice_uri, DCTERMS.publisher, Literal("Alice")))
d.add((bob_uri, DCTERMS.publisher, Literal("Bob")))

alice_graph.add((alice, FOAF.mbox, URIRef("mailto:alice@work.example.org")))
alice_graph.add((alice, FOAF.name, Literal("Alice")))

bob_graph.add((bob, FOAF.name, Literal("Bob")))
bob_graph.add((bob, FOAF.mbox, URIRef("mailto:bob@oldcorp.example.org")))
bob_graph.add((bob, FOAF.knows, alice))

yield d, alice_graph, bob_graph

context_formats = [ "json-ld", "trix", "nquads", "trig", "hext", ]

@pytest.fixture def xfail_selected_context_parse_data_formats(request): fmt = request.getfixturevalue("fmt") expected_failures = [ # "json-ld", # "trix", # "nquads", # "trig", # "hext", ] if fmt in expected_failures: request.node.add_marker( pytest.mark.xfail(reason=f"Expected failure with {fmt}") )

@pytest.mark.parametrize("fmt", context_formats) @pytest.mark.usefixtures("xfail_selected_context_parse_data_formats") def test_parse_example2_from_data(fmt, example2): # Use programmatically-created graphs as standard to be checked against d1, alice_graph, bob_graph = example2

d2 = Dataset()
d2.bind("ex", Namespace("http://example.org/"))
with open(example2_root + fmt, "r") as fp:
    d2.parse(data=fp.read(), format=fmt)

assert len(list(d2.contexts())) == 2
assert len(list(d2.graphs())) == 2
assert len(d2) == 2
assert alice_uri in d2.contexts()
assert bob_uri in d2.contexts()
assert len(list(d1.quads((None, None, None, None)))) == len(
    list(d2.quads((None, None, None, None)))
)
assert len(d1.store) == len(d2.store)
assert isomorphic(d1, d2)