hypothesis-sqlalchemy


Namehypothesis-sqlalchemy JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/lycantropos/hypothesis_sqlalchemy/
Summary``hypothesis`` strategies for ``SQLAlchemy`` objects and data from them.
upload_time2023-02-04 18:09:29
maintainer
docs_urlNone
authorAzat Ibrakov
requires_python>=3.7
licenseMIT License
keywords sqlalchemy hypothesis
VCS
bugtrack_url
requirements sqlalchemy hypothesis
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.7` or `pypy3.7`
or any later version (`python3.8`, `pypy3.8` 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.7",
    "maintainer_email": "",
    "keywords": "SQLAlchemy,hypothesis",
    "author": "Azat Ibrakov",
    "author_email": "azatibrakov@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/91/6b/c5a5a0034fc28b05f0a39af09623bb799564e872394db4179825c1bd3a43/hypothesis_sqlalchemy-1.1.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.7` or `pypy3.7`\nor any later version (`python3.8`, `pypy3.8` 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",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "``hypothesis`` strategies for ``SQLAlchemy`` objects and data from them.",
    "version": "1.1.0",
    "split_keywords": [
        "sqlalchemy",
        "hypothesis"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a1912ae6129226a2a21e94997c072408ec5460a8f7abed04a64303e85a807deb",
                "md5": "c54498ae4808179fc69f35afd43e2385",
                "sha256": "478d7264f39e8bf03326d993aff54fbcd58109b320b8fae25e7384556cca91da"
            },
            "downloads": -1,
            "filename": "hypothesis_sqlalchemy-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c54498ae4808179fc69f35afd43e2385",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 13250,
            "upload_time": "2023-02-04T18:09:27",
            "upload_time_iso_8601": "2023-02-04T18:09:27.578394Z",
            "url": "https://files.pythonhosted.org/packages/a1/91/2ae6129226a2a21e94997c072408ec5460a8f7abed04a64303e85a807deb/hypothesis_sqlalchemy-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "916bc5a5a0034fc28b05f0a39af09623bb799564e872394db4179825c1bd3a43",
                "md5": "9d6df7b96eacd76d3d3f23d3f0d69ccb",
                "sha256": "48caca6dfc16a8fb09c647b0e1ce94b59a4d6348c78d16343ab03220679e91b6"
            },
            "downloads": -1,
            "filename": "hypothesis_sqlalchemy-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "9d6df7b96eacd76d3d3f23d3f0d69ccb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 11295,
            "upload_time": "2023-02-04T18:09:29",
            "upload_time_iso_8601": "2023-02-04T18:09:29.191202Z",
            "url": "https://files.pythonhosted.org/packages/91/6b/c5a5a0034fc28b05f0a39af09623bb799564e872394db4179825c1bd3a43/hypothesis_sqlalchemy-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-02-04 18:09:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "lycantropos",
    "github_project": "hypothesis_sqlalchemy",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [
        {
            "name": "sqlalchemy",
            "specs": [
                [
                    ">=",
                    "1.4.46"
                ],
                [
                    "<",
                    "3.0"
                ]
            ]
        },
        {
            "name": "hypothesis",
            "specs": [
                [
                    ">=",
                    "6.66.0"
                ],
                [
                    "<",
                    "7.0"
                ]
            ]
        }
    ],
    "lcname": "hypothesis-sqlalchemy"
}
        
Elapsed time: 0.04890s