plexus-python-common 1.1.90__py3-none-any.whl → 1.1.92__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.
@@ -4,7 +4,7 @@ from decimal import Decimal
4
4
  from typing import Any, Protocol
5
5
 
6
6
  import pytest
7
- from _pytest.python_api import ApproxBase, ApproxDecimal, ApproxMapping, ApproxScalar, ApproxSequenceLike
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._approx_scalar(obj)
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 _yield_comparisons(self, actual):
47
- for k in range(len(self.expected)):
48
- mapping = nested_approx(self.expected[k], self.rel, self.abs, self.nan_ok)
49
- if isinstance(mapping, ApproxScalar):
50
- yield actual[k], self.expected[k]
51
- else:
52
- yield from mapping._yield_comparisons(actual[k])
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 _yield_comparisons(self, actual):
58
- for k in self.expected.keys():
59
- mapping = nested_approx(self.expected[k], self.rel, self.abs, self.nan_ok)
60
- if isinstance(mapping, ApproxScalar):
61
- yield actual[k], self.expected[k]
62
- else:
63
- yield from mapping._yield_comparisons(actual[k])
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(expected, rel: float = None, abs: float = None, nan_ok: bool = False) -> ApproxBase:
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 pytest.approx(expected, abs=datetime.timedelta(0))
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.90
3
+ Version: 1.1.92
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>=8.3; extra == "test"
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=AIuGok17mRackiSXO0ZiWXEwlna6Bv2J8ZFN48nypDY,5638
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.90.dist-info/METADATA,sha256=MvyUvvRwM_Z2a8E6xIuWNadmzhtEQx1zNmLL64nPT7k,880
21
- plexus_python_common-1.1.90.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
22
- plexus_python_common-1.1.90.dist-info/top_level.txt,sha256=ug_g7CVwaMQuas5UzAXbHUrQvKGCn8ezc6ZNvvRlJOE,7
23
- plexus_python_common-1.1.90.dist-info/RECORD,,
20
+ plexus_python_common-1.1.92.dist-info/METADATA,sha256=aZs0mnguJLL_FZCEyDKdKeiCwqk5g-bTZ2o38N5y7FU,880
21
+ plexus_python_common-1.1.92.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
22
+ plexus_python_common-1.1.92.dist-info/top_level.txt,sha256=ug_g7CVwaMQuas5UzAXbHUrQvKGCn8ezc6ZNvvRlJOE,7
23
+ plexus_python_common-1.1.92.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (84.0.0)
2
+ Generator: setuptools (84.2.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5