TinkerTest
Inline testing/validation in python 3, based on this wonderful blog post: https://tinkering.xyz/abusing-type-annotations/
What is this?
TinkerTest aims to simplify data validation checking in both unit tests and production environments. In order to do this
conveniently, TinkerTest abuses makes use of the fact that python type annotations can be any arbitrary python
expression. Using this fact allows us to inject validation logic into your scripts which simply evaluate your type
annotations.
Helpful Hint
Starting from python 3.7, the annotations future import exists. This may be helpful for you, as its lazy evaluation
should prevent some common mistakes in using this library.
Trivial Example
# my_script.py
from tinkertest import inject_into_type
class MyClass:
my_field: 'my_field < 0' # This field only accepts values < 0
my_str_field: str # This field only accepts strings
def __init__(self, my_field, my_str_field):
self.my_field = my_field
self.my_str_field = my_str_field
# This function only accepts a non-None argument and should always return 1
def some_func(self, input_val: 'input_val is not None') -> 'returned == 1': # 'returned' is a magic variable for use in return annotations
...
inject_into_type(MyClass) # Wires all the injections, now any calls will be validated!
Metadata
Release files for TinkerTest 0.1.1
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 |
|---|---|---|---|---|
| TinkerTest-0.1.1.tar.gz | 8.5 kB | Without provenance | Details for TinkerTest-0.1.1.tar.gz |
Release files / TinkerTest-0.1.1.tar.gz
| Download URL | TinkerTest-0.1.1.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
723d269ff81dff28b0b10f2d4dadde8c6687fcc78ea4dcd1f435ee9eab22aa46
|
|
BLAKE2b-256 checksum How to use checksums |
1bea3c4658f60592f1a1735cfbdffd977a54ad50a10540670972922da5772bfc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0
|
Security for TinkerTest 0.1.1
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.