Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: reintroduce too_slow healthchecks – speed up test example generation #69

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
jobs:
test:
strategy:
fail-fast: true
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest, windows-latest]
Expand All @@ -26,5 +26,5 @@ jobs:
python-version: ${{ matrix.python-version }}
cache: "pip"
- run: pip install ".[test]"
- run: pytest --hypothesis-profile ci
- run: pytest --hypothesis-profile ci --hypothesis-show-statistics

10 changes: 8 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from hypothesis import Verbosity, settings
from hypothesis import HealthCheck, Verbosity, settings

settings.register_profile("ci", max_examples=1000)
settings.register_profile(
"ci",
verbosity=Verbosity.verbose,
max_examples=1000,
deadline=2000,
suppress_health_check=[HealthCheck.too_slow, HealthCheck.data_too_large],
)
settings.register_profile("debug", max_examples=10, verbosity=Verbosity.verbose)
86 changes: 86 additions & 0 deletions tests/_superscript.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"""Functions to convert from normal to superscript characters.
After https://stackoverflow.com/questions/8651361/how-do-you-print-superscript/58612677#58612677
with thanks to norok2.


Examples:
>>> "".translate(to_superscript)
''
>>> "0".translate(to_superscript)
'⁰'
>>> "the quick brown fox jumps over the lazy dog".translate(to_superscript)
'ᵗʰᵉ ۹ᵘᶦᶜᵏ ᵇʳᵒʷⁿ ᶠᵒˣ ʲᵘᵐᵖˢ ᵒᵛᵉʳ ᵗʰᵉ ˡᵃᶻʸ ᵈᵒᵍ'
>>> "CCV (FTW)".translate(to_superscript)
'ᶜᶜⱽ ⁽ᶠᵀᵂ⁾'
"""

superscript_map = {
"0": "⁰",
"1": "¹",
"2": "²",
"3": "³",
"4": "⁴",
"5": "⁵",
"6": "⁶",
"7": "⁷",
"8": "⁸",
"9": "⁹",
"a": "ᵃ",
"b": "ᵇ",
"c": "ᶜ",
"d": "ᵈ",
"e": "ᵉ",
"f": "ᶠ",
"g": "ᵍ",
"h": "ʰ",
"i": "ᶦ",
"j": "ʲ",
"k": "ᵏ",
"l": "ˡ",
"m": "ᵐ",
"n": "ⁿ",
"o": "ᵒ",
"p": "ᵖ",
"q": "۹",
"r": "ʳ",
"s": "ˢ",
"t": "ᵗ",
"u": "ᵘ",
"v": "ᵛ",
"w": "ʷ",
"x": "ˣ",
"y": "ʸ",
"z": "ᶻ",
"A": "ᴬ",
"B": "ᴮ",
"C": "ᶜ",
"D": "ᴰ",
"E": "ᴱ",
"F": "ᶠ",
"G": "ᴳ",
"H": "ᴴ",
"I": "ᴵ",
"J": "ᴶ",
"K": "ᴷ",
"L": "ᴸ",
"M": "ᴹ",
"N": "ᴺ",
"O": "ᴼ",
"P": "ᴾ",
"Q": "Q",
"R": "ᴿ",
"S": "ˢ",
"T": "ᵀ",
"U": "ᵁ",
"V": "ⱽ",
"W": "ᵂ",
"X": "ˣ",
"Y": "ʸ",
"Z": "ᶻ",
"+": "⁺",
"-": "⁻",
"=": "⁼",
"(": "⁽",
")": "⁾",
}
to_superscript = str.maketrans(superscript_map)
8 changes: 4 additions & 4 deletions tests/test_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ def _load_dump_via_disk(o, module_name):
serializer_dump_load_strategy = st.sampled_from(
[
load_dump_pickle_string,
load_dump_dill_string,
load_dump_yaml_string,
# load_dump_dill_string,
# load_dump_yaml_string,
load_dump_pickle_disk,
load_dump_dill_disk,
load_dump_yaml_disk,
# load_dump_dill_disk,
# load_dump_yaml_disk,
]
)

Expand Down
30 changes: 27 additions & 3 deletions tests/test_state.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
import logging

import pandas as pd
from hypothesis import HealthCheck, given, settings
from hypothesis import given
from pandas import DataFrame

from autora.state import StandardState
from autora.variable import Variable, VariableCollection

from .test_serializer import serializer_dump_load_strategy
from .test_strategies import standard_state_strategy
from .test_strategies import (
dataframe_strategy,
standard_state_strategy,
variable_strategy,
variablecollection_strategy,
)

logger = logging.getLogger(__name__)


@given(variable_strategy(), serializer_dump_load_strategy)
def test_variable_serialize_deserialize(o: Variable, dump_load):
o_loaded = dump_load(o)
assert o == o_loaded


@given(variablecollection_strategy(), serializer_dump_load_strategy)
def test_variablecollection_serialize_deserialize(o: VariableCollection, dump_load):
o_loaded = dump_load(o)
assert o == o_loaded


@given(dataframe_strategy(), serializer_dump_load_strategy)
def test_dataframe_serialize_deserialize(o: DataFrame, dump_load):
o_loaded = dump_load(o)
o.equals(o_loaded)


@given(standard_state_strategy(), serializer_dump_load_strategy)
@settings(suppress_health_check={HealthCheck.too_slow}, deadline=1000)
def test_state_serialize_deserialize(o: StandardState, dump_load):
o_loaded = dump_load(o)
assert o.variables == o_loaded.variables
Expand Down
Loading
Loading