Skip to main content
https://badge.fury.io/py/covertable.svg https://github.com/walkframe/covertable/actions/workflows/python.yaml/badge.svg https://codecov.io/gh/walkframe/covertable/branch/master/graph/badge.svg https://img.shields.io/badge/License-Apache%202.0-blue.svg

Requirements

  • Python: 3.9 or later.

Installation

$ pip install covertable

Usage

Import covertable and call the make function.

>>> from covertable import make, sorters, criteria

>>> machine_list = ['iphone', 'pixel']
>>> os_list = ['ios', 'android']
>>> browser_list = ['FireFox', 'Chrome', 'Safari']

>>> # list input and output
>>> make(
...     [machine_list, os_list, browser_list],
...     strength=2,  # default: 2
...     sorter=sorters.random,  # default: sorters.hash
...     criterion=criteria.simple,  # default: criteria.greedy
...     salt='my_seed',  # default: ''
...     constraints=[
...         {'operator': 'custom', 'fields': [0, 1], 'evaluate':
...             lambda row: not(row[1] == 'android' and row[0] != 'pixel') and not(row[1] == 'ios' and row[0] != 'iphone')},
...     ],
... )
[['iphone', 'ios', 'FireFox'], ['pixel', 'android', 'Chrome'], ...]

>>> # dict input and output
>>> make(
...     {'machine': machine_list, 'os': os_list, 'browser': browser_list},
...     strength=2,
...     tolerance=3,
...     constraints=[
...         {'operator': 'or', 'conditions': [
...             {'operator': 'eq', 'left': 'os', 'value': 'android'},
...             {'operator': 'ne', 'left': 'machine', 'value': 'pixel'},
...         ]},
...     ],
... )
[{'machine': 'pixel', 'browser': 'Chrome', 'os': 'android'}, ...]

Declarative Constraints

The constraints parameter accepts a list of condition dicts evaluated under three-valued logic with forward checking and constraint propagation.

>>> from covertable import make

>>> rows = make(
...     {
...         'OS': ['Win', 'Mac', 'Linux'],
...         'Browser': ['Chrome', 'Firefox', 'Safari'],
...     },
...     constraints=[
...         # Safari only on Mac
...         {'operator': 'or', 'conditions': [
...             {'operator': 'ne', 'left': 'Browser', 'value': 'Safari'},
...             {'operator': 'eq', 'left': 'OS', 'value': 'Mac'},
...         ]},
...     ],
... )

Supported condition operators:

  • Comparison: eq, ne, gt, lt, gte, lte, in

  • Logical: and, or, not

  • Custom: fn (escape hatch with requires and evaluate callable)

Field-to-field comparison uses right:

{'operator': 'ne', 'left': 'A', 'right': 'B'}

Arithmetic expressions can be used as operands:

# A + B > 10
{'operator': 'gt', 'left': {'operator': 'add', 'left': 'A', 'right': 'B'}, 'value': 10}

Supported arithmetic operators: add, sub, mul, div, mod

Stats

When using constraints, the Controller exposes a stats property:

>>> from covertable.main import Controller

>>> ctrl = Controller(
...     {'A': [1, 2, 3], 'B': ['x', 'y', 'z']},
...     constraints=[{'operator': 'ne', 'left': 'A', 'value': 1}],
... )
>>> rows = list(ctrl.make_async())
>>> ctrl.stats
{'total_pairs': 9, 'pruned_pairs': 3, 'covered_pairs': 6, ...}

PICT Model

Parse PICT-format model files directly:

>>> from covertable.pict import PictModel

>>> model = PictModel("""
... OS: Win, Mac, Linux
... Browser: Chrome, Firefox, ~Safari
... IF [Browser] = "Safari" THEN [OS] = "Mac";
... """)
>>> rows = model.make()
>>> model.stats

Options

All options are keyword arguments to covertable.make.

strength

Number of factors to be covered. (default: 2)

The higher the value, the more combinations are generated.

sorter

Controls the order of pair processing.

sorters.hash:

Deterministic ordering using FNV-1a hash. (default)

Accepts a salt option for reproducible results.

sorters.random:

Random ordering. Different results each time.

criterion

criteria.greedy:

Attempts to make efficient combinations. (default)

Accepts a tolerance option.

criteria.simple:

Extracts any pairs that can be stored into the processing row.

constraints

A list of declarative condition dicts. See Declarative Constraints above.

comparer

A dict of custom comparison functions to override default operators.

make(factors, comparer={'eq': lambda a, b: str(a) == str(b)})

Development

# preparation
$ python3 -m venv venv
$ source venv/bin/activate
(venv) $ pip install -r dev_requirements.txt

# testing
(venv) $ pytest

More info

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

covertable-3.1.0.tar.gz (23.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

covertable-3.1.0-py3-none-any.whl (25.0 kB view details)

Uploaded Python 3

File details

Details for the file covertable-3.1.0.tar.gz.

File metadata

  • Download URL: covertable-3.1.0.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for covertable-3.1.0.tar.gz
Algorithm Hash digest
SHA256 0e0d71b59e10d0ee048319f286a4af42687f8d37a5e6bae511891b821554e61c
MD5 29f37bcd00b61d800656db8ecdb4ffdf
BLAKE2b-256 855f11f08977c96c0fe59711efd75b69e77f77b11fa2792825d14bc1ea71b90b

See more details on using hashes here.

File details

Details for the file covertable-3.1.0-py3-none-any.whl.

File metadata

  • Download URL: covertable-3.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for covertable-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d2862f6941cfabc34eaeebbc4d14448e1e77a291f8c0d9e59cf36ee87358b864
MD5 1db12bf73a5065fa9a3ae805e3c3d658
BLAKE2b-256 88e4c50fe8dbbaab0baa59c524a3570027cd5063aa589d37eacdd25c7771776e

See more details on using hashes here.

Release history Release notifications | RSS feed

3.2.0

2 files

This release

3.1.0 This release

2 files

3.0.0

2 files

2.1.0

2 files

2.0.1

2 files

2.0.0

2 files

1.1.0

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page