File: test_finalnewline.py

package info (click to toggle)
rdflib 6.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 38,248 kB
  • sloc: python: 39,216; sh: 153; makefile: 110
file content (27 lines) | stat: -rw-r--r-- 839 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from rdflib import ConjunctiveGraph, URIRef
import rdflib.plugin


def testFinalNewline():
    """
    http://code.google.com/p/rdflib/issues/detail?id=5
    """

    graph = ConjunctiveGraph()
    graph.add(
        (
            URIRef("http://ex.org/a"),
            URIRef("http://ex.org/b"),
            URIRef("http://ex.org/c"),
        )
    )

    failed = set()
    for p in rdflib.plugin.plugins(None, rdflib.plugin.Serializer):
        v = graph.serialize(format=p.name, encoding="utf-8")
        lines = v.split("\n".encode("utf-8"))
        if b"\n" not in v or (lines[-1] != b""):
            failed.add(p.name)
    # JSON-LD does not require a final newline (because JSON doesn't)
    failed = failed.difference({"json-ld", "application/ld+json"})
    assert len(failed) == 0, "No final newline for formats: '%s'" % failed