Skip to content

Commit

Permalink
Use hypothesis profiles for settings
Browse files Browse the repository at this point in the history
* Avoid deadlines altogheter in CI.
* Remove most deadlines when run locally, keep deadlines for
  selected slow tests, and mark them.
  • Loading branch information
berland committed Aug 11, 2022
1 parent a3e999d commit 85d8b7d
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Generate coverage report
run: |
pytest tests --disable-warnings --cov=pyscal --cov-report=xml
pytest --hypothesis-profile ci tests --disable-warnings --cov=pyscal --cov-report=xml
- name: Upload coverage to Codecov
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pyscal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- name: Run tests
run: |
python -c "import pyscal"
pytest tests/
pytest --strict-markers --hypothesis-profile ci tests/
- name: Syntax check documentation
run: |
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ignore = E741, W503, E203
markers =
integration: marks a test as an integration test
plot: marks a test as interactive, plots will flash to the screen
slow: a test that is expected to take up to a second or so to execute
xfail_strict=True

[build_sphinx]
Expand Down
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
import logging

import pytest
from hypothesis import HealthCheck, settings

settings.register_profile(
"ci", max_examples=250, deadline=None, suppress_health_check=[HealthCheck.too_slow]
)
settings.register_profile("slow", max_examples=50, deadline=1000)


@pytest.fixture
Expand Down
3 changes: 1 addition & 2 deletions tests/test_fromtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import pandas as pd
import pytest
from hypothesis import given, settings
from hypothesis import given

from pyscal import GasOil, WaterOil, WaterOilGas
from pyscal.utils.testing import check_table, float_df_checker
Expand Down Expand Up @@ -641,7 +641,6 @@ def test_fromtable_types():
)


@settings(deadline=2000)
@given(st.floats(min_value=1e-5, max_value=1))
def test_wo_fromtable_h(h):
"""Test making curves from tabular data with random stepsize h"""
Expand Down
14 changes: 6 additions & 8 deletions tests/test_gasoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import numpy as np
import pandas as pd
import pytest
from hypothesis import given, settings
from hypothesis import given

from pyscal import GasOil
from pyscal.constants import SWINTEGERS
from pyscal.constants import MAX_EXPONENT, SWINTEGERS
from pyscal.utils.relperm import truncate_zeroness
from pyscal.utils.testing import (
check_linear_sections,
Expand Down Expand Up @@ -130,7 +130,6 @@ def test_plotting(mocker):
gasoil.plotkrgkrog(logyscale=True, mpl_ax=None)


@settings(deadline=2000)
@given(st.text())
def test_gasoil_tag(tag):
"""Test tagging of GasOil objects,
Expand All @@ -143,7 +142,6 @@ def test_gasoil_tag(tag):
sat_table_str_ok(gasoil.SGFN())


@settings(deadline=2000)
@given(
st.floats(min_value=0, max_value=0.15), # swl
st.floats(min_value=0, max_value=0.3), # sgcr
Expand Down Expand Up @@ -182,7 +180,6 @@ def test_gasoil_normalization(swl, sgcr, sorg, h, tag):
assert float_df_checker(gasoil.table, "SG", gasoil.sgcr, "SGN", 0)


@settings(deadline=2000)
@given(
st.floats(min_value=0, max_value=0.3), # swl
st.floats(min_value=0, max_value=0.3), # sgcr
Expand Down Expand Up @@ -401,8 +398,10 @@ def test_kroend():
assert gasoil.table["KROG"].max() == 0.5


@settings(deadline=2000)
@given(st.floats(), st.floats())
@given(
st.floats(min_value=1e-4, max_value=MAX_EXPONENT), # ng
st.floats(min_value=1e-4, max_value=MAX_EXPONENT), # nog
)
def test_gasoil_corey1(ng, nog):
"""Test the Corey formulation for gasoil"""
gasoil = GasOil()
Expand Down Expand Up @@ -469,7 +468,6 @@ def test_comments():
assert "PC" in sgof


@settings(deadline=2000)
@given(st.floats(), st.floats(), st.floats(), st.floats(), st.floats())
def test_gasoil_let1(l, e, t, krgend, krgmax):
"""Test the LET formulation, take 1"""
Expand Down
6 changes: 1 addition & 5 deletions tests/test_gaswater.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import matplotlib.pyplot
import numpy as np
import pytest
from hypothesis import given, settings
from hypothesis import given

from pyscal import GasWater
from pyscal.constants import SWINTEGERS
Expand Down Expand Up @@ -79,7 +79,6 @@ def test_fast():
assert "krw = krg" not in sgfn # Crosspoint should not be present


@settings(deadline=2000)
@given(st.text())
def test_gaswater_tag(tag):
"""Test that we are unlikely to crash Eclipse
Expand All @@ -91,7 +90,6 @@ def test_gaswater_tag(tag):
sat_table_str_ok(gaswater.SGFN())


@settings(deadline=2000)
@given(st.floats(), st.floats())
def test_gaswater_corey1(nw, ng):
"""Test random corey parameters"""
Expand All @@ -116,7 +114,6 @@ def test_gaswater_corey1(nw, ng):
assert len(sgfnstr) > 100


@settings(deadline=2000)
@given(st.floats(), st.floats(), st.floats(), st.floats(), st.floats())
def test_gaswater_let1(l, e, t, krwend, krwmax):
"""Test random LET parameters"""
Expand All @@ -140,7 +137,6 @@ def test_gaswater_let1(l, e, t, krwend, krwmax):
assert len(sgfnstr) > 100


@settings(deadline=2000)
@given(
st.floats(min_value=0, max_value=0.3),
st.floats(min_value=0, max_value=0.3),
Expand Down
5 changes: 4 additions & 1 deletion tests/test_scalrecommendation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from pyscal.factory import slicedict
from pyscal.utils.testing import check_table, sat_table_str_ok

slow_profile = settings.get_profile("slow")

# Example SCAL recommendation, low case
LOW_SAMPLE_LET = {
"swirr": 0.1,
Expand Down Expand Up @@ -206,7 +208,8 @@ def test_make_scalrecommendation_go():
rec.interpolate(2)


@settings(max_examples=10, deadline=2000)
@pytest.mark.slow
@settings(deadline=slow_profile.deadline)
@given(
st.floats(min_value=-1.1, max_value=1.1), st.floats(min_value=-1.1, max_value=1.1)
)
Expand Down
5 changes: 1 addition & 4 deletions tests/test_slgof.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import hypothesis.strategies as st
import numpy as np
import pytest
from hypothesis import given, settings
from hypothesis import given

from pyscal import GasOil, WaterOilGas
from pyscal.constants import EPSILON, SWINTEGERS
Expand All @@ -24,7 +24,6 @@ def check_table(dframe):
assert dframe["PC"].is_monotonic_decreasing


@settings(deadline=2000)
@given(
st.floats(min_value=0.0, max_value=0.3),
st.floats(min_value=0.0, max_value=0.3),
Expand Down Expand Up @@ -125,7 +124,6 @@ def test_numerical_problems(swl, sorg, sgcr):
check_table(slgof)


@settings(deadline=2000) # This is slow for small h
@given(
st.floats(min_value=0.0, max_value=0.3),
st.floats(min_value=0.0, max_value=0.3),
Expand All @@ -150,7 +148,6 @@ def test_slgof_hypo(swl, sorg, sgcr, h):
sat_table_str_ok(slgof_str)


@settings(deadline=2000)
@given(
st.floats(min_value=0.0, max_value=0.3),
st.floats(min_value=0.0, max_value=0.3),
Expand Down
17 changes: 12 additions & 5 deletions tests/test_utils_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
)
from pyscal.utils.testing import check_table, float_df_checker, sat_table_str_ok

slow_profile = settings.get_profile("slow")

@settings(deadline=1000)

@pytest.mark.slow
@settings(deadline=slow_profile.deadline)
@given(
st.floats(min_value=0, max_value=0.1), # swl
st.floats(min_value=0, max_value=0.0), # dswcr
Expand Down Expand Up @@ -239,7 +242,8 @@ def test_tag_preservation():
sat_table_str_ok(interpolant1.SGOF())


@settings(max_examples=40, deadline=5000)
@pytest.mark.slow
@settings(max_examples=slow_profile.max_examples, deadline=slow_profile.deadline)
@given(
st.floats(min_value=0.01, max_value=0.1), # swl
st.floats(min_value=0, max_value=0.0), # dswcr
Expand Down Expand Up @@ -338,7 +342,8 @@ def test_interpolate_wo(
# trigger a discontinuity in the interpolants, which we don't want.


@settings(max_examples=40, deadline=5000)
@pytest.mark.slow
@settings(max_examples=slow_profile.max_examples, deadline=slow_profile.deadline)
@given(
st.floats(min_value=0.01, max_value=0.1), # swl
st.floats(min_value=0, max_value=0.0), # dswcr
Expand Down Expand Up @@ -409,7 +414,8 @@ def test_interpolate_wo_pc(swl, dswcr, dswlhigh, sorw, a_l, a_h, b_l, b_h):
# trigger a discontinuity in the interpolants, which we don't want.


@settings(max_examples=40, deadline=2000)
@pytest.mark.slow
@settings(deadline=slow_profile.deadline)
@given(
st.floats(min_value=0, max_value=0.1), # swl
st.floats(min_value=0, max_value=0.1), # sgcr
Expand Down Expand Up @@ -671,7 +677,8 @@ def test_ip_go_kroend():
assert float_df_checker(go_ip.table, "SG", 1 - 0.01 - 0.15, "KROG", 0)


@settings(max_examples=50, deadline=5000)
@pytest.mark.slow
@settings(max_examples=slow_profile.max_examples, deadline=slow_profile.deadline)
@given(
st.floats(min_value=0, max_value=0.1), # swl
st.floats(min_value=0, max_value=0.1), # sgcr
Expand Down
6 changes: 1 addition & 5 deletions tests/test_wateroil.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
import pandas as pd
import pytest
from hypothesis import given, settings
from hypothesis import given

from pyscal import WaterOil
from pyscal.constants import SWINTEGERS
Expand Down Expand Up @@ -43,7 +43,6 @@ def check_endpoints(wateroil, krwend, krwmax, kroend):
assert np.isclose(wateroil.table["KRW"].max(), krwend)


@settings(deadline=2000)
@given(st.text())
def test_wateroil_tag(tag):
"""Test that we are unlikely to crash Eclipse
Expand All @@ -55,7 +54,6 @@ def test_wateroil_tag(tag):
sat_table_str_ok(wateroil.SWFN())


@settings(deadline=2000)
@given(st.floats(), st.floats())
def test_wateroil_corey1(nw, now):
"""Test random corey parameters"""
Expand All @@ -76,7 +74,6 @@ def test_wateroil_corey1(nw, now):
assert len(swofstr) > 100


@settings(deadline=2000)
@given(st.floats(), st.floats(), st.floats(), st.floats(), st.floats())
def test_wateroil_let1(l, e, t, krwend, krwmax):
"""Test random LET parameters"""
Expand All @@ -96,7 +93,6 @@ def test_wateroil_let1(l, e, t, krwend, krwmax):
assert len(swofstr) > 100


@settings(deadline=2000)
@given(
st.floats(min_value=0, max_value=0.4),
st.floats(min_value=0, max_value=0.4),
Expand Down
4 changes: 1 addition & 3 deletions tests/test_wateroil_pc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import hypothesis.strategies as st
import numpy as np
import pytest
from hypothesis import given, settings
from hypothesis import given

from pyscal import WaterOil
from pyscal.constants import MAX_EXPONENT
Expand Down Expand Up @@ -84,7 +84,6 @@ def test_simple_j_petro():
wateroil.add_simple_J_petro(a=1, b=2)


@settings(deadline=2000)
@given(
st.floats(min_value=0.001, max_value=1000000),
st.floats(min_value=-0.9 * MAX_EXPONENT, max_value=-0.001),
Expand Down Expand Up @@ -139,7 +138,6 @@ def test_normalized_j(caplog):
assert "a parameter is very high" in caplog.text


@settings(deadline=2000)
@given(
st.floats(min_value=0, max_value=0.1), # swirr
st.floats(min_value=0.01, max_value=0.1), # swl - swirr
Expand Down
6 changes: 1 addition & 5 deletions tests/test_wateroil_saturation.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"""Test module for the saturation ranges in WaterOil objects"""

import hypothesis.strategies as st
from hypothesis import given, settings
from hypothesis import given

from pyscal import WaterOil
from pyscal.constants import EPSILON, SWINTEGERS
from pyscal.utils.testing import check_table, float_df_checker


@settings(deadline=2000)
@given(
st.floats(),
st.floats(),
Expand All @@ -27,7 +26,6 @@ def test_wateroil_random(swirr, swl, swcr, sorw, socr, h, tag):
pass


@settings(deadline=2000)
@given(
st.floats(min_value=0, max_value=0.1),
st.floats(min_value=0, max_value=0.15),
Expand Down Expand Up @@ -69,7 +67,6 @@ def test_wateroil_normalization(swirr, swl, swcr, sorw, socr_add, h, tag):
assert float_df_checker(wateroil.table, "SW", 1.0, "SWNPC", 1)


@settings(deadline=2000)
@given(st.floats(min_value=0, max_value=1 - EPSILON))
def test_wateroil_swir(swirr):
"""Check that the saturation values are valid for all swirr"""
Expand Down Expand Up @@ -105,7 +102,6 @@ def test_wateroil_socr(socr):
check_table(wateroil.table)


@settings(deadline=2000)
@given(st.floats(min_value=0, max_value=1), st.floats(min_value=0, max_value=1))
def test_wateroil_dual(param1, param2):
"""Test combination of 2 floats as parameters"""
Expand Down

0 comments on commit 85d8b7d

Please sign in to comment.