Skip to content

Commit 7289f68

Browse files
authored
Merge pull request #1054 from achaudhary997/fix1043
Fixes #1043.
2 parents c0d017b + 8441263 commit 7289f68

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

rdflib/term.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,10 +1259,9 @@ def _literal_n3(self, use_plain=False, qname_callback=None):
12591259
return sub("\\.?0*e", "e", "%e" % float(self))
12601260
elif self.datatype == _XSD_DECIMAL:
12611261
s = "%s" % self
1262-
if "." not in s:
1262+
if "." not in s and "e" not in s and "E" not in s:
12631263
s += ".0"
12641264
return s
1265-
12661265
elif self.datatype == _XSD_BOOLEAN:
12671266
return ("%s" % self).lower()
12681267
else:

test/test_issue1043.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import decimal
2+
import unittest
3+
import io
4+
import sys
5+
6+
from rdflib import Graph, Namespace, XSD, RDFS, Literal
7+
8+
9+
class TestIssue1043(unittest.TestCase):
10+
11+
def test_issue_1043(self):
12+
expected = """@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
13+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
14+
15+
<http://example.org/number> rdfs:label 4e-08 .
16+
17+
18+
"""
19+
capturedOutput = io.StringIO()
20+
sys.stdout = capturedOutput
21+
g = Graph()
22+
g.bind('xsd', XSD)
23+
g.bind('rdfs', RDFS)
24+
n = Namespace("http://example.org/")
25+
g.add((n.number, RDFS.label, Literal(0.00000004, datatype=XSD.decimal)))
26+
print(g.serialize(format="turtle").decode("utf-8"))
27+
sys.stdout = sys.__stdout__
28+
self.assertEqual(capturedOutput.getvalue(), expected)
29+
30+
31+
32+
if __name__ == "__main__":
33+
unittest.main()

0 commit comments

Comments
 (0)