hypothesis-sqlalchemy


Namehypothesis-sqlalchemy JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/lycantropos/hypothesis_sqlalchemy/
Summary``hypothesis`` strategies for ``SQLAlchemy`` objects and data from them.
upload_time2022-03-29 16:43:00
maintainer
docs_urlNone
authorAzat Ibrakov
requires_python>=3.6
licenseMIT License
keywords sqlalchemy hypothesis
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            hypothesis_sqlalchemy
=====================

[![](https://github.com/lycantropos/hypothesis_sqlalchemy/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/lycantropos/hypothesis_sqlalchemy/actions/workflows/ci.yml "Github Actions")
[![](https://codecov.io/gh/lycantropos/hypothesis_sqlalchemy/branch/master/graph/badge.svg)](https://codecov.io/gh/lycantropos/hypothesis_sqlalchemy "Codecov")
[![](https://img.shields.io/github/license/lycantropos/hypothesis_sqlalchemy.svg)](https://github.com/lycantropos/hypothesis_sqlalchemy/blob/master/LICENSE "License")
[![](https://badge.fury.io/py/hypothesis-sqlalchemy.svg)](https://badge.fury.io/py/hypothesis-sqlalchemy "PyPI")

In what follows `python` is an alias for `python3.6` or `pypy3.6`
or any later version (`python3.7`, `pypy3.7` and so on).

Installation
------------

Install the latest `pip` & `setuptools` packages versions
```bash
python -m pip install --upgrade pip setuptools
```

### User

Download and install the latest stable version from `PyPI` repository
```bash
python -m pip install --upgrade hypothesis_sqlalchemy
```

### Developer

Download the latest version from `GitHub` repository
```bash
git clone https://github.com/lycantropos/hypothesis_sqlalchemy.git
cd hypothesis_sqlalchemy
```

Install dependencies
```bash
python -m pip install -r requirements.txt
```

Install
```bash
python setup.py install
```

Usage
-----

With setup
```python
>>> 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
```python
>>> 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
```python
>>> 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)
    ```python
    >>> 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 configurable `list` size bounds)
    ```python
    >>> 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](https://github.com/c4urself/bump2version#installation).

#### Pre-release

Choose which version number category to bump following [semver
specification](http://semver.org/).

Test bumping version
```bash
bump2version --dry-run --verbose $CATEGORY
```

where `$CATEGORY` is the target version number category name, possible
values are `patch`/`minor`/`major`.

Bump version
```bash
bump2version --verbose $CATEGORY
```

This will set version to `major.minor.patch-alpha`. 

#### Release

Test bumping version
```bash
bump2version --dry-run --verbose release
```

Bump version
```bash
bump2version --verbose release
```

This will set version to `major.minor.patch`.

### Running tests

Install dependencies
```bash
python -m pip install -r requirements-tests.txt
```

Plain
```bash
pytest
```

Inside `Docker` container:
- with `CPython`
  ```bash
  docker-compose --file docker-compose.cpython.yml up
  ```
- with `PyPy`
  ```bash
  docker-compose --file docker-compose.pypy.yml up
  ```

`Bash` script:
- with `CPython`
  ```bash
  ./run-tests.sh
  ```
  or
  ```bash
  ./run-tests.sh cpython
  ```

- with `PyPy`
  ```bash
  ./run-tests.sh pypy
  ```

`PowerShell` script:
- with `CPython`
  ```powershell
  .\run-tests.ps1
  ```
  or
  ```powershell
  .\run-tests.ps1 cpython
  ```
- with `PyPy`
  ```powershell
  .\run-tests.ps1 pypy
  ```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/lycantropos/hypothesis_sqlalchemy/",
    "name": "hypothesis-sqlalchemy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "SQLAlchemy,hypothesis",
    "author": "Azat Ibrakov",
    "author_email": "azatibrakov@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d2/44/f85a6d6c98c6eb6057a5a27a7b1e5cd69dac6bcdd3dfebe1cdc10de76dd8/hypothesis_sqlalchemy-1.0.0.tar.gz",
    "platform": null,
    "description": "hypothesis_sqlalchemy\n=====================\n\n[![](https://github.com/lycantropos/hypothesis_sqlalchemy/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/lycantropos/hypothesis_sqlalchemy/actions/workflows/ci.yml \"Github Actions\")\n[![](https://codecov.io/gh/lycantropos/hypothesis_sqlalchemy/branch/master/graph/badge.svg)](https://codecov.io/gh/lycantropos/hypothesis_sqlalchemy \"Codecov\")\n[![](https://img.shields.io/github/license/lycantropos/hypothesis_sqlalchemy.svg)](https://github.com/lycantropos/hypothesis_sqlalchemy/blob/master/LICENSE \"License\")\n[![](https://badge.fury.io/py/hypothesis-sqlalchemy.svg)](https://badge.fury.io/py/hypothesis-sqlalchemy \"PyPI\")\n\nIn what follows `python` is an alias for `python3.6` or `pypy3.6`\nor any later version (`python3.7`, `pypy3.7` and so on).\n\nInstallation\n------------\n\nInstall the latest `pip` & `setuptools` packages versions\n```bash\npython -m pip install --upgrade pip setuptools\n```\n\n### User\n\nDownload and install the latest stable version from `PyPI` repository\n```bash\npython -m pip install --upgrade hypothesis_sqlalchemy\n```\n\n### Developer\n\nDownload the latest version from `GitHub` repository\n```bash\ngit clone https://github.com/lycantropos/hypothesis_sqlalchemy.git\ncd hypothesis_sqlalchemy\n```\n\nInstall dependencies\n```bash\npython -m pip install -r requirements.txt\n```\n\nInstall\n```bash\npython setup.py install\n```\n\nUsage\n-----\n\nWith setup\n```python\n>>> import warnings\n>>> from hypothesis.errors import NonInteractiveExampleWarning\n>>> # ignore hypothesis warnings caused by `example` method call\n... warnings.filterwarnings('ignore', category=NonInteractiveExampleWarning)\n\n```\nlet's take a look at what can be generated and how.\n\n### Tables\n\nWe can write a strategy that produces tables\n```python\n>>> from hypothesis_sqlalchemy import scheme\n>>> from sqlalchemy.engine.default import DefaultDialect\n>>> dialect = DefaultDialect()\n>>> tables = scheme.tables(dialect,\n...                        min_size=3,\n...                        max_size=10)\n>>> table = tables.example()\n>>> from sqlalchemy.schema import Table\n>>> isinstance(table, Table)\nTrue\n>>> from sqlalchemy.schema import Column\n>>> all(isinstance(column, Column) for column in table.columns)\nTrue\n>>> 3 <= len(table.columns) <= 10\nTrue\n\n```\n\n### Records\n\nSuppose we have a table\n```python\n>>> from sqlalchemy.schema import (Column,\n...                                MetaData,\n...                                Table)\n>>> from sqlalchemy.sql.sqltypes import (Integer,\n...                                      String)\n>>> metadata = MetaData()\n>>> user_table = Table('user', metadata,\n...                    Column('user_id', Integer,\n...                           primary_key=True),\n...                    Column('user_name', String(16),\n...                           nullable=False),\n...                    Column('email_address', String(60)),\n...                    Column('password', String(20),\n...                           nullable=False))\n\n```\nand we can write strategy that\n* produces single records (as `tuple`s)\n    ```python\n    >>> from hypothesis import strategies\n    >>> from hypothesis_sqlalchemy.sample import table_records\n    >>> records = table_records(user_table, \n    ...                         email_address=strategies.emails())\n    >>> record = records.example()\n    >>> isinstance(record, tuple)\n    True\n    >>> len(record) == len(user_table.columns)\n    True\n    >>> all(column.nullable and value is None\n    ...     or isinstance(value, column.type.python_type) \n    ...     for value, column in zip(record, user_table.columns))\n    True\n  \n    ```\n* produces records `list`s (with configurable `list` size bounds)\n    ```python\n    >>> from hypothesis_sqlalchemy.sample import table_records_lists\n    >>> records_lists = table_records_lists(user_table,\n    ...                                     min_size=2,\n    ...                                     max_size=5, \n    ...                                     email_address=strategies.emails())\n    >>> records_list = records_lists.example()\n    >>> isinstance(records_list, list)\n    True\n    >>> 2 <= len(records_list) <= 5\n    True\n    >>> all(isinstance(record, tuple) for record in records_list)\n    True\n    >>> all(len(record) == len(user_table.columns) for record in records_list)\n    True\n\n    ```\n\nDevelopment\n-----------\n\n### Bumping version\n\n#### Preparation\n\nInstall\n[bump2version](https://github.com/c4urself/bump2version#installation).\n\n#### Pre-release\n\nChoose which version number category to bump following [semver\nspecification](http://semver.org/).\n\nTest bumping version\n```bash\nbump2version --dry-run --verbose $CATEGORY\n```\n\nwhere `$CATEGORY` is the target version number category name, possible\nvalues are `patch`/`minor`/`major`.\n\nBump version\n```bash\nbump2version --verbose $CATEGORY\n```\n\nThis will set version to `major.minor.patch-alpha`. \n\n#### Release\n\nTest bumping version\n```bash\nbump2version --dry-run --verbose release\n```\n\nBump version\n```bash\nbump2version --verbose release\n```\n\nThis will set version to `major.minor.patch`.\n\n### Running tests\n\nInstall dependencies\n```bash\npython -m pip install -r requirements-tests.txt\n```\n\nPlain\n```bash\npytest\n```\n\nInside `Docker` container:\n- with `CPython`\n  ```bash\n  docker-compose --file docker-compose.cpython.yml up\n  ```\n- with `PyPy`\n  ```bash\n  docker-compose --file docker-compose.pypy.yml up\n  ```\n\n`Bash` script:\n- with `CPython`\n  ```bash\n  ./run-tests.sh\n  ```\n  or\n  ```bash\n  ./run-tests.sh cpython\n  ```\n\n- with `PyPy`\n  ```bash\n  ./run-tests.sh pypy\n  ```\n\n`PowerShell` script:\n- with `CPython`\n  ```powershell\n  .\\run-tests.ps1\n  ```\n  or\n  ```powershell\n  .\\run-tests.ps1 cpython\n  ```\n- with `PyPy`\n  ```powershell\n  .\\run-tests.ps1 pypy\n  ```\n\n\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "``hypothesis`` strategies for ``SQLAlchemy`` objects and data from them.",
    "version": "1.0.0",
    "split_keywords": [
        "sqlalchemy",
        "hypothesis"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "71833e3ddc737f7c34f2ef7a068eab24",
                "sha256": "3def854f4333f9cf7874148aea0acb4804c611fb8049bc9565f5997b2c66a86e"
            },
            "downloads": -1,
            "filename": "hypothesis_sqlalchemy-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "71833e3ddc737f7c34f2ef7a068eab24",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 12882,
            "upload_time": "2022-03-29T16:42:59",
            "upload_time_iso_8601": "2022-03-29T16:42:59.297848Z",
            "url": "https://files.pythonhosted.org/packages/97/1f/8bbf5cdcd086f5b5ef4df931da2eaab11a97949af84bf40d5521e77b48bf/hypothesis_sqlalchemy-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "10158a0fd8acde4976013544dbcaf5da",
                "sha256": "229e88d463b558aa9fc98d08aae8bc779e76c73e83e26b421ec2fe1bdf4b847d"
            },
            "downloads": -1,
            "filename": "hypothesis_sqlalchemy-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "10158a0fd8acde4976013544dbcaf5da",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 11035,
            "upload_time": "2022-03-29T16:43:00",
            "upload_time_iso_8601": "2022-03-29T16:43:00.758349Z",
            "url": "https://files.pythonhosted.org/packages/d2/44/f85a6d6c98c6eb6057a5a27a7b1e5cd69dac6bcdd3dfebe1cdc10de76dd8/hypothesis_sqlalchemy-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-03-29 16:43:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "lycantropos",
    "github_project": "hypothesis_sqlalchemy",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "lcname": "hypothesis-sqlalchemy"
}
        
Elapsed time: 0.35920s