Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1043. #1054

Merged
merged 3 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions rdflib/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,10 +1259,9 @@ def _literal_n3(self, use_plain=False, qname_callback=None):
return sub("\\.?0*e", "e", "%e" % float(self))
elif self.datatype == _XSD_DECIMAL:
s = "%s" % self
if "." not in s:
if "." not in s and "e" not in s and "E" not in s:
s += ".0"
return s

elif self.datatype == _XSD_BOOLEAN:
return ("%s" % self).lower()
else:
Expand Down
33 changes: 33 additions & 0 deletions test/test_issue1043.py
Original file line number Diff line number Diff line change
@@ -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: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://example.org/number> 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()