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 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions rdflib/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -1242,8 +1242,6 @@ 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
achaudhary997 marked this conversation as resolved.
Show resolved Hide resolved
if '.' not in s:
s += '.0'
return s

elif self.datatype == _XSD_BOOLEAN:
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()