Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 204a048

Browse files
committed
Added tests
1 parent 859b6de commit 204a048

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

plotly/tests/test_optional/test_utils/test_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import datetime
88
import json
99
import math
10+
import decimal
1011
from datetime import datetime as dt
1112
from unittest import TestCase
1213

@@ -149,6 +150,13 @@ def test_encode_as_date(self):
149150
)
150151
self.assertEqual(res, '2013-10-01 00:00:00.000010')
151152

153+
def test_encode_as_decimal(self):
154+
155+
# should work with decimal values
156+
res = utils.PlotlyJSONEncoder.encode_as_decimal(decimal.Decimal(1.023452))
157+
158+
self.assertAlmostEqual(res, 1.023452) # Checks upto 7 decimal places
159+
self.assertIsInstance(res, float)
152160

153161
## JSON encoding
154162
numeric_list = [1, 2, 3]

plotly/utils.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,6 @@ def coerce_to_strict(self, const):
131131
# before python 2.7, 'true', 'false', 'null', were include here.
132132
if const in ('Infinity', '-Infinity', 'NaN'):
133133
return None
134-
# Decimal Fails on Serialization, convert it to float
135-
elif isinstance(const, decimal.Decimal):
136-
return float(const)
137134
else:
138135
return const
139136

0 commit comments

Comments
 (0)