assertpy2 2.0.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.
Files changed (58) hide show
  1. assertpy2-2.0.0/.github/workflows/ci.yml +60 -0
  2. assertpy2-2.0.0/.github/workflows/publish.yml +29 -0
  3. assertpy2-2.0.0/.gitignore +32 -0
  4. assertpy2-2.0.0/CONTRIBUTING.md +22 -0
  5. assertpy2-2.0.0/LICENSE +28 -0
  6. assertpy2-2.0.0/PKG-INFO +227 -0
  7. assertpy2-2.0.0/README.md +196 -0
  8. assertpy2-2.0.0/assertpy2/__init__.py +25 -0
  9. assertpy2-2.0.0/assertpy2/assertpy.py +468 -0
  10. assertpy2-2.0.0/assertpy2/base.py +435 -0
  11. assertpy2-2.0.0/assertpy2/collection.py +217 -0
  12. assertpy2-2.0.0/assertpy2/contains.py +386 -0
  13. assertpy2-2.0.0/assertpy2/date.py +219 -0
  14. assertpy2-2.0.0/assertpy2/dict.py +255 -0
  15. assertpy2-2.0.0/assertpy2/dynamic.py +113 -0
  16. assertpy2-2.0.0/assertpy2/exception.py +128 -0
  17. assertpy2-2.0.0/assertpy2/extracting.py +233 -0
  18. assertpy2-2.0.0/assertpy2/file.py +276 -0
  19. assertpy2-2.0.0/assertpy2/helpers.py +273 -0
  20. assertpy2-2.0.0/assertpy2/numeric.py +555 -0
  21. assertpy2-2.0.0/assertpy2/py.typed +0 -0
  22. assertpy2-2.0.0/assertpy2/snapshot.py +217 -0
  23. assertpy2-2.0.0/assertpy2/string.py +413 -0
  24. assertpy2-2.0.0/docs/api.md +1045 -0
  25. assertpy2-2.0.0/docs/logo.svg +5 -0
  26. assertpy2-2.0.0/pyproject.toml +72 -0
  27. assertpy2-2.0.0/tests/test_bool.py +63 -0
  28. assertpy2-2.0.0/tests/test_class.py +144 -0
  29. assertpy2-2.0.0/tests/test_collection.py +230 -0
  30. assertpy2-2.0.0/tests/test_core.py +110 -0
  31. assertpy2-2.0.0/tests/test_custom_dict.py +237 -0
  32. assertpy2-2.0.0/tests/test_custom_list.py +80 -0
  33. assertpy2-2.0.0/tests/test_datetime.py +554 -0
  34. assertpy2-2.0.0/tests/test_description.py +63 -0
  35. assertpy2-2.0.0/tests/test_dict.py +483 -0
  36. assertpy2-2.0.0/tests/test_dict_compare.py +459 -0
  37. assertpy2-2.0.0/tests/test_dyn.py +124 -0
  38. assertpy2-2.0.0/tests/test_equals.py +104 -0
  39. assertpy2-2.0.0/tests/test_expected_exception.py +206 -0
  40. assertpy2-2.0.0/tests/test_extensions.py +233 -0
  41. assertpy2-2.0.0/tests/test_extracting.py +369 -0
  42. assertpy2-2.0.0/tests/test_fail.py +45 -0
  43. assertpy2-2.0.0/tests/test_file.py +329 -0
  44. assertpy2-2.0.0/tests/test_in.py +75 -0
  45. assertpy2-2.0.0/tests/test_list.py +497 -0
  46. assertpy2-2.0.0/tests/test_namedtuple.py +91 -0
  47. assertpy2-2.0.0/tests/test_none.py +57 -0
  48. assertpy2-2.0.0/tests/test_numbers.py +681 -0
  49. assertpy2-2.0.0/tests/test_readme.py +511 -0
  50. assertpy2-2.0.0/tests/test_same_as.py +72 -0
  51. assertpy2-2.0.0/tests/test_snapshots.py +254 -0
  52. assertpy2-2.0.0/tests/test_soft.py +247 -0
  53. assertpy2-2.0.0/tests/test_soft_fail.py +103 -0
  54. assertpy2-2.0.0/tests/test_string.py +625 -0
  55. assertpy2-2.0.0/tests/test_traceback.py +63 -0
  56. assertpy2-2.0.0/tests/test_type.py +105 -0
  57. assertpy2-2.0.0/tests/test_warn.py +136 -0
  58. assertpy2-2.0.0/uv.lock +323 -0
@@ -0,0 +1,60 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15"]
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+
18
+ - name: Install uv
19
+ uses: astral-sh/setup-uv@v6
20
+
21
+ - name: Set up Python ${{ matrix.python-version }}
22
+ uses: actions/setup-python@v5
23
+ with:
24
+ python-version: ${{ matrix.python-version }}
25
+ allow-prereleases: true
26
+
27
+ - name: Install dependencies
28
+ run: uv sync
29
+
30
+ - name: Lint
31
+ run: uv run ruff check .
32
+
33
+ - name: Test with coverage
34
+ run: uv run pytest -v --cov=assertpy2 --cov-report=term-missing tests
35
+
36
+ - name: Upload coverage to Codecov
37
+ if: matrix.python-version == '3.14'
38
+ uses: codecov/codecov-action@v5
39
+
40
+ lint:
41
+ runs-on: ubuntu-latest
42
+ steps:
43
+ - uses: actions/checkout@v4
44
+
45
+ - name: Install uv
46
+ uses: astral-sh/setup-uv@v6
47
+
48
+ - name: Set up Python
49
+ uses: actions/setup-python@v5
50
+ with:
51
+ python-version: "3.14"
52
+
53
+ - name: Install dependencies
54
+ run: uv sync
55
+
56
+ - name: Ruff check
57
+ run: uv run ruff check .
58
+
59
+ - name: Ruff format check
60
+ run: uv run ruff format --check .
@@ -0,0 +1,29 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ publish:
9
+ runs-on: ubuntu-latest
10
+ environment: pypi
11
+ permissions:
12
+ id-token: write
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - name: Install uv
17
+ uses: astral-sh/setup-uv@v6
18
+
19
+ - name: Set up Python
20
+ uses: actions/setup-python@v5
21
+ with:
22
+ python-version: "3.15"
23
+ allow-prereleases: true
24
+
25
+ - name: Build
26
+ run: uv build
27
+
28
+ - name: Publish to PyPI
29
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,32 @@
1
+ # .gitignore
2
+ *.py[cod]
3
+ .cache
4
+ .pytest_cache
5
+ __pycache__
6
+
7
+ # testing output
8
+ *.xml
9
+ *.log
10
+ cover
11
+ .coverage
12
+ htmlcov
13
+ __snapshots
14
+ mycustompath
15
+
16
+ # packaging
17
+ MANIFEST
18
+ dist
19
+
20
+ # mac
21
+ .DS_Store
22
+
23
+ # venv
24
+ .venv
25
+
26
+ # IDE
27
+ /.idea
28
+ .vscode
29
+
30
+ # docs output
31
+ docs/build
32
+ docs/out
@@ -0,0 +1,22 @@
1
+ # Contributing
2
+
3
+ Contributions of docs, tests, or code are welcome.
4
+
5
+ 1. Fork it
6
+ 1. Clone your fork (`git clone https://my_fork`)
7
+ 1. Create a branch (`git checkout -b my_branch`)
8
+ 1. Commit your changes (`git commit -am "added some cool feature"`)
9
+ 1. Push your branch to your fork (`git push origin my_branch`)
10
+ 1. Open a [Pull Request](http://github.com/Solganis/assertpy2/pulls)
11
+ 1. Respond to any questions during our review process
12
+
13
+ Read more about how pulls work on GitHub's [About pull requests](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests) page.
14
+
15
+ ## Running the Tests
16
+
17
+ Before sending a pull request, write tests (and use `assertpy2` assertions in them).
18
+
19
+ ```
20
+ uv sync
21
+ uv run pytest -v
22
+ ```
@@ -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.
@@ -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,196 @@
1
+ <p align="center">
2
+ <img src="docs/logo.svg" alt="assertpy2" width="280">
3
+ </p>
4
+
5
+ <p align="center">
6
+ <b>Fluent assertion library for Python with full type safety and soft assertions.</b><br>
7
+ Maintained fork of <a href="https://github.com/assertpy/assertpy">assertpy</a>.
8
+ </p>
9
+
10
+ <p align="center">
11
+ <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>
12
+ <a href="https://pypi.org/project/assertpy2/"><img src="https://img.shields.io/pypi/v/assertpy2" alt="PyPI version"></a>
13
+ <a href="https://pepy.tech/projects/assertpy2"><img src="https://static.pepy.tech/badge/assertpy2/month" alt="Downloads"></a>
14
+ <a href="https://pypi.org/project/assertpy2/"><img src="https://img.shields.io/pypi/pyversions/assertpy2" alt="Python"></a>
15
+ <a href="https://codecov.io/gh/Solganis/assertpy2"><img src="https://codecov.io/gh/Solganis/assertpy2/graph/badge.svg" alt="Coverage"></a>
16
+ <a href="https://github.com/Solganis/assertpy2/blob/main/LICENSE"><img src="https://img.shields.io/github/license/Solganis/assertpy2" alt="License"></a>
17
+ </p>
18
+
19
+
20
+ ## Quick start
21
+
22
+ ```bash
23
+ pip install assertpy2
24
+ ```
25
+
26
+ ```py
27
+ from assertpy2 import assert_that
28
+
29
+ def test_user():
30
+ user = {"name": "Alice", "age": 30, "roles": ["viewer", "editor"]}
31
+
32
+ assert_that(user).contains_key("name", "age")
33
+ assert_that(user["age"]).is_between(18, 120)
34
+ assert_that(user["roles"]).contains("viewer").does_not_contain("admin")
35
+ assert_that(user).has_name("Alice")
36
+ ```
37
+
38
+ When an assertion fails, the error message tells you exactly what went wrong:
39
+
40
+ ```py
41
+ assert_that(user["age"]).is_between(50, 120)
42
+ # AssertionError: Expected <30> to be between <50> and <120>, but was not.
43
+
44
+ assert_that(user["roles"]).contains("admin")
45
+ # AssertionError: Expected <['viewer', 'editor']> to contain <admin>, but did not.
46
+ ```
47
+
48
+
49
+ ## Why fluent assertions?
50
+
51
+ ```py
52
+ # bare assert - passes, but failure message is useless
53
+ assert user["age"] >= 18
54
+ # AssertionError
55
+
56
+ # assertpy2 - same check, clear failure message
57
+ assert_that(user["age"]).is_greater_than_or_equal_to(18)
58
+ # AssertionError: Expected <16> to be greater than or equal to <18>, but was not.
59
+
60
+ # bare assert - three separate statements
61
+ assert isinstance(items, list)
62
+ assert len(items) == 3
63
+ assert "admin" in items
64
+
65
+ # assertpy2 - one fluent chain
66
+ assert_that(items).is_type_of(list).is_length(3).contains("admin")
67
+ ```
68
+
69
+
70
+ ## Features
71
+
72
+ - **Type safety**: `Self` return types, `py.typed` ([PEP 561](https://peps.python.org/pep-0561/)).
73
+ - **IDE support**: full autocomplete and chaining inference out of the box.
74
+ - **Soft assertions**: collect all failures with `soft_assertions()`, plus `soft_fail()` for non-halting explicit failures.
75
+ - **Fluent chaining**: write assertions as readable one-liners that chain naturally.
76
+ - **Dynamic assertions**: `has_<name>()` for any attribute, property, or zero-argument method on objects and dicts.
77
+ - **Dict comparison**: `is_equal_to()` with `ignore` and `include` for selective key matching.
78
+ - **Extracting**: flatten collections on attributes with `filter` and `sort` support.
79
+ - **File assertions**: `exists()`, `is_file()`, `is_readable()`, `is_writable()`, `is_executable()` with `pathlib.Path` support.
80
+ - **Snapshot testing**: store and compare data structures in JSON format, inspired by Jest.
81
+ - **Extensions**: add custom assertions via `add_extension()`.
82
+ - Strings, numbers, lists, tuples, sets, dicts, dates, booleans, objects, exceptions.
83
+
84
+
85
+ ## Soft assertions
86
+
87
+ Collect all failures instead of stopping at the first one:
88
+
89
+ ```py
90
+ from assertpy2 import assert_that, soft_assertions
91
+
92
+ def test_user_profile():
93
+ with soft_assertions():
94
+ assert_that(user.name).is_equal_to("Alice")
95
+ assert_that(user.age).is_greater_than(0)
96
+ assert_that(user.email).contains("@")
97
+ ```
98
+
99
+ All failures are reported at the end of the block:
100
+
101
+ ```
102
+ AssertionError: soft assertion failures:
103
+ 1. Expected <Bob> to be equal to <Alice>, but was not.
104
+ 2. Expected <-1> to be greater than <0>, but was not.
105
+ 3. Expected <invalid> to contain <@>, but did not.
106
+ ```
107
+
108
+ Use `soft_fail("message")` inside the block for non-halting explicit failures (unlike `fail()`, which stops immediately).
109
+
110
+
111
+ ## API highlights
112
+
113
+ ### Dict comparison with ignore/include
114
+
115
+ ```py
116
+ assert_that({"a": 1, "b": 2, "c": 3}).is_equal_to({"a": 1}, ignore=["b", "c"])
117
+ assert_that({"a": 1, "b": {"c": 2, "d": 3}}).is_equal_to({"b": {"d": 3}}, include=("b", "d"))
118
+ ```
119
+
120
+ ### Extracting with filter and sort
121
+
122
+ ```py
123
+ users = [
124
+ {"user": "Fred", "age": 36, "active": True},
125
+ {"user": "Bob", "age": 40, "active": False},
126
+ {"user": "Johnny", "age": 13, "active": True},
127
+ ]
128
+
129
+ assert_that(users).extracting("user", filter="active").is_equal_to(["Fred", "Johnny"])
130
+ assert_that(users).extracting("user", sort="age").is_equal_to(["Johnny", "Fred", "Bob"])
131
+ ```
132
+
133
+ ### Expected exceptions
134
+
135
+ ```py
136
+ assert_that(some_func).raises(RuntimeError).when_called_with("bad_arg")\
137
+ .is_length(8).starts_with("some").is_equal_to("some err")
138
+ ```
139
+
140
+ ### Snapshot testing
141
+
142
+ ```py
143
+ assert_that({"a": 1, "b": 2, "c": 3}).snapshot()
144
+ ```
145
+
146
+ See the [full API reference](docs/api.md) for all assertion methods, examples, and advanced features.
147
+
148
+
149
+ ## Migration from assertpy
150
+
151
+ assertpy2 is a drop-in replacement for Python 3.10+. Change the import, everything else works:
152
+
153
+ ```py
154
+ # before
155
+ from assertpy import assert_that, soft_assertions
156
+
157
+ # after
158
+ from assertpy2 import assert_that, soft_assertions
159
+ ```
160
+
161
+ <div align="center">
162
+
163
+ | | assertpy | assertpy2 |
164
+ |---|---|---|
165
+ | Maintained | Last release 2020 | Active |
166
+ | Python | 2.7+ | 3.10-3.15 |
167
+ | Type safety | No annotations | `Self` return types, `py.typed` (PEP 561) |
168
+ | IDE support | No type info | Full autocomplete and chaining inference |
169
+ | Soft assertions | Basic | Stable, with `soft_fail()` support |
170
+ | Security | [CVE in snapshots](https://github.com/assertpy/assertpy/issues/156) | Fixed |
171
+ | Open bugs | 15+ unresolved | All resolved |
172
+
173
+ </div>
174
+
175
+
176
+ ## Contributing
177
+
178
+ Contributions are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
179
+
180
+
181
+ ## License
182
+
183
+ All files are licensed under the BSD 3-Clause License as follows:
184
+
185
+ > Copyright (c) 2015-2019, Activision Publishing, Inc.
186
+ > All rights reserved.
187
+ >
188
+ > Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
189
+ >
190
+ > 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
191
+ >
192
+ > 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.
193
+ >
194
+ > 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.
195
+ >
196
+ > 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,25 @@
1
+ from .assertpy import (
2
+ WarningLoggingAdapter,
3
+ __version__,
4
+ add_extension,
5
+ assert_that,
6
+ assert_warn,
7
+ fail,
8
+ remove_extension,
9
+ soft_assertions,
10
+ soft_fail,
11
+ )
12
+ from .file import contents_of
13
+
14
+ __all__ = [
15
+ "WarningLoggingAdapter",
16
+ "__version__",
17
+ "add_extension",
18
+ "assert_that",
19
+ "assert_warn",
20
+ "contents_of",
21
+ "fail",
22
+ "remove_extension",
23
+ "soft_assertions",
24
+ "soft_fail",
25
+ ]