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:

  • 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

Suppose we have metadata

>>> from sqlalchemy.schema import MetaData 
>>> metadata = MetaData()

We can write a 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 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_sqlalchemy import tables
    >>> records = tables.records.factory(user_table)
    >>> records.example()
    (1022, '>5', None, '+b8a*,\x04&3<')
    
  • produces records lists (with configurable list 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')]
    

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 --tag release

Bump version

bump2version --verbose --tag release

This will set version to major.minor.patch and add Git tag.

Notes

To avoid inconsistency between branches and pull requests, bumping version should be merged into master branch as separate pull request.

Running tests

Plain:

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

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.0.6.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

hypothesis_sqlalchemy-0.0.6-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hypothesis_sqlalchemy-0.0.6.tar.gz
  • Upload date:
  • Size: 7.7 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.0.6.tar.gz
Algorithm Hash digest
SHA256 4171e77c54b4e6178c7ffcc9153a137f6ccababb918304ebaaac700ebbe6befa
MD5 a2dbc9ea64a39a8b6e658811655d8aa7
BLAKE2b-256 35df9cbf46c7741b1b99f24c71e549772d783f650b8afd70392016cf57071b2b

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: hypothesis_sqlalchemy-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 10.4 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.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 819f2e864adc7bb4e620a81d1caf7df7fc6917aadb3ff417e1354ab1de293543
MD5 f50fe11b78d59eab377d40873bb7c058
BLAKE2b-256 0b5b2bcfda5be65922c7ef1810f194a1b2c411ef836dd6bbfe689f3e369e4d76

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