Skip to main content

hypothesis strategies for geometric objects (points, polygons, etc.).

Project description

hypothesis_geometry

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_geometry
    
  • with PyPy
    pypy -m pip install --upgrade hypothesis_geometry
    

Developer

Download the latest version from GitHub repository

git clone https://github.com/lycantropos/hypothesis_geometry.git
cd hypothesis_geometry

Install dependencies:

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

Install:

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

Usage

With setup

>>> from hypothesis import strategies
>>> from hypothesis_geometry import planar
>>> min_coordinate, max_coordinate = -100, 100
>>> coordinates_type = int
>>> coordinates = strategies.integers(min_coordinate, max_coordinate)
>>> 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.

Points

>>> points = planar.points(coordinates)
>>> point = points.example()
>>> isinstance(point, tuple)
True
>>> len(point) == 2
True
>>> all(isinstance(coordinate, coordinates_type) for coordinate in point)
True
>>> all(min_coordinate <= coordinate <= max_coordinate for coordinate in point)
True

Contours

>>> min_size, max_size = 5, 10
>>> contours = planar.contours(coordinates, 
...                            min_size=min_size,
...                            max_size=max_size)
>>> contour = contours.example()
>>> isinstance(contour, list)
True
>>> min_size <= len(contour) <= max_size
True
>>> all(isinstance(vertex, tuple) for vertex in contour)
True
>>> all(len(vertex) == 2 for vertex in contour)
True
>>> all(all(isinstance(coordinate, coordinates_type) for coordinate in vertex)
...     for vertex in contour)
True
>>> all(all(min_coordinate <= coordinate <= max_coordinate for coordinate in vertex)
...     for vertex in contour)
True

also planar.concave_contours & planar.convex_contours options are available.

Caveats

  • Strategies may be slow depending on domain, so it may be necessary to add HealthCheck.filter_too_much, HealthCheck.too_slow in suppress_health_check and set deadline to None.

  • Unbounded floating point strategies for coordinates (like hypothesis.strategies.floats or hypothesis.strategies.decimals with unset min_value/max_value) do not play well with bounded sizes and may cause a lot of searching iterations with no success, so it is recommended to use bounded floating point coordinates with bounded sizes or unbounded coordinates with unbounded sizes.


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 --force-reinstall -r requirements-tests.txt
    
  • with PyPy
    pypy -m pip install --force-reinstall -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_geometry-0.2.0.tar.gz (9.4 kB view hashes)

Uploaded Source

Built Distribution

hypothesis_geometry-0.2.0-py3-none-any.whl (12.6 kB view hashes)

Uploaded Python 3

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