Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tybruno/unittest_assertions
Thin wrapper around the python builtin unittest library allowing developers to use builtin assertions for non-unittest use cases.
https://github.com/tybruno/unittest_assertions
assertify functional-testing python unittest verification verify wrapper
Last synced: 2 months ago
JSON representation
Thin wrapper around the python builtin unittest library allowing developers to use builtin assertions for non-unittest use cases.
- Host: GitHub
- URL: https://github.com/tybruno/unittest_assertions
- Owner: tybruno
- License: mit
- Created: 2021-08-03T16:12:45.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-16T14:57:39.000Z (about 3 years ago)
- Last Synced: 2024-03-15T10:50:01.064Z (9 months ago)
- Topics: assertify, functional-testing, python, unittest, verification, verify, wrapper
- Language: Python
- Homepage:
- Size: 236 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
[![License: MIT](https://img.shields.io/badge/License-MIT-blueviolet.svg)](https://opensource.org/licenses/MIT)
[![Linting and Testing](https://github.com/tybruno/unittest_assertions/actions/workflows/linting-and-testing.yml/badge.svg)](https://github.com/tybruno/unittest_assertions/actions/workflows/linting-and-testing.yml)
[![codecov](https://codecov.io/gh/tybruno/unittest_assertions/branch/main/graph/badge.svg?token=HPP1A6F39K)](https://codecov.io/gh/tybruno/unittest_assertions)# unittest_assertions
Thin wrapper around the python builtin `unittest` allowing developers to use the builtin assertions for non-unittest use cases.
#### Key Features:
* **Easy**: Designed to make it be simple allowing developers to use the builtin unittest assertions for their own use cases.
* **Great Developer Experience**: Being fully typed, documented, and tested makes it great for editor support and extension.
* **There is More!!!**:
* [assertify](https://github.com/tybruno/assertify): Simple, Flexible, and Extendable python3.6+ library to evaluate an expression and return `True`/`False` or raise an `AssertionError` or `Exception`.## Installation
```bash
pip install unittest-assertions
```
## Examples
```python
from unittest_assertions.identity import AssertIsInstanceassert_is_instance = AssertIsInstance(msg="Raised an AssertionError")
assert_is_instance("example str", int) # raise AssertionError("'example str' is not an instance of : Raised an AssertionError")
``````python
from unittest_assertions import AssertEqualassert_equal = AssertEqual()
assert_equal(1, 1)
assert_equal(first="hello", second="hello")
```
```python
from unittest_assertions import AssertNotIn
assert_in = AssertNotIn()
assert_in(member=1, container=[5,2,3])
```
# Asserters
## Container
| Asserter | Expression |
|-----------------|----------------|
|AssertIn| `assert member in container`|
| AssertNotIn| `assert member not in container` |## Control
| Asserter | Expression |
|-----------------|----------------|
|AssertRaises| `assert function raises expected_exception` |
|AssertWarns| `assert function warns expected_warning`|
|AssertLogs| `assert logger(level)` |## Equality
| Asserter | Expression |
|-----------------|----------|
|AssertEqual| `assert first == second`|
|AssertNotEqual| `assert first != second` |
|AssertAlmostEqual| `assert first ~= second` |
|AssertNotAlmostEqual| `assert first !~= second` |
|AssertCountEqual| `assert Counter(list(first) == Counter(list(second))`|
|AssertMultilineEqual| `assert first.splitlines() == second.splitlines()` |
|AssertSequenceEqual| `assert seq1 == seq2`|
|AssertListEqual| `assert list1 == list2`|
|AssertTupleEqual| `assert tuple1 == tuple2`|
|AssertSetEqual| `assert set1 == set2` |
|AssertDictEqual| `assert dict1 == dict2`|
|AssertLess| `assert a < b`|
|AssertLessEqual| `assert a <= b` |
|AssertGreater| `assert a > b` |
|AssertGreater| `assert a >= b` |## Identity
| Asserter | Expression |
|-----------------|----------------|
|AssertTrue| `assert expr is True` |
|AssertFalse| `assert expr is False` |
|AssertIs| `assert exp1 is exp2`|
|AssertIsNot| `assert exp1 is not exp2`|
|AssertIsNone| `assert obj is None`|
|AssertIsNotNone| `assert obj is not None`|
|AssertIsInstance|`assert isinstance(obj,class)` |
|AssertIsNotInstance| `assert not isinstance(obj,class)` |## Regex
| Asserter | Expression |
|-----------------|----------------|
|AssertRaisesRegex| `assert expected_regex in expected_exception_message` |
|AssertWarnsRegex| `assert expected_regex in expected_warning_message` |
|AssertRegex| `assert text in expected_regex`|
|AssertNotRegex| `assert text not in expected_regex`|