Skip to content

Commit

Permalink
Add Decimal codec tests
Browse files Browse the repository at this point in the history
Ensure it both unwraps as a `String` (or `str`) and that the
`api.decimal()` encoder routine does the same.
  • Loading branch information
goodboy committed May 25, 2023
1 parent 5627e7c commit 8e0239a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ def test_integer():
assert isinstance(i, Integer)


def test_decimal():
d = tomlkit.decimal("34.56")

assert isinstance(d, String)


def test_float():
i = tomlkit.float_("34.56")

Expand Down
11 changes: 11 additions & 0 deletions tests/test_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import math
import pickle

from decimal import Decimal
from datetime import date
from datetime import datetime
from datetime import time
Expand Down Expand Up @@ -90,6 +91,16 @@ def test_integer_unwrap():
elementary_test(item(666), int)


def test_decimal_unwrap():
"""Ensure a decimal unwraps as a string
after TOML encode.
"""
elementary_test(
item(Decimal("0.001")),
str,
)


def test_float_unwrap():
elementary_test(item(2.78), float)

Expand Down

0 comments on commit 8e0239a

Please sign in to comment.