Skip to content

Commit eabab5f

Browse files
authored
Remove extra newline from N-Triples output (#1999)
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
1 parent 4f96f46 commit eabab5f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

rdflib/plugins/serializers/nt.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def serialize(
3939

4040
for triple in self.store:
4141
stream.write(_nt_row(triple).encode())
42-
stream.write("\n".encode())
4342

4443

4544
class NT11Serializer(NTSerializer):

test/test_issues/test_issue1998.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""Test that N-Triples formats do not have double newlines at the end
2+
of the output.
3+
4+
https://github.com/RDFLib/rdflib/issues/1998
5+
"""
6+
import rdflib
7+
8+
9+
def test_1998():
10+
g = rdflib.Graph()
11+
bob = rdflib.URIRef("http://example.org/people/Bob")
12+
g.add((bob, rdflib.RDF.type, rdflib.FOAF.Person))
13+
for nt_format in ("nt", "nt11"):
14+
output = g.serialize(format=nt_format)
15+
assert not output.endswith("\n\n")

0 commit comments

Comments
 (0)