lollipop-hypothesis
Library to generate random test data using Hypothesis based on Lollipop schema.
Example
from collections import namedtuple
import lollipop.types as lt
import lollipop.validators as lv
import string
EMAIL_REGEXP = r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]{2,}\.[a-zA-Z0-9-.]{2,}$"
Email = lt.validated_type(lt.String, 'Email', lv.Regexp(EMAIL_REGEXP))
User = namedtuple('User', ['name', 'email', 'age'])
USER = lt.Object({
'name': lt.String(validate=lv.Length(min=1)),
'email': Email(),
'age': lt.Optional(lt.Integer(validate=lv.Range(min=18))),
}, constructor=User)
import hypothesis as h
import hypothesis.strategies as hs
import lollipop_hypothesis as lh
# Write a test using data generation strategy based on Lollipop schema
@h.given(lh.type_strategy(USER))
def test_can_register_any_valid_user(user):
register(user)
# Configure custom strategy for Email type
lh.register(
Email,
lambda _, type, context=None: \
hs.tuples(
hs.text('abcdefghijklmnopqrstuvwxyz'
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
'0123456789'
'_.+-', min_size=1),
hs.lists(
hs.text('abcdefghijklmnopqrstuvwxyz'
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
'0123456789', min_size=2),
min_size=2,
average_size=3,
)
).map(lambda (name, domain_parts): name + '@' + '.'.join(domain_parts)),
)
# Or configure custom strategy for the whole type instance
lh.register(
USER,
lambda registry, type, context=None: \
hs.builds(
User,
name=hs.text(min_size=1),
email=registry.convert(Email(), context),
age=hs.integers(min_value=0, max_value=100),
)
)
Installation
$ pip install lollipop-hypothesis # install optional package for regex support $ pip install lollipop-hypothesis[regex]
Requirements
Python >= 2.7 and <= 3.6
lollipop >= 1.1.3
hypothesis >= 3.8
(optional) hypothesis-regex >= 0.1
Project Links
License
MIT licensed. See the bundled LICENSE file for more details.
Metadata
Release files for lollipop-hypothesis 0.2
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 |
|---|---|---|---|---|
| lollipop-hypothesis-0.2.tar.gz | 7.2 kB | Without provenance | Details for lollipop-hypothesis-0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lollipop_hypothesis-0.2-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for lollipop_hypothesis-0.2-py2.py3-none-any.whl |
Total release size: 14.3 kB
Release files / lollipop-hypothesis-0.2.tar.gz
| Download URL | lollipop-hypothesis-0.2.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0d8297a89e486037e0908b6dfe7ed1b4475a5642d2cbc48552a174d9a22d9ad1
|
|
BLAKE2b-256 checksum How to use checksums |
30591c7e8f0db3ae2437db3bcca96e18beebaf3d8f1900ca9587ec72e70a42e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / lollipop_hypothesis-0.2-py2.py3-none-any.whl
| Download URL | lollipop_hypothesis-0.2-py2.py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
4f97297fbd7d86cb8c814f42535389a8743b43c84b20497465c3b8448bd6e039
|
|
BLAKE2b-256 checksum How to use checksums |
d2233b7b5cc5ab64cc096c4bcc61e15b7a91d14ba14f0d9f95267a1074a9eeda
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for lollipop-hypothesis 0.2
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.