requiresthat 2025.6.17.1__py3-none-any.whl → 2025.6.18.1__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.
- requiresthat/_exceptions.py +4 -2
- requiresthat/_requires.py +27 -11
- {requiresthat-2025.6.17.1.dist-info → requiresthat-2025.6.18.1.dist-info}/METADATA +1 -1
- requiresthat-2025.6.18.1.dist-info/RECORD +8 -0
- requiresthat-2025.6.17.1.dist-info/RECORD +0 -8
- {requiresthat-2025.6.17.1.dist-info → requiresthat-2025.6.18.1.dist-info}/WHEEL +0 -0
- {requiresthat-2025.6.17.1.dist-info → requiresthat-2025.6.18.1.dist-info}/top_level.txt +0 -0
requiresthat/_exceptions.py
CHANGED
@@ -3,11 +3,13 @@ import textwrap
|
|
3
3
|
class RequirementNotFulfilledError(Exception):
|
4
4
|
"""Raise this when a requirement is found wanting"""
|
5
5
|
|
6
|
-
def __init__(self, that, when, msg=None):
|
6
|
+
def __init__(self, that, when, subwhen=str(), msg=None):
|
7
7
|
"""Show a default or a user-provided message indicating that some condition is unmet"""
|
8
8
|
|
9
|
+
if subwhen:
|
10
|
+
subwhen = f' ({subwhen.name!r})'
|
9
11
|
self.default_msg = textwrap.dedent(f"""
|
10
|
-
{that!r} ({when.name!r}) does not hold
|
12
|
+
{that!r} ({when.name!r}{subwhen}) does not hold
|
11
13
|
""").strip()
|
12
14
|
|
13
15
|
# Call the base class' constructor to init the exception class
|
requiresthat/_requires.py
CHANGED
@@ -22,24 +22,40 @@ def requires(that, when: When = APRIORI) -> Optional[Callable]:
|
|
22
22
|
assert callable(func)
|
23
23
|
except AssertionError as exc:
|
24
24
|
raise NoCallableConstructError(func) from exc
|
25
|
-
|
26
|
-
|
25
|
+
else:
|
26
|
+
# Since we want to give detailed sub-failure diax in case of BEFOREANDAFTER,
|
27
|
+
# economisng on the ifs below is tricky.
|
27
28
|
if when == APRIORI:
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
try:
|
30
|
+
assert eval(that)
|
31
|
+
except AssertionError as exc:
|
32
|
+
raise RequirementNotFulfilledError(that, when) from exc
|
33
|
+
else:
|
34
|
+
func(self, *pargs, **kwargs)
|
35
|
+
|
31
36
|
elif when == POSTMORTEM:
|
32
37
|
func(self, *pargs, **kwargs)
|
33
|
-
|
38
|
+
try:
|
39
|
+
assert eval(that)
|
40
|
+
except AssertionError as exc:
|
41
|
+
raise RequirementNotFulfilledError(that, when) from exc
|
42
|
+
|
34
43
|
elif when == BEFOREANDAFTER:
|
35
|
-
|
36
|
-
|
37
|
-
|
44
|
+
try:
|
45
|
+
assert eval(that)
|
46
|
+
except AssertionError as exc:
|
47
|
+
raise RequirementNotFulfilledError(that, when, APRIORI) from exc
|
48
|
+
else:
|
49
|
+
func(self, *pargs, **kwargs)
|
50
|
+
try:
|
51
|
+
assert eval(that)
|
52
|
+
except AssertionError as exc:
|
53
|
+
raise RequirementNotFulfilledError(that, when, POSTMORTEM) from exc
|
54
|
+
|
38
55
|
# We don't need an else clause; trying to enlist something that's not in the enum
|
39
56
|
# will be penalised with an AttributeError, and small typos will be healed with a
|
40
57
|
# suggestion as to what you might have meant.
|
41
|
-
|
42
|
-
raise RequirementNotFulfilledError(that, when) from exc
|
58
|
+
|
43
59
|
return inner_wrapper
|
44
60
|
|
45
61
|
return func_wrapper
|
@@ -0,0 +1,8 @@
|
|
1
|
+
requiresthat/__init__.py,sha256=VTyJru4K2_e7UEa0od6kXU7M8ovfD176GXEXqtNf-nY,154
|
2
|
+
requiresthat/_exceptions.py,sha256=-Q9lhvHnSapP_UGMAnlXxwDaGcxagULIe5oP5h8a2IU,1275
|
3
|
+
requiresthat/_requires.py,sha256=5hQMT5T5VZuQj6W13108j_cedx4wKzJ7Kt4xseOR4cI,2447
|
4
|
+
requiresthat/_when.py,sha256=VoGuvoG9WDEMIPeKnxAsjMTaCMhgSszf4xxa1vLn5aU,299
|
5
|
+
requiresthat-2025.6.18.1.dist-info/METADATA,sha256=anVc8oEKzMwwStJ7PH7tCHDLFBaQ0qTNteQd3-ZbJ5s,1575
|
6
|
+
requiresthat-2025.6.18.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
7
|
+
requiresthat-2025.6.18.1.dist-info/top_level.txt,sha256=mUgMTpAG75GYtt5_rVajUyWp-O_1VrrkqRo_hY9L9So,13
|
8
|
+
requiresthat-2025.6.18.1.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
1
|
-
requiresthat/__init__.py,sha256=VTyJru4K2_e7UEa0od6kXU7M8ovfD176GXEXqtNf-nY,154
|
2
|
-
requiresthat/_exceptions.py,sha256=8675wEink7JD3mBsOYCWVL5KYpNQMZ5IQ0C7M2CJ1LU,1186
|
3
|
-
requiresthat/_requires.py,sha256=zp99m8m3kRTpS8XKHLBZ0r0eH3skDJEMeKTAZIh6PkU,1748
|
4
|
-
requiresthat/_when.py,sha256=VoGuvoG9WDEMIPeKnxAsjMTaCMhgSszf4xxa1vLn5aU,299
|
5
|
-
requiresthat-2025.6.17.1.dist-info/METADATA,sha256=HPpmJgWGi2gEtIUQEaCrOezW6MgFVPxrafOSo2Gk3PM,1575
|
6
|
-
requiresthat-2025.6.17.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
7
|
-
requiresthat-2025.6.17.1.dist-info/top_level.txt,sha256=mUgMTpAG75GYtt5_rVajUyWp-O_1VrrkqRo_hY9L9So,13
|
8
|
-
requiresthat-2025.6.17.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|