Skip to content

Commit

Permalink
Remove extra newline from N-Triples output (#1999)
Browse files Browse the repository at this point in the history
Remove the extra newline generated by the N-Triples serializer and add
a unit test to verify that N-Triples output does not end in two
consecutive newlines.

Closes #1998
  • Loading branch information
tcmitchell committed Jun 24, 2022
1 parent 4f96f46 commit eabab5f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 0 additions & 1 deletion rdflib/plugins/serializers/nt.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def serialize(

for triple in self.store:
stream.write(_nt_row(triple).encode())
stream.write("\n".encode())


class NT11Serializer(NTSerializer):
Expand Down
15 changes: 15 additions & 0 deletions test/test_issues/test_issue1998.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Test that N-Triples formats do not have double newlines at the end
of the output.
https://github.com/RDFLib/rdflib/issues/1998
"""
import rdflib


def test_1998():
g = rdflib.Graph()
bob = rdflib.URIRef("http://example.org/people/Bob")
g.add((bob, rdflib.RDF.type, rdflib.FOAF.Person))
for nt_format in ("nt", "nt11"):
output = g.serialize(format=nt_format)
assert not output.endswith("\n\n")

0 comments on commit eabab5f

Please sign in to comment.