``hypothesis`` strategies for generating ``SQLAlchemy`` objects.
Project description
hypothesis
strategies for SQLAlchemy
In what follows python3
is an alias for python3.5
or any later
version (python3.6
and so on).
Installation
Install the latest pip
& setuptools
packages versions
python3 -m pip install --upgrade pip setuptools
Release
Download and install the latest stable version from PyPI
repository
python3 -m pip install --upgrade hypothesis_sqlalchemy
Developer
Download and install the latest version from GitHub
repository
git clone https://github.com/lycantropos/hypothesis_sqlalchemy.git
cd hypothesis_sqlalchemy
python3 setup.py install
Usage
Let's take a look at what can be generated and how.
Tables
Suppose we have metadata
>>> from sqlalchemy.schema import MetaData
>>> metadata = MetaData()
We can write strategy that produces tables associated with given metadata
>>> from hypothesis import strategies
>>> from hypothesis_sqlalchemy import tables
>>> tables_strategy = tables.factory(metadatas=strategies.just(metadata))
>>> table = tables_strategy.example()
>>> table.name
kahtvedrpis
>>> table.columns
['kahtvedrpis.wkeggvqvekovyornpixczunhlslpirtqbnpwdppjvccgvy',
'kahtvedrpis.olyrajvsfxbgxzmxheaxdwzgcaj']
Records
Suppose we have table
>>> from sqlalchemy.schema import (Column,
MetaData,
Table)
>>> from sqlalchemy.sql.sqltypes import (Integer,
String)
>>> metadata = MetaData()
>>> user_table = Table('user', metadata,
Column('user_id', Integer,
primary_key=True),
Column('user_name', String(16),
nullable=False),
Column('email_address', String(60)),
Column('password', String(20),
nullable=False))
We can write strategy that
- produces single records (as
tuple
s)>>> from hypothesis_sqlalchemy import tables >>> records = tables.records.factory(user_table) >>> records.example() (1022, '>5', None, '+b8a*,\x04&3<')
- produces records
list
s (with configurablelist
size bounds)>>> from hypothesis_sqlalchemy import tables >>> records_lists = tables.records.lists_factory(user_table, min_size=2, max_size=5) >>> records_lists.example() [(11310, '', 'P\x02LT/Q\\', ''), (16747, '\x08*Z#j0 ;', None, ''), (29983, '', None, ''), (7597, '', '}\x16', '<:+n$W')]
Running tests
Plain
python3 setup.py test
Inside Docker
container
docker-compose up
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file hypothesis_sqlalchemy-0.0.3.tar.gz
.
File metadata
- Download URL: hypothesis_sqlalchemy-0.0.3.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 296ee729b1d79428e529dd52ee04c58f5533e22f75494060bd7bda1a3f4043f5 |
|
MD5 | cfc9aa530ef10b1e9673f756d56acfae |
|
BLAKE2b-256 | e9fa357448474fa00fa244dbda6fcb001d34387facd1d974698a21e3b091d374 |