mirror of https://github.com/jab/bidict.git
Compare commits
2 Commits
05582a619a
...
3d9aa43243
Author | SHA1 | Date |
---|---|---|
Joshua Bronson | 3d9aa43243 | |
Joshua Bronson | 23ae1fdecb |
|
@ -3,8 +3,7 @@ name: Test
|
|||
"on":
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
# Every Friday at noon
|
||||
- cron: "0 12 * * 5"
|
||||
- cron: "30 21 * * *"
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
@ -29,6 +28,7 @@ jobs:
|
|||
- pyversion: "3.11"
|
||||
enable_coverage: true
|
||||
- pyversion: "3.10"
|
||||
crank_up_hypothesis_if_nightly: true
|
||||
- pyversion: "3.9"
|
||||
- pyversion: "3.8"
|
||||
- pyversion: "3.7"
|
||||
|
@ -42,6 +42,10 @@ jobs:
|
|||
python-version: ${{ matrix.pyversion }}
|
||||
cache: pip
|
||||
cache-dependency-path: dev-deps/test.txt
|
||||
- name: Set --hypothesis-profile=more-examples # See tests/conftest.py
|
||||
if: ${{ github.event_name == 'schedule' && matrix.crank_up_hypothesis_if_nightly }}
|
||||
run: |
|
||||
echo PYTEST_ADDOPTS="${PYTEST_ADDOPTS} --hypothesis-profile=more-examples" >> "${GITHUB_ENV}"
|
||||
- run: python -m pip install -U pip setuptools wheel tox==4.0.16
|
||||
- name: cache .hypothesis dir
|
||||
uses: actions/cache@c1a5de879eb890d062a85ee0252d6036480b1fe2
|
||||
|
|
|
@ -15,9 +15,7 @@ jobs:
|
|||
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b
|
||||
with:
|
||||
token: ${{ secrets.ACTIONS_VERSION_UPDATER_TOKEN }}
|
||||
# https://github.com/saadmk11/github-actions-version-updater/issues/49#issuecomment-1356182123
|
||||
# - uses: saadmk11/github-actions-version-updater@v0.7.1
|
||||
- uses: saadmk11/github-actions-version-updater@66922a38bf9dfb2afa06dee9592da2d8a158ceec
|
||||
- uses: saadmk11/github-actions-version-updater@5d7d1286cb239c77a611861d710cfffaeea05fd2
|
||||
with:
|
||||
token: ${{ secrets.ACTIONS_VERSION_UPDATER_TOKEN }}
|
||||
update_version_with: release-commit-sha
|
||||
|
|
|
@ -4,20 +4,9 @@
|
|||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
"""Set up hypothesis."""
|
||||
|
||||
from datetime import timedelta
|
||||
from os import getenv
|
||||
"""Set up Hypothesis."""
|
||||
|
||||
from hypothesis import settings
|
||||
|
||||
|
||||
MAX_EXAMPLES_DEFAULT = 200
|
||||
DEADLINE_DEFAULT = 200
|
||||
|
||||
SETTINGS = {
|
||||
'max_examples': int(getenv('HYPOTHESIS_MAX_EXAMPLES') or MAX_EXAMPLES_DEFAULT),
|
||||
'deadline': timedelta(milliseconds=int(getenv('HYPOTHESIS_DEADLINE') or DEADLINE_DEFAULT)),
|
||||
}
|
||||
settings.register_profile('custom', **SETTINGS)
|
||||
settings.load_profile('custom')
|
||||
settings.register_profile('more-examples', max_examples=10_000)
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
from collections import OrderedDict
|
||||
from operator import attrgetter, itemgetter, methodcaller
|
||||
from os import getenv
|
||||
|
||||
import hypothesis.strategies as st
|
||||
from bidict import DROP_NEW, DROP_OLD, RAISE, OnDup, OrderedBidictBase, namedbidict
|
||||
|
@ -16,9 +15,6 @@ from bidict import DROP_NEW, DROP_OLD, RAISE, OnDup, OrderedBidictBase, namedbid
|
|||
from . import _types as t
|
||||
|
||||
|
||||
MAX = int(getenv('HYPOTHESIS_GEN_MAX_SIZE', '0')) or None
|
||||
|
||||
|
||||
def one_of(items):
|
||||
"""Create a one_of strategy using the given items."""
|
||||
return st.one_of((st.just(i) for i in items))
|
||||
|
@ -47,21 +43,21 @@ PAIRS = st.tuples(ATOMS, ATOMS)
|
|||
NON_MAPPINGS = ATOMS | st.iterables(ATOMS)
|
||||
ALPHABET = tuple(chr(i) for i in range(0x10ffff) if chr(i).isidentifier())
|
||||
VALID_NAMES = st.text(ALPHABET, min_size=1, max_size=16)
|
||||
DICTS_KW_PAIRS = st.dictionaries(VALID_NAMES, ATOMS, max_size=MAX)
|
||||
L_PAIRS = st.lists(PAIRS, max_size=MAX)
|
||||
I_PAIRS = st.iterables(PAIRS, max_size=MAX)
|
||||
DICTS_KW_PAIRS = st.dictionaries(VALID_NAMES, ATOMS)
|
||||
L_PAIRS = st.lists(PAIRS)
|
||||
I_PAIRS = st.iterables(PAIRS)
|
||||
FST_SND = (itemgetter(0), itemgetter(1))
|
||||
L_PAIRS_NODUP = st.lists(PAIRS, unique_by=FST_SND, max_size=MAX)
|
||||
I_PAIRS_NODUP = st.iterables(PAIRS, unique_by=FST_SND, max_size=MAX)
|
||||
L_PAIRS_NODUP = st.lists(PAIRS, unique_by=FST_SND)
|
||||
I_PAIRS_NODUP = st.iterables(PAIRS, unique_by=FST_SND)
|
||||
# Reserve a disjoint set of atoms as a source of values guaranteed not to have been
|
||||
# inserted into a test bidict already.
|
||||
DIFF_ATOMS = st.characters()
|
||||
DIFF_PAIRS = st.tuples(DIFF_ATOMS, DIFF_ATOMS)
|
||||
L_DIFF_PAIRS_NODUP = st.lists(DIFF_PAIRS, unique_by=FST_SND, min_size=1, max_size=MAX)
|
||||
L_DIFF_PAIRS_NODUP = st.lists(DIFF_PAIRS, unique_by=FST_SND, min_size=1)
|
||||
DIFF_ITEMS = st.tuples(L_PAIRS_NODUP, L_DIFF_PAIRS_NODUP)
|
||||
RANDOMS = st.randoms(use_true_random=False)
|
||||
SAME_ITEMS_DIFF_ORDER = st.tuples(
|
||||
st.lists(PAIRS, unique_by=FST_SND, min_size=2, max_size=MAX), RANDOMS
|
||||
st.lists(PAIRS, unique_by=FST_SND, min_size=2), RANDOMS
|
||||
).map(
|
||||
lambda i: (i[0], i[1].sample(i[0], len(i[0]))) # (seq, shuffled seq)
|
||||
).filter(lambda i: i[0] != i[1])
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
import typing as t
|
||||
|
||||
from hypothesis import assume, given, settings
|
||||
from hypothesis.stateful import RuleBasedStateMachine, initialize, invariant, precondition, rule
|
||||
from hypothesis.strategies import integers, data, sampled_from
|
||||
|
||||
from ._strategies import BIDICT_TYPES, I_PAIRS_NODUP
|
||||
|
||||
import bidict
|
||||
from bidict._typing import KT, VT
|
||||
|
||||
|
||||
class BidictStateMachine(RuleBasedStateMachine):
|
||||
@initialize(bidict_type=BIDICT_TYPES, init_items=I_PAIRS_NODUP)
|
||||
def init_lfu(
|
||||
self,
|
||||
bidict_type: t.Type[bidict.BidirectionalMapping[KT, VT]],
|
||||
init_items: t.Any,
|
||||
) -> None:
|
||||
self.bi = bidict_type(init_items)
|
||||
|
||||
@invariant()
|
||||
def bijectivity(self):
|
||||
for b in (self.bi, self.bi.inv):
|
||||
assert all(b.inv[v] == k for (k, v) in b.items())
|
||||
|
||||
# @rule(item=)
|
||||
# def put(self, item)
|
26
tox.ini
26
tox.ini
|
@ -1,26 +0,0 @@
|
|||
[tox]
|
||||
envlist =
|
||||
py3{11,10,9,8,7}
|
||||
pypy3{9,8,7}
|
||||
lint
|
||||
docs
|
||||
|
||||
skip_missing_interpreters = true
|
||||
isolated_build = true
|
||||
|
||||
[testenv]
|
||||
deps = -r dev-deps/test.txt
|
||||
passenv =
|
||||
PYTEST_ADDOPTS
|
||||
FORCE_COLOR
|
||||
allowlist_externals = ./run_tests.py
|
||||
commands = ./run_tests.py
|
||||
|
||||
[testenv:lint]
|
||||
deps = -r dev-deps/lint.txt
|
||||
skip_install = true
|
||||
commands = pre-commit run --all-files --verbose --show-diff-on-failure
|
||||
|
||||
[testenv:docs]
|
||||
deps = -r dev-deps/docs.txt
|
||||
commands = sphinx-build -W --keep-going -b html -d {envtmpdir}/doctrees docs {envtmpdir}/html
|
Loading…
Reference in New Issue