simple-assertions
Assertion library (skeleton) inspired from assertpy but without batteries! also allows to convert all the assertions to warnings, just like delayed asserts.
Motivation
assertpy is beautiful library but for my needs it's too much, i really loved the API of
assertpy so i created new module because of following reasons
please check tests/test_*.py for use cases.
- I wanted
assert_warnto be dynamic, i.e. given certain condition all assertions are converted to warning.- I added
ASSERT_ERROR_AS_WARNINGvariable which can do that! - Modified
assert_thatAPI to make is call based withassert_that(.., as_warn=True)
- I added
- Extending is possible but i wanted more intuitive logic
- I exposed the
SimpleAssertionsclass, and just inherit it to add new method
- I exposed the
assert_thatinassertpycreates new instance of class and loads all the extensions on every call, and i wanted to avoid that!- By exposing the
SimpleAssertionclass, you can just make it part of your assertion class
- By exposing the
Note: earlier i used
assert_thatkeyword fromassertpybut i felt like it's copying from other library , so i changedassert_thattocheck, while reading this gives same amount of experience but saved 6 chars!
Installation
pip install simple-assertions
Usage
Please check tests files for more usage here is only basic usage
As Function
Just import the check function, and away you go...
from simple_assertions import check
def test_something():
check(4 + 10).is_equal_to(14)
check(1).is_instance_of(int)
check(3, "lucky_num", as_warn=True).is_equal_to(4)
As instance
from simple_assertions import SimpleAssertions
class YourTestClass:
def __init__(self):
self.check = SimpleAssertions().check
def test_something(self):
self.check(4 + 10).is_equal_to(14)
self.check(1).is_instance_of(int)
self.check(3, "lucky_num", as_warn=True).is_equal_to(4)
Add your own batteries
from simple_assertions import SimpleAssertions
from typing import Union
class YourAssertions(SimpleAssertions):
def __init__(self, as_warn=False, logger=None):
super().__init__(as_warn, logger)
def is_greater_than(self, other: Union[int, float]):
if self.val_to_chk.val < other:
self.raise_err(self.compare_err_msg(other, "to be greater than"))
return self
class YourTestClass:
def __init__(self):
self.check = YourAssertions().check
def test_something(self):
self.check(4 + 10).is_greater_than(10).is_equal_to(14)
self.check(1).is_instance_of(int)
self.check(3, "lucky_num", as_warn=True).is_equal_to(4)
Though only checked with unittests but it should work fine with pytest or Nose.
Metadata
Release files for simple-assertions 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| simple-assertions-0.3.0.tar.gz | 4.7 kB | Without provenance | Details for simple-assertions-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| simple_assertions-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for simple_assertions-0.3.0-py3-none-any.whl |
Total release size: 10.5 kB
Release files / simple-assertions-0.3.0.tar.gz
| Download URL | simple-assertions-0.3.0.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6529fa4f2ee30ab79622707dea80a10b3271f605b9cd3ae13264b28afa2c19ad
|
|
BLAKE2b-256 checksum How to use checksums |
bfb6d8e954614af1e259cd503db20310c43d7d9e71a0eab7f215842cf7ecda83
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3
|
Release files / simple_assertions-0.3.0-py3-none-any.whl
| Download URL | simple_assertions-0.3.0-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
440e07ea07f0ac82fb922986247cea9d1cd25282c9633c8e17798f6fcb34d7c9
|
|
BLAKE2b-256 checksum How to use checksums |
4cbd7de60b2fa4fd805d07152a67451283a6cc63413841d346652c3895e73d4b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3
|
Security for simple-assertions 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.