hypothesis-regex


Namehypothesis-regex JSON
Version 0.3.1 PyPI version JSON
download
home_pagehttps://github.com/maximkulkin/hypothesis-regex
SummaryHypothesis extension to allow generating strings based on regex
upload_time2018-03-14 16:46:16
maintainer
docs_urlNone
authorMaxim Kulkin
requires_python
licenseMIT
keywords hypothesis regex
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            ****************
hypothesis-regex
****************

.. image:: https://img.shields.io/pypi/l/hypothesis-regex.svg
    :target: https://github.com/maximkulkin/hypothesis-regex/blob/master/LICENSE
    :alt: License: MIT

.. image:: https://img.shields.io/travis/maximkulkin/hypothesis-regex.svg
    :target: https://travis-ci.org/maximkulkin/hypothesis-regex
    :alt: Build Status

.. image:: https://img.shields.io/pypi/v/hypothesis-regex.svg
    :target: https://pypi.python.org/pypi/hypothesis-regex
    :alt: PyPI

`Hypothesis <https://hypothesis.readthedocs.io/en/latest/>`_ extension 
to allow generating strings based on regex. Useful in case you have some schema
(e.g. JSON Schema) which already has regular expressions validating data.

Example
=======

.. code:: python

    from hypothesis_regex import regex
    import requests
    import json

    EMAIL_REGEX = r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]{2,}\.[a-zA-Z0-9-.]{2,}$"

    @given(regex(EMAIL_REGEX))
    def test_registering_user(email):
        response = requests.post('/signup', json.dumps({'email': email}))
        assert response.status_code == 201

Features
========

Regex strategy returns strings that always match given regex (this check is
enforced by a filter) and it tries to do that in an effective way so that less
generated examples are filtered out. However, some regex constructs may decrease
strategy efficiency and should be used with caution:

* "^" and "$" in the middle of a string - do not do anything.
* "\\b" and "\\B" (word boundary and not a word boundary) - do not do anything and
  instead just rely on top-level regex match filter to filter out non-matching
  examples.
* positive lookaheads and lookbehinds just generate data they should match (as if
  it was part of preceeding/following parts).
* negative lookaheads and lookbehinds do not do anything so it relies on
  preceeding/following parts to generate correct strings (otherwise the example will
  be filtered out).
* "(?(id)yes-pattern|no-pattern)" does not actually check if group with given id
  was actually used and instead just generates either yes- or no-pattern.

Regex strategy tries to go all crazy about generated data (e.g. "$" at the end of a
string either does not generate anything or generate a newline). The idea is not to
generate a nicely looking strings but instead any craze unexpected combination that
will still match your given regex so you can prepare for those and handle them in
most apropriate way.

You can use regex flags to get more control on strategy:

* re.IGNORECASE - literals or literal ranges generate both lowercase and uppercase
  letters. E.g. `r'a'` will generate both `"a"` and `"A"`, or `'[a-z]'` will generate
  both lowercase and uppercase english characters.
* re.DOTALL - "." char will be able to generate newlines
* re.UNICODE - character categories
  ("\\w", "\\d" or "\\s" and their negations) will generate unicode characters.
  This is default for Python 3, see re.ASCII to reverse it.

There are two ways to pass regex flags:

1. By passing compiled regex with that flags: `regex(re.compile('abc', re.IGNORECASE))`
2. By using inline flags syntax: `regex('(?i)abc')`

Installation
============
::

    $ pip install hypothesis-regex

Requirements
============

- Python >= 2.7 and <= 3.6
- `hypothesis <https://pypi.python.org/pypi/hypothesis>`__ >= 3.8

Project Links
=============

- PyPI: https://pypi.python.org/pypi/hypothesis-regex
- Issues: https://github.com/maximkulkin/hypothesis-regex/issues

License
=======

MIT licensed. See the bundled `LICENSE <https://github.com/maximkulkin/hypothesis-regex/blob/master/LICENSE>`_ file for more details.



            

Raw data

            {
    "_id": null,
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "cheesecake_code_kwalitee_id": null,
    "keywords": "hypothesis,regex",
    "upload_time": "2018-03-14 16:46:16",
    "author": "Maxim Kulkin",
    "home_page": "https://github.com/maximkulkin/hypothesis-regex",
    "github_user": "maximkulkin",
    "download_url": "https://pypi.python.org/packages/b1/0c/f58b9b187d48274a74238344f66afe262fc953bd4c4dd5fc3206c769b2ea/hypothesis-regex-0.3.1.tar.gz",
    "platform": "",
    "version": "0.3.1",
    "cheesecake_documentation_id": null,
    "description": "****************\nhypothesis-regex\n****************\n\n.. image:: https://img.shields.io/pypi/l/hypothesis-regex.svg\n    :target: https://github.com/maximkulkin/hypothesis-regex/blob/master/LICENSE\n    :alt: License: MIT\n\n.. image:: https://img.shields.io/travis/maximkulkin/hypothesis-regex.svg\n    :target: https://travis-ci.org/maximkulkin/hypothesis-regex\n    :alt: Build Status\n\n.. image:: https://img.shields.io/pypi/v/hypothesis-regex.svg\n    :target: https://pypi.python.org/pypi/hypothesis-regex\n    :alt: PyPI\n\n`Hypothesis <https://hypothesis.readthedocs.io/en/latest/>`_ extension \nto allow generating strings based on regex. Useful in case you have some schema\n(e.g. JSON Schema) which already has regular expressions validating data.\n\nExample\n=======\n\n.. code:: python\n\n    from hypothesis_regex import regex\n    import requests\n    import json\n\n    EMAIL_REGEX = r\"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]{2,}\\.[a-zA-Z0-9-.]{2,}$\"\n\n    @given(regex(EMAIL_REGEX))\n    def test_registering_user(email):\n        response = requests.post('/signup', json.dumps({'email': email}))\n        assert response.status_code == 201\n\nFeatures\n========\n\nRegex strategy returns strings that always match given regex (this check is\nenforced by a filter) and it tries to do that in an effective way so that less\ngenerated examples are filtered out. However, some regex constructs may decrease\nstrategy efficiency and should be used with caution:\n\n* \"^\" and \"$\" in the middle of a string - do not do anything.\n* \"\\\\b\" and \"\\\\B\" (word boundary and not a word boundary) - do not do anything and\n  instead just rely on top-level regex match filter to filter out non-matching\n  examples.\n* positive lookaheads and lookbehinds just generate data they should match (as if\n  it was part of preceeding/following parts).\n* negative lookaheads and lookbehinds do not do anything so it relies on\n  preceeding/following parts to generate correct strings (otherwise the example will\n  be filtered out).\n* \"(?(id)yes-pattern|no-pattern)\" does not actually check if group with given id\n  was actually used and instead just generates either yes- or no-pattern.\n\nRegex strategy tries to go all crazy about generated data (e.g. \"$\" at the end of a\nstring either does not generate anything or generate a newline). The idea is not to\ngenerate a nicely looking strings but instead any craze unexpected combination that\nwill still match your given regex so you can prepare for those and handle them in\nmost apropriate way.\n\nYou can use regex flags to get more control on strategy:\n\n* re.IGNORECASE - literals or literal ranges generate both lowercase and uppercase\n  letters. E.g. `r'a'` will generate both `\"a\"` and `\"A\"`, or `'[a-z]'` will generate\n  both lowercase and uppercase english characters.\n* re.DOTALL - \".\" char will be able to generate newlines\n* re.UNICODE - character categories\n  (\"\\\\w\", \"\\\\d\" or \"\\\\s\" and their negations) will generate unicode characters.\n  This is default for Python 3, see re.ASCII to reverse it.\n\nThere are two ways to pass regex flags:\n\n1. By passing compiled regex with that flags: `regex(re.compile('abc', re.IGNORECASE))`\n2. By using inline flags syntax: `regex('(?i)abc')`\n\nInstallation\n============\n::\n\n    $ pip install hypothesis-regex\n\nRequirements\n============\n\n- Python >= 2.7 and <= 3.6\n- `hypothesis <https://pypi.python.org/pypi/hypothesis>`__ >= 3.8\n\nProject Links\n=============\n\n- PyPI: https://pypi.python.org/pypi/hypothesis-regex\n- Issues: https://github.com/maximkulkin/hypothesis-regex/issues\n\nLicense\n=======\n\nMIT licensed. See the bundled `LICENSE <https://github.com/maximkulkin/hypothesis-regex/blob/master/LICENSE>`_ file for more details.\n\n\n",
    "tox": true,
    "lcname": "hypothesis-regex",
    "name": "hypothesis-regex",
    "github": true,
    "coveralls": false,
    "bugtrack_url": "",
    "license": "MIT",
    "travis_ci": true,
    "github_project": "hypothesis-regex",
    "summary": "Hypothesis extension to allow generating strings based on regex",
    "split_keywords": [
        "hypothesis",
        "regex"
    ],
    "author_email": "maxim.kulkin@gmail.com",
    "urls": [
        {
            "has_sig": false,
            "upload_time": "2018-03-14T16:46:16",
            "comment_text": "",
            "python_version": "source",
            "url": "https://pypi.python.org/packages/b1/0c/f58b9b187d48274a74238344f66afe262fc953bd4c4dd5fc3206c769b2ea/hypothesis-regex-0.3.1.tar.gz",
            "md5_digest": "f4d97ff427e5cbe6fee0876a7474773e",
            "downloads": 0,
            "filename": "hypothesis-regex-0.3.1.tar.gz",
            "packagetype": "sdist",
            "path": "b1/0c/f58b9b187d48274a74238344f66afe262fc953bd4c4dd5fc3206c769b2ea/hypothesis-regex-0.3.1.tar.gz",
            "size": 9190
        },
        {
            "has_sig": false,
            "upload_time": "2018-03-14T16:46:14",
            "comment_text": "",
            "python_version": "py2.py3",
            "url": "https://pypi.python.org/packages/4a/5e/66e12e5bab7aaa5cf8a20fc22d877c575969f4b308e1db3d69e590a6fbcf/hypothesis_regex-0.3.1-py2.py3-none-any.whl",
            "md5_digest": "9adbf1b8f8ea4636a4f7cc4badd11b1d",
            "downloads": 0,
            "filename": "hypothesis_regex-0.3.1-py2.py3-none-any.whl",
            "packagetype": "bdist_wheel",
            "path": "4a/5e/66e12e5bab7aaa5cf8a20fc22d877c575969f4b308e1db3d69e590a6fbcf/hypothesis_regex-0.3.1-py2.py3-none-any.whl",
            "size": 9018
        }
    ],
    "cheesecake_installability_id": null
}
        
Elapsed time: 0.28264s