checkcases
Check a Python function against a few example inputs and see clearly what passes and what fails.
It's made for practice: you write a function, list some inputs with the answers you expect, and run check. No test framework, no setup, no dependencies.
pip install checkcases
Example
from checkcases import check, raises
def fizzbuzz(n):
if n % 15 == 0:
return "FizzBuzz"
if n % 3 == 0:
return "Fizz"
if n % 5 == 0:
return "Buzz"
return str(n)
check(fizzbuzz, [
(3, "Fizz"),
(5, "Buzz"),
(15, "FizzBuzz"),
(7, "7"),
])
PASS fizzbuzz(3) == 'Fizz'
PASS fizzbuzz(5) == 'Buzz'
PASS fizzbuzz(15) == 'FizzBuzz'
PASS fizzbuzz(7) == '7'
------------------------------
4/4 passed
When something is wrong, you see the call, what came back and what you expected:
FAIL add(1, 2) returned 4, expected 3
Writing cases
| Case | Means |
|---|---|
(5, 25) |
f(5) should return 25 |
((2, 3), 5) |
f(2, 3) should return 5 |
{"args": (2,), "kwargs": {"b": 3}, "expected": 5} |
f(2, b=3) should return 5 |
((1, 0), raises(ZeroDivisionError)) |
f(1, 0) should raise ZeroDivisionError |
Floats are compared with a small tolerance, so 0.1 + 0.2 counts as 0.3. Change it with check(f, cases, tol=1e-6).
Using the result
check returns a result you can use in scripts:
result = check(add, cases, verbose=False)
if not result:
print(result.failures)
result.passed, result.failed and result.failures hold the details, and the result is truthy when everything passed.
Looking for something to practice on?
PyChallenge has Python challenges to work through in your browser, from beginner to more advanced.
License
MIT
Metadata
Release files for checkcases 0.1.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 |
|---|---|---|---|---|
| checkcases-0.1.0.tar.gz | 5.6 kB | Without provenance | Details for checkcases-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| checkcases-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for checkcases-0.1.0-py3-none-any.whl |
Total release size: 10.7 kB
Release files / checkcases-0.1.0.tar.gz
| Download URL | checkcases-0.1.0.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c2e170f6dd7ed632b2eb861655b5d2c6fb381b76b4a691702103d2ec0514761d
|
|
BLAKE2b-256 checksum How to use checksums |
937efde42540f5fae9909bd1d15ddea09c34ea1b82e3a2a03606a3cb080e27a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.15.2
|
Release files / checkcases-0.1.0-py3-none-any.whl
| Download URL | checkcases-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
76f7bbebfd62d0cdd0efdc9ee9b135e27c4f6a0b7feef300217bd153e20f4fc8
|
|
BLAKE2b-256 checksum How to use checksums |
dac71f5c10e97b3c2de1101ddea163e9b5a3afdac72f6784587dc6e95f7f50a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.15.2
|
Security for checkcases 0.1.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.