Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ and this project adheres to
### Fixed

- Fix leaked file handles in tests using context managers ([b66a6f5], [#25])
- Fix `Decimal.normalize()` stripping trailing zeros, breaking round-trip
serialization; add regression test ([28c76f1], [0130743], [#28])
- Fix typo in test name: `test_l9events_form_ip4scout` ->
`test_l9events_from_ip4scout` ([0d8736e], [#27])

Expand Down Expand Up @@ -152,6 +154,8 @@ and this project adheres to

<!-- Commit links -->

[0130743]: https://github.com/LeakIX/l9format-python/commit/0130743
[28c76f1]: https://github.com/LeakIX/l9format-python/commit/28c76f1
[b66a6f5]: https://github.com/LeakIX/l9format-python/commit/b66a6f5
[cbea4fc]: https://github.com/LeakIX/l9format-python/commit/cbea4fc
[3547e22]: https://github.com/LeakIX/l9format-python/commit/3547e22
Expand Down Expand Up @@ -221,6 +225,7 @@ and this project adheres to
[#21]: https://github.com/LeakIX/l9format-python/issues/21
[#22]: https://github.com/LeakIX/l9format-python/issues/22
[#26]: https://github.com/LeakIX/l9format-python/issues/26
[#28]: https://github.com/LeakIX/l9format-python/issues/28
[#27]: https://github.com/LeakIX/l9format-python/issues/27
[#33]: https://github.com/LeakIX/l9format-python/issues/33
[#25]: https://github.com/LeakIX/l9format-python/issues/25
Expand Down
4 changes: 1 addition & 3 deletions l9format/l9format.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
def round_decimal(
decimal_obj: decimal.Decimal, num_of_places: int = 6
) -> decimal.Decimal:
return decimal_obj.quantize(
decimal.Decimal(10) ** -num_of_places
).normalize()
return decimal_obj.quantize(decimal.Decimal(10) ** -num_of_places)


class Decimal(fields.Instance):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,14 @@ def test_geopoint_negative_values(self) -> None:
assert gp.lat == -1.5
assert gp.lon == -2.5

def test_geopoint_round_trip_preserves_value(self) -> None:
"""Regression: normalize() used to strip trailing zeros."""
gp = GeoPoint.from_dict({"lat": "1.000000", "lon": "2.500000"})
serialized = gp.to_dict()
gp2 = GeoPoint.from_dict(serialized)
assert gp2.lat == gp.lat
assert gp2.lon == gp.lon


class TestComplexNestedValidation:
"""Test validation behavior with complex nested structures."""
Expand Down