From c7c4e15a4ad021d8c6ae518b435b0841cf488e9a Mon Sep 17 00:00:00 2001 From: Anubhav Chaudhary Date: Tue, 19 May 2020 11:23:24 +0530 Subject: [PATCH] Fixes #1043. * Added test case for #1043 * Don't make XSD.Decimal pretty during serialization --- rdflib/term.py | 4 ++-- test/test_issue1043.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 test/test_issue1043.py diff --git a/rdflib/term.py b/rdflib/term.py index 125210df8..0dfac0565 100644 --- a/rdflib/term.py +++ b/rdflib/term.py @@ -1242,8 +1242,8 @@ def _literal_n3(self, use_plain=False, qname_callback=None): return sub("\\.?0*e", "e", u'%e' % float(self)) elif self.datatype == _XSD_DECIMAL: s = '%s' % self - if '.' not in s: - s += '.0' + # if '.' not in s: + # s += '.0' return s elif self.datatype == _XSD_BOOLEAN: diff --git a/test/test_issue1043.py b/test/test_issue1043.py new file mode 100644 index 000000000..db202d774 --- /dev/null +++ b/test/test_issue1043.py @@ -0,0 +1,33 @@ +import decimal +import unittest +import io +import sys + +from rdflib import Graph, Namespace, XSD, RDFS, Literal + + +class TestIssue1043(unittest.TestCase): + + def test_issue_1043(self): + expected = """@prefix rdfs: . +@prefix xsd: . + + rdfs:label 4e-08 . + + +""" + capturedOutput = io.StringIO() + sys.stdout = capturedOutput + g = Graph() + g.bind('xsd', XSD) + g.bind('rdfs', RDFS) + n = Namespace("http://example.org/") + g.add((n.number, RDFS.label, Literal(0.00000004, datatype=XSD.decimal))) + print(g.serialize(format="turtle").decode("utf-8")) + sys.stdout = sys.__stdout__ + self.assertEqual(capturedOutput.getvalue(), expected) + + + +if __name__ == "__main__": + unittest.main() \ No newline at end of file