From 83d9b88b5b8a561f9c1b24cae40dc49b85125409 Mon Sep 17 00:00:00 2001 From: nikokaoja Date: Tue, 30 Jul 2024 11:58:13 +0200 Subject: [PATCH] add parsererror --- oxrdflib/parser.py | 3 +++ tests/test_parser.py | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/oxrdflib/parser.py b/oxrdflib/parser.py index a6a6f89..f340cd8 100644 --- a/oxrdflib/parser.py +++ b/oxrdflib/parser.py @@ -117,6 +117,9 @@ def parse( encoding: Optional[str] = None, **kwargs: Any, ) -> None: + if not sink.context_aware: + raise ParserError("OxigraphNQuadsParser must be given a context aware store.") + super().parse(source, sink, format, encoding, **kwargs) diff --git a/tests/test_parser.py b/tests/test_parser.py index 10d458f..8d6606b 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -185,6 +185,28 @@ def test_parsing_ox_nquads_load(self): 2, ) + def test_parsing_ox_nquads_load_conjuctive(self): + graph = rdflib.ConjunctiveGraph(store="Oxigraph") + graph.parse(_TEST_DIR / "data/test.nq", format="ox-nquads", transactional=True) + self.assertEqual(len(graph), 6) + self.assertEqual(len(graph.query(_NAMEDGRAPH_QUERY)), 4) + self.assertEqual( + len(graph.query(_NAMEDGRAPH_TRIPLE_QUERY.format(namedgraph="urn:x-rdflib:default"))), + 2, + ) + self.assertEqual( + len(graph.query(_NAMEDGRAPH_TRIPLE_QUERY.format(namedgraph="http://example.com/graph3"))), + 1, + ) + self.assertEqual( + len(graph.query(_NAMEDGRAPH_TRIPLE_QUERY.format(namedgraph="http://example.com/graph2"))), + 1, + ) + self.assertEqual( + len(graph.query(_NAMEDGRAPH_TRIPLE_QUERY.format(namedgraph="http://example.com/graph1"))), + 2, + ) + if __name__ == "__main__": unittest.main()