Skip to content

N3 serializer "randomly" omits triple #1807

@ghost

Description

There seems to be an issue with the notation3 serializer randomly omitting to serialize triples.

Given the following test created in test/test_n3_formula.py ...

import pytest
import rdflib

test_n3 = """@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix : <http://test/> .
{:a :b :c;a :foo} => {:a :d :c,?y} .
_:foo a rdfs:Class .
:a :d :c ."""

@pytest.mark.xfail(reason="N3 serializer randomly omits triple")
def test():
    graph1 = rdflib.Graph()
    graph1.parse(data=test_n3, format="n3")

    """
    >>> sorted(list(graph1))
    [
        (
            rdflib.term.BNode('fde0470d85a044b6780f0c6804b119063b1'),
            rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
            rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#Class')
        ),
        (
            rdflib.term.URIRef('http://test/a'),
            rdflib.term.URIRef('http://test/d'),
            rdflib.term.URIRef('http://test/c')
        ),
        (
            <Graph identifier=_:Formula2 (<class 'rdflib.graph.QuotedGraph'>)>,
            rdflib.term.URIRef('http://www.w3.org/2000/10/swap/log#implies'),
            <Graph identifier=_:Formula3 (<class 'rdflib.graph.QuotedGraph'>)>
        )
    ]
    """

    graph2 = rdflib.Graph()
    graph2.parse(data=graph1.serialize(format="n3"), format="n3")
    assert (
        rdflib.term.URIRef('http://test/a'),
        rdflib.term.URIRef('http://test/d'),
        rdflib.term.URIRef('http://test/c')
    ) in graph2

Sample run_test.py results ...

(rdflib) $ ./run_tests.py test/test_n3_formula.py 
Running pytest with: ["test/test_n3_formula.py"]
============================================ test session starts =============================================
platform linux -- Python 3.8.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: rdflib, configfile: tox.ini
plugins: subtests-0.6.0, cov-3.0.0
collected 1 item                                                                                             

test/test_n3_formula.py::test XFAIL (N3 serializer randomly omits triple)                              [100%]

============================================= 1 xfailed in 0.02s =============================================
(rdflib) $ ./run_tests.py test/test_n3_formula.py 
Running pytest with: ["test/test_n3_formula.py"]
============================================ test session starts =============================================
platform linux -- Python 3.8.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: rdflib, configfile: tox.ini
plugins: subtests-0.6.0, cov-3.0.0
collected 1 item                                                                                             

test/test_n3_formula.py::test XPASS (N3 serializer randomly omits triple)                              [100%]

============================================= 1 xpassed in 0.01s =============================================

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingformat: N3Related to N3 format.serializationRelated to serialization.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions