Skip to content

Commit

Permalink
Use Decimal for parsing JSON to mitigate precision problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Argmaster committed Jun 7, 2024
1 parent b4f239d commit 0b82717
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions test/gerberx3/test_assets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import decimal
import json
from dataclasses import dataclass

Expand Down Expand Up @@ -182,8 +183,14 @@ def test_parser2(asset: Asset, config: Config) -> None:
".parser2", asset.relative_path
).with_suffix(".json")

output_file_content = json.loads(output_file_path.read_text())
reference_file_content = json.loads(reference_path.read_text())
output_file_content = json.loads(
output_file_path.read_text(),
parse_float=lambda x: round(decimal.Decimal(x), 6),
)
reference_file_content = json.loads(
reference_path.read_text(),
parse_float=lambda x: round(decimal.Decimal(x), 6),
)

assert output_file_content == reference_file_content

Expand Down

0 comments on commit 0b82717

Please sign in to comment.