summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshley Sommer <ashleysommer@gmail.com>2020-09-18 10:32:08 +1000
committerGitHub <noreply@github.com>2020-09-18 10:32:08 +1000
commit7289f6876fc8ee497ffc7028ddfbc768dca6b3c0 (patch)
tree54cc629e3117a89252fb566b7a8697c89aec899f
parentc0d017ba8fc8a16b6f394ffd90248728aa5ada1c (diff)
parent8441263a5f1c698f92cab20740b78a51ee85235d (diff)
downloadrdflib-7289f6876fc8ee497ffc7028ddfbc768dca6b3c0.tar.gz
Merge pull request #1054 from achaudhary997/fix1043
Fixes #1043.
-rw-r--r--rdflib/term.py3
-rw-r--r--test/test_issue1043.py33
2 files changed, 34 insertions, 2 deletions
diff --git a/rdflib/term.py b/rdflib/term.py
index 32ec6af4..ac69c3bd 100644
--- a/rdflib/term.py
+++ b/rdflib/term.py
@@ -1259,10 +1259,9 @@ class Literal(Identifier):
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:
diff --git a/test/test_issue1043.py b/test/test_issue1043.py
new file mode 100644
index 00000000..db202d77
--- /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: <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() \ No newline at end of file