Skip to content

Commit

Permalink
Add an explicit test for Dataset.graph without identifier
Browse files Browse the repository at this point in the history
This is to test the somewhat arbitrary behaviour of binding the `genid`
namespace when `Dataset.graph` is used without an identifier.
  • Loading branch information
aucampia committed May 17, 2022
1 parent e7f91dc commit 7c51027
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion test/test_dataset/test_dataset.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# -*- coding: utf-8 -*-
import os
import re
import shutil
import tempfile
from test.data import context1, likes, pizza, tarek

import pytest

from rdflib import URIRef, plugin
from rdflib.graph import DATASET_DEFAULT_GRAPH_ID, Dataset
from rdflib.graph import DATASET_DEFAULT_GRAPH_ID, Dataset, Graph, Namespace

# Will also run SPARQLUpdateStore tests against local SPARQL1.1 endpoint if
# available. This assumes SPARQL1.1 query/update endpoints running locally at
Expand Down Expand Up @@ -231,3 +232,26 @@ def test_iter(get_dataset):
i_new += 1

assert i_new == i_trad # both should be 3


EGSCHEMA = Namespace("example:")


def test_subgraph_without_identifier() -> None:
"""
Graphs with no identifies assigned are identified by Skolem IRIs with a
prefix that is bound to `genid`.
TODO: This is somewhat questionable and arbitrary behaviour and should be
reviewed at some point.
"""

dataset = Dataset()

subgraph: Graph = dataset.graph()
subgraph.add((EGSCHEMA["subject"], EGSCHEMA["predicate"], EGSCHEMA["object"]))

data = dataset.serialize(format="trig")

re.match(r"\s+genid:\s+", data, re.MULTILINE | re.DOTALL)
re.match(r"genid:\S", data, re.MULTILINE | re.DOTALL)

0 comments on commit 7c51027

Please sign in to comment.