Skip to main content

``hypothesis`` strategies for generating ``SQLAlchemy`` objects.

Project description

hypothesis strategies for SQLAlchemy

In what follows

  • python is an alias for python3.5 or any later version (python3.6 and so on),
  • pypy is an alias for pypy3.5 or any later version (pypy3.6 and so on).

Installation

Install the latest pip & setuptools packages versions:

  • with CPython
    python -m pip install --upgrade pip setuptools
    
  • with PyPy
    pypy -m pip install --upgrade pip setuptools
    

User

Download and install the latest stable version from PyPI repository:

  • with CPython
    python -m pip install --upgrade hypothesis_sqlalchemy
    
  • with PyPy
    pypy -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:

  • with CPython
    python -m pip install -r requirements.txt
    
  • with PyPy
    pypy -m pip install -r requirements.txt
    

Install:

  • with CPython
    python setup.py install
    
  • with PyPy
    pypy setup.py install
    

Usage

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 tabular
>>> from sqlalchemy.schema import MetaData
>>> tables = tabular.factory(metadata=MetaData(),
...                          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 tuples)
    >>> from hypothesis import strategies
    >>> from hypothesis_sqlalchemy import tabular
    >>> records = tabular.records.factory(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 lists (with configurable list size bounds)
    >>> from hypothesis_sqlalchemy import tabular
    >>> records_lists = tabular.records.lists_factory(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:

  • with CPython
    python -m pip install -r requirements-tests.txt
    
  • with PyPy
    pypy -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 (e.g. can be used in Git hooks):

  • with CPython

    ./run-tests.sh
    

    or

    ./run-tests.sh cpython
    
  • with PyPy

    ./run-tests.sh pypy
    

PowerShell script (e.g. can be used in Git hooks):

  • with CPython
    .\run-tests.ps1
    
    or
    .\run-tests.ps1 cpython
    
  • with PyPy
    .\run-tests.ps1 pypy
    

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

hypothesis_sqlalchemy-0.3.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

hypothesis_sqlalchemy-0.3.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file hypothesis_sqlalchemy-0.3.0.tar.gz.

File metadata

  • Download URL: hypothesis_sqlalchemy-0.3.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.4

File hashes

Hashes for hypothesis_sqlalchemy-0.3.0.tar.gz
Algorithm Hash digest
SHA256 7404a649a6cfcbaef7208163827a83b40b21e69d8e904ee1bd7063c054bc4e57
MD5 26903aaa6477f086f18fd1b29830d2bf
BLAKE2b-256 52fa8e151a3bf15ae7a09a98a6b6e1541cc95bd060d1500d6d8935a8db424d65

See more details on using hashes here.

Provenance

File details

Details for the file hypothesis_sqlalchemy-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: hypothesis_sqlalchemy-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.4

File hashes

Hashes for hypothesis_sqlalchemy-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6105fff6754a90f73e032a8322b35140fc3428a8e0d567f5f24cbd66e990d5f
MD5 a82cf3f8179a3c78718735a4dd17a96a
BLAKE2b-256 b46216378365e424928a28dbee661f65f00b6e56127de1b3659aba83a41c7821

See more details on using hashes here.

Provenance

Supported by

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