assertpy2 2.0.0__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.
- assertpy2/__init__.py +25 -0
- assertpy2/assertpy.py +468 -0
- assertpy2/base.py +435 -0
- assertpy2/collection.py +217 -0
- assertpy2/contains.py +386 -0
- assertpy2/date.py +219 -0
- assertpy2/dict.py +255 -0
- assertpy2/dynamic.py +113 -0
- assertpy2/exception.py +128 -0
- assertpy2/extracting.py +233 -0
- assertpy2/file.py +276 -0
- assertpy2/helpers.py +273 -0
- assertpy2/numeric.py +555 -0
- assertpy2/py.typed +0 -0
- assertpy2/snapshot.py +217 -0
- assertpy2/string.py +413 -0
- assertpy2-2.0.0.dist-info/METADATA +227 -0
- assertpy2-2.0.0.dist-info/RECORD +20 -0
- assertpy2-2.0.0.dist-info/WHEEL +4 -0
- assertpy2-2.0.0.dist-info/licenses/LICENSE +28 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: assertpy2
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Fluent assertion library for Python with full type safety and soft assertions
|
|
5
|
+
Project-URL: Homepage, https://github.com/Solganis/assertpy2
|
|
6
|
+
Project-URL: Repository, https://github.com/Solganis/assertpy2
|
|
7
|
+
Project-URL: Issues, https://github.com/Solganis/assertpy2/issues
|
|
8
|
+
Author-email: Justin Shacklette <justin@saturnboy.com>
|
|
9
|
+
Maintainer: Solganis
|
|
10
|
+
License-Expression: BSD-3-Clause
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: assert,assert_that,assertion,assertthat,pytest,test,testing,unittest
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
16
|
+
Classifier: Natural Language :: English
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
26
|
+
Classifier: Topic :: Software Development
|
|
27
|
+
Classifier: Topic :: Software Development :: Testing
|
|
28
|
+
Requires-Python: >=3.10
|
|
29
|
+
Requires-Dist: typing-extensions>=4.0
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
<p align="center">
|
|
33
|
+
<img src="docs/logo.svg" alt="assertpy2" width="280">
|
|
34
|
+
</p>
|
|
35
|
+
|
|
36
|
+
<p align="center">
|
|
37
|
+
<b>Fluent assertion library for Python with full type safety and soft assertions.</b><br>
|
|
38
|
+
Maintained fork of <a href="https://github.com/assertpy/assertpy">assertpy</a>.
|
|
39
|
+
</p>
|
|
40
|
+
|
|
41
|
+
<p align="center">
|
|
42
|
+
<a href="https://github.com/Solganis/assertpy2/actions/workflows/ci.yml"><img src="https://github.com/Solganis/assertpy2/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
43
|
+
<a href="https://pypi.org/project/assertpy2/"><img src="https://img.shields.io/pypi/v/assertpy2" alt="PyPI version"></a>
|
|
44
|
+
<a href="https://pepy.tech/projects/assertpy2"><img src="https://static.pepy.tech/badge/assertpy2/month" alt="Downloads"></a>
|
|
45
|
+
<a href="https://pypi.org/project/assertpy2/"><img src="https://img.shields.io/pypi/pyversions/assertpy2" alt="Python"></a>
|
|
46
|
+
<a href="https://codecov.io/gh/Solganis/assertpy2"><img src="https://codecov.io/gh/Solganis/assertpy2/graph/badge.svg" alt="Coverage"></a>
|
|
47
|
+
<a href="https://github.com/Solganis/assertpy2/blob/main/LICENSE"><img src="https://img.shields.io/github/license/Solganis/assertpy2" alt="License"></a>
|
|
48
|
+
</p>
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
## Quick start
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install assertpy2
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```py
|
|
58
|
+
from assertpy2 import assert_that
|
|
59
|
+
|
|
60
|
+
def test_user():
|
|
61
|
+
user = {"name": "Alice", "age": 30, "roles": ["viewer", "editor"]}
|
|
62
|
+
|
|
63
|
+
assert_that(user).contains_key("name", "age")
|
|
64
|
+
assert_that(user["age"]).is_between(18, 120)
|
|
65
|
+
assert_that(user["roles"]).contains("viewer").does_not_contain("admin")
|
|
66
|
+
assert_that(user).has_name("Alice")
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
When an assertion fails, the error message tells you exactly what went wrong:
|
|
70
|
+
|
|
71
|
+
```py
|
|
72
|
+
assert_that(user["age"]).is_between(50, 120)
|
|
73
|
+
# AssertionError: Expected <30> to be between <50> and <120>, but was not.
|
|
74
|
+
|
|
75
|
+
assert_that(user["roles"]).contains("admin")
|
|
76
|
+
# AssertionError: Expected <['viewer', 'editor']> to contain <admin>, but did not.
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
## Why fluent assertions?
|
|
81
|
+
|
|
82
|
+
```py
|
|
83
|
+
# bare assert - passes, but failure message is useless
|
|
84
|
+
assert user["age"] >= 18
|
|
85
|
+
# AssertionError
|
|
86
|
+
|
|
87
|
+
# assertpy2 - same check, clear failure message
|
|
88
|
+
assert_that(user["age"]).is_greater_than_or_equal_to(18)
|
|
89
|
+
# AssertionError: Expected <16> to be greater than or equal to <18>, but was not.
|
|
90
|
+
|
|
91
|
+
# bare assert - three separate statements
|
|
92
|
+
assert isinstance(items, list)
|
|
93
|
+
assert len(items) == 3
|
|
94
|
+
assert "admin" in items
|
|
95
|
+
|
|
96
|
+
# assertpy2 - one fluent chain
|
|
97
|
+
assert_that(items).is_type_of(list).is_length(3).contains("admin")
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
## Features
|
|
102
|
+
|
|
103
|
+
- **Type safety**: `Self` return types, `py.typed` ([PEP 561](https://peps.python.org/pep-0561/)).
|
|
104
|
+
- **IDE support**: full autocomplete and chaining inference out of the box.
|
|
105
|
+
- **Soft assertions**: collect all failures with `soft_assertions()`, plus `soft_fail()` for non-halting explicit failures.
|
|
106
|
+
- **Fluent chaining**: write assertions as readable one-liners that chain naturally.
|
|
107
|
+
- **Dynamic assertions**: `has_<name>()` for any attribute, property, or zero-argument method on objects and dicts.
|
|
108
|
+
- **Dict comparison**: `is_equal_to()` with `ignore` and `include` for selective key matching.
|
|
109
|
+
- **Extracting**: flatten collections on attributes with `filter` and `sort` support.
|
|
110
|
+
- **File assertions**: `exists()`, `is_file()`, `is_readable()`, `is_writable()`, `is_executable()` with `pathlib.Path` support.
|
|
111
|
+
- **Snapshot testing**: store and compare data structures in JSON format, inspired by Jest.
|
|
112
|
+
- **Extensions**: add custom assertions via `add_extension()`.
|
|
113
|
+
- Strings, numbers, lists, tuples, sets, dicts, dates, booleans, objects, exceptions.
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
## Soft assertions
|
|
117
|
+
|
|
118
|
+
Collect all failures instead of stopping at the first one:
|
|
119
|
+
|
|
120
|
+
```py
|
|
121
|
+
from assertpy2 import assert_that, soft_assertions
|
|
122
|
+
|
|
123
|
+
def test_user_profile():
|
|
124
|
+
with soft_assertions():
|
|
125
|
+
assert_that(user.name).is_equal_to("Alice")
|
|
126
|
+
assert_that(user.age).is_greater_than(0)
|
|
127
|
+
assert_that(user.email).contains("@")
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
All failures are reported at the end of the block:
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
AssertionError: soft assertion failures:
|
|
134
|
+
1. Expected <Bob> to be equal to <Alice>, but was not.
|
|
135
|
+
2. Expected <-1> to be greater than <0>, but was not.
|
|
136
|
+
3. Expected <invalid> to contain <@>, but did not.
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Use `soft_fail("message")` inside the block for non-halting explicit failures (unlike `fail()`, which stops immediately).
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
## API highlights
|
|
143
|
+
|
|
144
|
+
### Dict comparison with ignore/include
|
|
145
|
+
|
|
146
|
+
```py
|
|
147
|
+
assert_that({"a": 1, "b": 2, "c": 3}).is_equal_to({"a": 1}, ignore=["b", "c"])
|
|
148
|
+
assert_that({"a": 1, "b": {"c": 2, "d": 3}}).is_equal_to({"b": {"d": 3}}, include=("b", "d"))
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Extracting with filter and sort
|
|
152
|
+
|
|
153
|
+
```py
|
|
154
|
+
users = [
|
|
155
|
+
{"user": "Fred", "age": 36, "active": True},
|
|
156
|
+
{"user": "Bob", "age": 40, "active": False},
|
|
157
|
+
{"user": "Johnny", "age": 13, "active": True},
|
|
158
|
+
]
|
|
159
|
+
|
|
160
|
+
assert_that(users).extracting("user", filter="active").is_equal_to(["Fred", "Johnny"])
|
|
161
|
+
assert_that(users).extracting("user", sort="age").is_equal_to(["Johnny", "Fred", "Bob"])
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Expected exceptions
|
|
165
|
+
|
|
166
|
+
```py
|
|
167
|
+
assert_that(some_func).raises(RuntimeError).when_called_with("bad_arg")\
|
|
168
|
+
.is_length(8).starts_with("some").is_equal_to("some err")
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Snapshot testing
|
|
172
|
+
|
|
173
|
+
```py
|
|
174
|
+
assert_that({"a": 1, "b": 2, "c": 3}).snapshot()
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
See the [full API reference](docs/api.md) for all assertion methods, examples, and advanced features.
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
## Migration from assertpy
|
|
181
|
+
|
|
182
|
+
assertpy2 is a drop-in replacement for Python 3.10+. Change the import, everything else works:
|
|
183
|
+
|
|
184
|
+
```py
|
|
185
|
+
# before
|
|
186
|
+
from assertpy import assert_that, soft_assertions
|
|
187
|
+
|
|
188
|
+
# after
|
|
189
|
+
from assertpy2 import assert_that, soft_assertions
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
<div align="center">
|
|
193
|
+
|
|
194
|
+
| | assertpy | assertpy2 |
|
|
195
|
+
|---|---|---|
|
|
196
|
+
| Maintained | Last release 2020 | Active |
|
|
197
|
+
| Python | 2.7+ | 3.10-3.15 |
|
|
198
|
+
| Type safety | No annotations | `Self` return types, `py.typed` (PEP 561) |
|
|
199
|
+
| IDE support | No type info | Full autocomplete and chaining inference |
|
|
200
|
+
| Soft assertions | Basic | Stable, with `soft_fail()` support |
|
|
201
|
+
| Security | [CVE in snapshots](https://github.com/assertpy/assertpy/issues/156) | Fixed |
|
|
202
|
+
| Open bugs | 15+ unresolved | All resolved |
|
|
203
|
+
|
|
204
|
+
</div>
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
## Contributing
|
|
208
|
+
|
|
209
|
+
Contributions are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
All files are licensed under the BSD 3-Clause License as follows:
|
|
215
|
+
|
|
216
|
+
> Copyright (c) 2015-2019, Activision Publishing, Inc.
|
|
217
|
+
> All rights reserved.
|
|
218
|
+
>
|
|
219
|
+
> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
220
|
+
>
|
|
221
|
+
> 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
222
|
+
>
|
|
223
|
+
> 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
224
|
+
>
|
|
225
|
+
> 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
226
|
+
>
|
|
227
|
+
> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
assertpy2/__init__.py,sha256=v6D0blfs8OmzQ4o1cQ6UPTBPW-fE0OmDmqi8ShWsyZw,438
|
|
2
|
+
assertpy2/assertpy.py,sha256=qG2onOQgolv0RN2CA9Wt0uzMsrZZrr4qglh5ndiVk-g,16578
|
|
3
|
+
assertpy2/base.py,sha256=6v2yLWvVCFiihPv3jvjgb3HcXYy-hus_Mh0B2MRzZ54,15981
|
|
4
|
+
assertpy2/collection.py,sha256=XQpC9DnJh7HGRO99336Xa8NERGN90EupdxecsGrt8U0,8376
|
|
5
|
+
assertpy2/contains.py,sha256=0KSe8Jr2qSU76ISkjdsGujCwk9vgiYE9_IWam5vEX0I,14663
|
|
6
|
+
assertpy2/date.py,sha256=Si-N0LHdYSfNUfB7ENLCM7sXs9fDJVUYMsfQ52jaJKM,8833
|
|
7
|
+
assertpy2/dict.py,sha256=YSY9eEPU4IyzgITwADcUAjBZgWSe8Zokm4Pi0248LeY,10086
|
|
8
|
+
assertpy2/dynamic.py,sha256=5OaaNK9iledjfT25yKqXw44Da6VB4GULbOn3isphOOw,4936
|
|
9
|
+
assertpy2/exception.py,sha256=tew9yCNXL4w4Gjh0arEfi-nbIDc_HPZLgSljVZ8jmKY,5143
|
|
10
|
+
assertpy2/extracting.py,sha256=3X6_n6E_fKTtwEEbxlO8gTgshvOCLTb8HbfHVnuG8FM,10395
|
|
11
|
+
assertpy2/file.py,sha256=qzYm4pVmjDMwTINU96QqMJf1rZTC3SMZFVA2EGP5c2c,9698
|
|
12
|
+
assertpy2/helpers.py,sha256=1RgEDuLGOMkbaFn7Dpr24bK7h9hh3K1kK-dd9A4jVFk,12308
|
|
13
|
+
assertpy2/numeric.py,sha256=KJP8aEb3fDIektlh1VGM1oEsOx9JSQ6C3DEKZz58mkw,19793
|
|
14
|
+
assertpy2/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
+
assertpy2/snapshot.py,sha256=aoNCskZDI3T2lerhZS1RhXa4BBJX149afDKhPBLBIf8,8823
|
|
16
|
+
assertpy2/string.py,sha256=MwmEVjvEbmPXo3ktgaBfWSbWAXc0t1wClSUQRGBPwqY,16040
|
|
17
|
+
assertpy2-2.0.0.dist-info/METADATA,sha256=GMFcEtgBOs6zTT06ZTk81mCZPHZGfEn289JtcgI04_0,9046
|
|
18
|
+
assertpy2-2.0.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
19
|
+
assertpy2-2.0.0.dist-info/licenses/LICENSE,sha256=tugsGV7w81349vK3IDCgB1FqfiqRZMcJiyWY5N55t4A,1564
|
|
20
|
+
assertpy2-2.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Copyright (c) 2015-2019, Activision Publishing, Inc.
|
|
2
|
+
Copyright (c) 2026, Solganis (assertpy2 fork)
|
|
3
|
+
All rights reserved.
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
6
|
+
are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
16
|
+
may be used to endorse or promote products derived from this software without
|
|
17
|
+
specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
20
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
21
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
23
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
24
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
25
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
26
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
27
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
28
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|