generated from ApeWorX/project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: error checking type for "subscripted generics" (#77)
* fix: error checking type for "subscripted generics" * fix(type): get_args still needed for union check * refactor: introduce `is_scalar_type` instead * refactor: change name for better readability * refactor: use Datapoints root model to assist in automated conversion * fix: unused imports * test: add test for Datapoints parsing * fix: add dict methods to Datapoints --------- Co-authored-by: fubuloubu <[email protected]>
- Loading branch information
1 parent
1b49588
commit 29c24f1
Showing
3 changed files
with
95 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from decimal import Decimal | ||
|
||
import pytest | ||
|
||
from silverback.types import Datapoints | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"raw_return,expected", | ||
[ | ||
# String datapoints don't parse (empty datapoints) | ||
({"a": "b"}, {}), | ||
# ints parse | ||
({"a": 1}, {"a": {"type": "scalar", "data": 1}}), | ||
# max INT96 value | ||
( | ||
{"a": 2**96 - 1}, | ||
{"a": {"type": "scalar", "data": 79228162514264337593543950335}}, | ||
), | ||
# int over INT96 max parses as Decimal | ||
( | ||
{"a": 2**96}, | ||
{"a": {"type": "scalar", "data": Decimal("79228162514264337593543950336")}}, | ||
), | ||
# Decimal parses as Decimal | ||
( | ||
{"a": Decimal("1e12")}, | ||
{"a": {"type": "scalar", "data": Decimal("1000000000000")}}, | ||
), | ||
# float parses as float | ||
( | ||
{"a": 1e12}, | ||
{"a": {"type": "scalar", "data": 1000000000000.0}}, | ||
), | ||
], | ||
) | ||
def test_datapoint_parsing(raw_return, expected): | ||
assert Datapoints(root=raw_return).model_dump() == expected |