plexus-python-common 1.1.91__py3-none-any.whl → 1.1.93__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- plexus/common/utils/testutils.py +41 -27
- {plexus_python_common-1.1.91.dist-info → plexus_python_common-1.1.93.dist-info}/METADATA +2 -2
- {plexus_python_common-1.1.91.dist-info → plexus_python_common-1.1.93.dist-info}/RECORD +5 -5
- {plexus_python_common-1.1.91.dist-info → plexus_python_common-1.1.93.dist-info}/WHEEL +0 -0
- {plexus_python_common-1.1.91.dist-info → plexus_python_common-1.1.93.dist-info}/top_level.txt +0 -0
plexus/common/utils/testutils.py
CHANGED
|
@@ -4,7 +4,7 @@ from decimal import Decimal
|
|
|
4
4
|
from typing import Any, Protocol
|
|
5
5
|
|
|
6
6
|
import pytest
|
|
7
|
-
from _pytest.
|
|
7
|
+
from _pytest.approx import ApproxDecimal, ApproxMapping, ApproxSequenceLike
|
|
8
8
|
|
|
9
9
|
from plexus.common.utils.numutils import to_decimal
|
|
10
10
|
|
|
@@ -16,8 +16,14 @@ __all__ = [
|
|
|
16
16
|
"throw_callee",
|
|
17
17
|
]
|
|
18
18
|
|
|
19
|
+
SupportApprox = int | float | str | bool | list | tuple | dict | Decimal | datetime.datetime | datetime.date | datetime.time | datetime.timedelta | None
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ApproxNestedMixin(pytest.Approx):
|
|
23
|
+
def __init__(self, expected, rel: SupportApprox = None, abs: SupportApprox = None, nan_ok: bool = False):
|
|
24
|
+
# Bypass the container constructors, which reject nested values.
|
|
25
|
+
pytest.Approx.__init__(self, expected, rel, abs, nan_ok)
|
|
19
26
|
|
|
20
|
-
class ApproxNestedMixin(ApproxBase):
|
|
21
27
|
def __repr__(self) -> str:
|
|
22
28
|
|
|
23
29
|
def recur_repr_helper(obj):
|
|
@@ -28,42 +34,50 @@ class ApproxNestedMixin(ApproxBase):
|
|
|
28
34
|
elif isinstance(obj, list):
|
|
29
35
|
return list(recur_repr_helper(o) for o in obj)
|
|
30
36
|
else:
|
|
31
|
-
return self.
|
|
37
|
+
return nested_approx(obj, self.rel, self.abs, self.nan_ok)
|
|
32
38
|
|
|
33
39
|
return "approx({!r})".format(recur_repr_helper(self.expected))
|
|
34
40
|
|
|
35
|
-
def _approx_scalar(self, x) -> ApproxScalar:
|
|
36
|
-
if isinstance(x, Decimal):
|
|
37
|
-
return ApproxDecimal(x, to_decimal(self.rel), to_decimal(self.abs), self.nan_ok)
|
|
38
|
-
return ApproxScalar(x, self.rel, self.abs, self.nan_ok)
|
|
39
|
-
|
|
40
|
-
def _check_type(self):
|
|
41
|
-
pass
|
|
42
|
-
|
|
43
41
|
|
|
44
42
|
class ApproxNestedSequenceLike(ApproxNestedMixin, ApproxSequenceLike):
|
|
45
43
|
|
|
46
|
-
def
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
44
|
+
def __eq__(self, actual):
|
|
45
|
+
if not isinstance(actual, (list, tuple)) or len(actual) != len(self.expected):
|
|
46
|
+
return False
|
|
47
|
+
return all(
|
|
48
|
+
value == nested_approx(expected, self.rel, self.abs, self.nan_ok)
|
|
49
|
+
for value, expected in zip(actual, self.expected)
|
|
50
|
+
)
|
|
53
51
|
|
|
54
52
|
|
|
55
53
|
class ApproxNestedMapping(ApproxNestedMixin, ApproxMapping):
|
|
56
54
|
|
|
57
|
-
def
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
def __eq__(self, actual):
|
|
56
|
+
if not isinstance(actual, dict) or actual.keys() != self.expected.keys():
|
|
57
|
+
return False
|
|
58
|
+
return all(
|
|
59
|
+
actual[key] == nested_approx(expected, self.rel, self.abs, self.nan_ok)
|
|
60
|
+
for key, expected in self.expected.items()
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class ApproxDataTime(pytest.Approx):
|
|
65
|
+
|
|
66
|
+
def __repr__(self) -> str:
|
|
67
|
+
return f"approx({self.expected!r})"
|
|
68
|
+
|
|
69
|
+
def __eq__(self, actual) -> bool:
|
|
70
|
+
return actual == self.expected
|
|
64
71
|
|
|
65
72
|
|
|
66
|
-
def nested_approx(
|
|
73
|
+
def nested_approx(
|
|
74
|
+
expected,
|
|
75
|
+
rel: SupportApprox = None,
|
|
76
|
+
abs: SupportApprox = None,
|
|
77
|
+
nan_ok: bool = False,
|
|
78
|
+
) -> pytest.Approx:
|
|
79
|
+
if expected is None or isinstance(expected, str):
|
|
80
|
+
return pytest.approx(expected, nan_ok=nan_ok)
|
|
67
81
|
if isinstance(expected, dict):
|
|
68
82
|
return ApproxNestedMapping(expected, rel, abs, nan_ok)
|
|
69
83
|
if isinstance(expected, (tuple, list)):
|
|
@@ -71,7 +85,7 @@ def nested_approx(expected, rel: float = None, abs: float = None, nan_ok: bool =
|
|
|
71
85
|
if isinstance(expected, Decimal):
|
|
72
86
|
return ApproxDecimal(expected, to_decimal(rel), to_decimal(abs), nan_ok)
|
|
73
87
|
if isinstance(expected, (datetime.datetime, datetime.date, datetime.time, datetime.timedelta)):
|
|
74
|
-
return
|
|
88
|
+
return ApproxDataTime(expected, rel, abs, nan_ok)
|
|
75
89
|
return pytest.approx(expected, rel=rel, abs=abs, nan_ok=nan_ok)
|
|
76
90
|
|
|
77
91
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: plexus-python-common
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.93
|
|
4
4
|
Classifier: Programming Language :: Python :: 3
|
|
5
5
|
Classifier: Programming Language :: Python :: 3.12
|
|
6
6
|
Classifier: Programming Language :: Python :: 3.13
|
|
@@ -20,4 +20,4 @@ Requires-Dist: pytest-cov>=5.0; extra == "test"
|
|
|
20
20
|
Requires-Dist: pytest-mysql>=3.0; extra == "test"
|
|
21
21
|
Requires-Dist: pytest-order>=1.3; extra == "test"
|
|
22
22
|
Requires-Dist: pytest-postgresql>=6.1; extra == "test"
|
|
23
|
-
Requires-Dist: pytest>=
|
|
23
|
+
Requires-Dist: pytest>=9.2; extra == "test"
|
|
@@ -15,9 +15,9 @@ plexus/common/utils/randutils.py,sha256=Mkba-g2ZnasuhdtBWoVDsP_VuwKMJ8p2UCf6-GF4
|
|
|
15
15
|
plexus/common/utils/retry.py,sha256=S_IfYrA30ci_sx6_ar0WUkNpKufoWi8xOSiWeYeAemA,11424
|
|
16
16
|
plexus/common/utils/span.py,sha256=RqgUuupN01xCjm4l5uxrr8BFFrUrytRVGihmENUawpk,6839
|
|
17
17
|
plexus/common/utils/strutils.py,sha256=uB46pPgaO_UMulwfW-hO7QOpCyhB9AdupeWSsJR3wGA,5098
|
|
18
|
-
plexus/common/utils/testutils.py,sha256=
|
|
18
|
+
plexus/common/utils/testutils.py,sha256=VuxLicsfHoGe9ESYX__BTU6Etsj4VKmhyreGFZ9h4Gs,6000
|
|
19
19
|
plexus/common/utils/typeutils.py,sha256=RVkYkFRgDrx77OHFH7PavMV0AIB0S8ly40rs4g7JWE4,8220
|
|
20
|
-
plexus_python_common-1.1.
|
|
21
|
-
plexus_python_common-1.1.
|
|
22
|
-
plexus_python_common-1.1.
|
|
23
|
-
plexus_python_common-1.1.
|
|
20
|
+
plexus_python_common-1.1.93.dist-info/METADATA,sha256=WiU-fMroTL3_Eer_cLZuRXNp0DSr0oBsJw7ib9KOYmA,880
|
|
21
|
+
plexus_python_common-1.1.93.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
22
|
+
plexus_python_common-1.1.93.dist-info/top_level.txt,sha256=ug_g7CVwaMQuas5UzAXbHUrQvKGCn8ezc6ZNvvRlJOE,7
|
|
23
|
+
plexus_python_common-1.1.93.dist-info/RECORD,,
|
|
File without changes
|
{plexus_python_common-1.1.91.dist-info → plexus_python_common-1.1.93.dist-info}/top_level.txt
RENAMED
|
File without changes
|