Skip to content

Commit 9dd5a87

Browse files
jkhsjdhjss-heppner
authored andcommitted
test.model.datatypes: add (de-)serialization tests for Decimal
1 parent 0edb506 commit 9dd5a87

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

test/model/test_datatypes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,14 @@ def test_float(self) -> None:
273273
self.assertEqual("NaN", model.datatypes.xsd_repr(float("nan")))
274274
self.assertEqual("INF", model.datatypes.xsd_repr(float("inf")))
275275
self.assertEqual("-INF", model.datatypes.xsd_repr(float("-inf")))
276+
277+
278+
class TestDecimalType(unittest.TestCase):
279+
def test_parse_decimal(self) -> None:
280+
self.assertEqual(model.datatypes.Decimal("0.1"), model.datatypes.from_xsd("0.1", model.datatypes.Decimal))
281+
with self.assertRaises(ValueError) as cm:
282+
model.datatypes.from_xsd("foo", model.datatypes.Decimal)
283+
self.assertEqual("Cannot convert 'foo' to Decimal!", str(cm.exception))
284+
285+
def test_serialize_decimal(self) -> None:
286+
self.assertEqual("0.1", model.datatypes.xsd_repr(model.datatypes.Decimal("0.1")))

0 commit comments

Comments
 (0)