``hypothesis`` strategies for ``SQLAlchemy`` objects and data from them.
Project description
hypothesis_sqlalchemy
In what follows python
is an alias for python3.7
or pypy3.7
or any later version (python3.8
, pypy3.8
and so on).
Installation
Install the latest pip
& setuptools
packages versions
python -m pip install --upgrade pip setuptools
User
Download and install the latest stable version from PyPI
repository
python -m pip install --upgrade hypothesis_sqlalchemy
Developer
Download the latest version from GitHub
repository
git clone https://github.com/lycantropos/hypothesis_sqlalchemy.git
cd hypothesis_sqlalchemy
Install dependencies
python -m pip install -r requirements.txt
Install
python setup.py install
Usage
With setup
>>> import warnings
>>> from hypothesis.errors import NonInteractiveExampleWarning
>>> # ignore hypothesis warnings caused by `example` method call
... warnings.filterwarnings('ignore', category=NonInteractiveExampleWarning)
let's take a look at what can be generated and how.
Tables
We can write a strategy that produces tables
>>> from hypothesis_sqlalchemy import scheme
>>> from sqlalchemy.engine.default import DefaultDialect
>>> dialect = DefaultDialect()
>>> tables = scheme.tables(dialect,
... min_size=3,
... max_size=10)
>>> table = tables.example()
>>> from sqlalchemy.schema import Table
>>> isinstance(table, Table)
True
>>> from sqlalchemy.schema import Column
>>> all(isinstance(column, Column) for column in table.columns)
True
>>> 3 <= len(table.columns) <= 10
True
Records
Suppose we have a 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))
and we can write strategy that
- produces single records (as
tuple
s)>>> from hypothesis import strategies >>> from hypothesis_sqlalchemy.sample import table_records >>> records = table_records(user_table, ... email_address=strategies.emails()) >>> record = records.example() >>> isinstance(record, tuple) True >>> len(record) == len(user_table.columns) True >>> all(column.nullable and value is None ... or isinstance(value, column.type.python_type) ... for value, column in zip(record, user_table.columns)) True
- produces records
list
s (with configurablelist
size bounds)>>> from hypothesis_sqlalchemy.sample import table_records_lists >>> records_lists = table_records_lists(user_table, ... min_size=2, ... max_size=5, ... email_address=strategies.emails()) >>> records_list = records_lists.example() >>> isinstance(records_list, list) True >>> 2 <= len(records_list) <= 5 True >>> all(isinstance(record, tuple) for record in records_list) True >>> all(len(record) == len(user_table.columns) for record in records_list) True
Development
Bumping version
Preparation
Install bump2version.
Pre-release
Choose which version number category to bump following semver specification.
Test bumping version
bump2version --dry-run --verbose $CATEGORY
where $CATEGORY
is the target version number category name, possible
values are patch
/minor
/major
.
Bump version
bump2version --verbose $CATEGORY
This will set version to major.minor.patch-alpha
.
Release
Test bumping version
bump2version --dry-run --verbose release
Bump version
bump2version --verbose release
This will set version to major.minor.patch
.
Running tests
Install dependencies
python -m pip install -r requirements-tests.txt
Plain
pytest
Inside Docker
container:
- with
CPython
docker-compose --file docker-compose.cpython.yml up
- with
PyPy
docker-compose --file docker-compose.pypy.yml up
Bash
script:
-
with
CPython
./run-tests.sh
or
./run-tests.sh cpython
-
with
PyPy
./run-tests.sh pypy
PowerShell
script:
- with
CPython
.\run-tests.ps1
or.\run-tests.ps1 cpython
- with
PyPy
.\run-tests.ps1 pypy
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
Built Distribution
File details
Details for the file hypothesis_sqlalchemy-1.1.0.tar.gz
.
File metadata
- Download URL: hypothesis_sqlalchemy-1.1.0.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48caca6dfc16a8fb09c647b0e1ce94b59a4d6348c78d16343ab03220679e91b6 |
|
MD5 | 9d6df7b96eacd76d3d3f23d3f0d69ccb |
|
BLAKE2b-256 | 916bc5a5a0034fc28b05f0a39af09623bb799564e872394db4179825c1bd3a43 |
Provenance
File details
Details for the file hypothesis_sqlalchemy-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: hypothesis_sqlalchemy-1.1.0-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 478d7264f39e8bf03326d993aff54fbcd58109b320b8fae25e7384556cca91da |
|
MD5 | c54498ae4808179fc69f35afd43e2385 |
|
BLAKE2b-256 | a1912ae6129226a2a21e94997c072408ec5460a8f7abed04a64303e85a807deb |