requiresthat 2025.6.17.1__py3-none-any.whl → 2025.6.18.2__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.2.dist-info}/METADATA +6 -4
- requiresthat-2025.6.18.2.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.2.dist-info}/WHEEL +0 -0
- {requiresthat-2025.6.17.1.dist-info → requiresthat-2025.6.18.2.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
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: requiresthat
|
3
|
-
Version: 2025.6.
|
3
|
+
Version: 2025.6.18.2
|
4
4
|
Summary: Support for requirements-assisted development
|
5
5
|
Author-email: Ann T Ropea <bedhanger@gmx.de>
|
6
6
|
License-Expression: MIT
|
@@ -35,12 +35,14 @@ Example usage
|
|
35
35
|
X = C(data='spam')
|
36
36
|
X.method()
|
37
37
|
|
38
|
-
The ``that`` can be almost any valid Python statement which can be evaluated
|
39
|
-
|
38
|
+
The ``that`` can be almost any valid Python statement which can be evaluated and whose veracity can
|
39
|
+
be asserted, and the result thereof will decide whether or not the method fires/will be considered a
|
40
|
+
success.
|
40
41
|
|
41
42
|
The parameter ``when`` decides if the condition is a-priori, post-mortem, or before-and-after.
|
42
43
|
The default is a-priori, meaning a precondition. Note that before-and-after does *not* mean during;
|
43
44
|
you cannot mandate an invariant this way!
|
44
45
|
|
45
46
|
``RequirementNotFulfilledError`` is the exception you have to deal with in case a condition is not
|
46
|
-
met.
|
47
|
+
met. ``NoCallableConstructError`` gets raised should you apply the decorator to a construct that is
|
48
|
+
not callable.
|
@@ -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.2.dist-info/METADATA,sha256=ap9RNE7_6pymDKgOAS9E-a8RbgvPFD5SQBMUC2c6gCk,1709
|
6
|
+
requiresthat-2025.6.18.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
7
|
+
requiresthat-2025.6.18.2.dist-info/top_level.txt,sha256=mUgMTpAG75GYtt5_rVajUyWp-O_1VrrkqRo_hY9L9So,13
|
8
|
+
requiresthat-2025.6.18.2.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
|