Skip to main content

Library to generate random test data using Hypothesis based on Lollipop schema

Project description

License: MIT Build Status PyPI

Library to generate random test data using Hypothesis based on Lollipop schema.

Example

import lollipop.types as lt
import lollipop.validators as lv
import string

EMAIL_REGEXP = r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"
Email = lt.validated_type(lt.String, 'Email', lv.Regexp(EMAIL_REGEXP))

USER = lt.Object({
    'name': lt.String(validate=lv.Length(min=1)),
    'email': Email(),
    'age': lt.Optional(lt.Integer(validate=lv.Range(min=18))),
})

import hypothesis as h
import hypothesis.strategies as hs
import lollipop_hypothesis as lh

# Use 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)),
)

# 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)

Installation

$ pip install lollipop-hypothesis

Requirements

License

MIT licensed. See the bundled LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lollipop-hypothesis-0.1.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

lollipop_hypothesis-0.1-py2.py3-none-any.whl (6.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file lollipop-hypothesis-0.1.tar.gz.

File metadata

File hashes

Hashes for lollipop-hypothesis-0.1.tar.gz
Algorithm Hash digest
SHA256 c19be9816424eb9c75b737d3b5282b5449b86815da86c69a7cc5831157194f2c
MD5 6cf25f17ac097585930bf326bc2f903e
BLAKE2b-256 992a0d2f4595d7803c4bdb47b691cd6832f8d42f125ffe3f2a1175ded0bdd5be

See more details on using hashes here.

File details

Details for the file lollipop_hypothesis-0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for lollipop_hypothesis-0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 722bc1d7635b8efa701ef2072cbcf31e37adcea688f10961e0ab00bbea2d54ba
MD5 078ef78ecac4feead2911f5a44a085c3
BLAKE2b-256 c664744785ee99e6a16d8abf8093c4956f7f1c64ebe0c157ad7a3fc6e17504cb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page