requiresthat 2025.6.20.0__tar.gz → 2025.6.22.0__tar.gz
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-2025.6.20.0 → requiresthat-2025.6.22.0}/PKG-INFO +1 -1
- {requiresthat-2025.6.20.0 → requiresthat-2025.6.22.0}/pyproject.toml +1 -1
- {requiresthat-2025.6.20.0 → requiresthat-2025.6.22.0}/src/requiresthat/_exceptions.py +6 -2
- {requiresthat-2025.6.20.0 → requiresthat-2025.6.22.0}/src/requiresthat/_requires.py +9 -3
- {requiresthat-2025.6.20.0 → requiresthat-2025.6.22.0}/src/requiresthat.egg-info/PKG-INFO +1 -1
- {requiresthat-2025.6.20.0 → requiresthat-2025.6.22.0}/tests/test_requiresthat.py +20 -0
- {requiresthat-2025.6.20.0 → requiresthat-2025.6.22.0}/README.rst +0 -0
- {requiresthat-2025.6.20.0 → requiresthat-2025.6.22.0}/setup.cfg +0 -0
- {requiresthat-2025.6.20.0 → requiresthat-2025.6.22.0}/src/requiresthat/__init__.py +0 -0
- {requiresthat-2025.6.20.0 → requiresthat-2025.6.22.0}/src/requiresthat/_when.py +0 -0
- {requiresthat-2025.6.20.0 → requiresthat-2025.6.22.0}/src/requiresthat.egg-info/SOURCES.txt +0 -0
- {requiresthat-2025.6.20.0 → requiresthat-2025.6.22.0}/src/requiresthat.egg-info/dependency_links.txt +0 -0
- {requiresthat-2025.6.20.0 → requiresthat-2025.6.22.0}/src/requiresthat.egg-info/top_level.txt +0 -0
@@ -1,6 +1,10 @@
|
|
1
1
|
import textwrap
|
2
2
|
|
3
|
-
class
|
3
|
+
class RequirementError(Exception):
|
4
|
+
"""Base class for all exceptions that follow here"""
|
5
|
+
pass
|
6
|
+
|
7
|
+
class RequirementNotFulfilledError(RequirementError):
|
4
8
|
"""Raise this when a requirement is found wanting"""
|
5
9
|
|
6
10
|
def __init__(self, that, when, subwhen: str = str(), msg=None):
|
@@ -15,7 +19,7 @@ class RequirementNotFulfilledError(Exception):
|
|
15
19
|
# Call the base class' constructor to init the exception class
|
16
20
|
super().__init__(msg or self.default_msg)
|
17
21
|
|
18
|
-
class NoCallableConstructError(
|
22
|
+
class NoCallableConstructError(RequirementError):
|
19
23
|
"""Raise this when a construct is not callable"""
|
20
24
|
|
21
25
|
def __init__(self, construct, msg=None):
|
@@ -80,8 +80,14 @@ def __assert(self, that, when: When, subwhen: str = str()):
|
|
80
80
|
The reason we don't use assert here is to avoid the Knuthian dilemma of premature optimisation;
|
81
81
|
namely, that it nukes this useful tool, :-[
|
82
82
|
"""
|
83
|
+
# We map everything that can go wrong to one exception; that way, the user has to deal with only
|
84
|
+
# one catagory of exceptions.
|
85
|
+
failure = RequirementNotFulfilledError(that, when, subwhen)
|
83
86
|
try:
|
84
87
|
if not eval(that):
|
85
|
-
raise
|
86
|
-
except:
|
87
|
-
raise
|
88
|
+
raise failure from None
|
89
|
+
except Exception:
|
90
|
+
raise failure from None
|
91
|
+
else:
|
92
|
+
# Success!
|
93
|
+
pass
|
@@ -106,3 +106,23 @@ class TestCase_requiresthat_01:
|
|
106
106
|
|
107
107
|
X = C(data='spam')
|
108
108
|
X.method()
|
109
|
+
|
110
|
+
@pytest.mark.filterwarnings("ignore::SyntaxWarning")
|
111
|
+
def test_the_impossible(self):
|
112
|
+
"""Make the evaluation itself a problem"""
|
113
|
+
|
114
|
+
# In algebraic wheels, div by zero is meaningful: https://en.wikipedia.org/wiki/Wheel_theory
|
115
|
+
# In Python wheels, it is not!
|
116
|
+
the_impossible = '1 / 0 is not None'
|
117
|
+
class C:
|
118
|
+
|
119
|
+
def __init__(self, data=None):
|
120
|
+
self.data = data
|
121
|
+
|
122
|
+
@requires(the_impossible)
|
123
|
+
def method(self):
|
124
|
+
self.data = 'ham'
|
125
|
+
|
126
|
+
X = C(data='spam')
|
127
|
+
with pytest.raises(RequirementNotFulfilledError):
|
128
|
+
X.method()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{requiresthat-2025.6.20.0 → requiresthat-2025.6.22.0}/src/requiresthat.egg-info/dependency_links.txt
RENAMED
File without changes
|
{requiresthat-2025.6.20.0 → requiresthat-2025.6.22.0}/src/requiresthat.egg-info/top_level.txt
RENAMED
File without changes
|