Skip to content

Commit 9823394

Browse files
committed
Add Decimal codec tests
Ensure it both unwraps as a `String` (or `str`) and that the `api.decimal()` encoder routine does the same.
1 parent 84588ec commit 9823394

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

tests/test_api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ def test_integer():
187187
assert isinstance(i, Integer)
188188

189189

190+
def test_decimal():
191+
d = tomlkit.decimal("34.56")
192+
193+
assert isinstance(d, String)
194+
195+
190196
def test_float():
191197
i = tomlkit.float_("34.56")
192198

tests/test_items.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import math
33
import pickle
44

5+
from decimal import Decimal
56
from datetime import date
67
from datetime import datetime
78
from datetime import time
@@ -90,6 +91,16 @@ def test_integer_unwrap():
9091
elementary_test(item(666), int)
9192

9293

94+
def test_decimal_unwrap():
95+
"""Ensure a decimal unwraps as a string
96+
after TOML encode.
97+
"""
98+
elementary_test(
99+
item(Decimal("0.001")),
100+
str,
101+
)
102+
103+
93104
def test_float_unwrap():
94105
elementary_test(item(2.78), float)
95106

0 commit comments

Comments
 (0)