Skip to content

Commit

Permalink
Relax deadlines for test using hypotesis.st.text() (#357)
Browse files Browse the repository at this point in the history
This hypothesis strategy can probably generate some very long
strings that occasionally makes tests time out. Also
changed other deadline settings to at least 2000 msec for
consistency.

Bonus: Updated black.
  • Loading branch information
berland authored Mar 15, 2022
1 parent ce03684 commit 8459917
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 22 deletions.
8 changes: 4 additions & 4 deletions pyscal/utils/monotonicity.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def modify_dframe_monotonicity(

# Modify data for monotonicity:
for col in monotonicity:
accuracy = 1.0 / 10.0 ** digits - epsilon
accuracy = 1.0 / 10.0**digits - epsilon

if "allowzero" in monotonicity[col]:
# Treat zero as an exception for strict monotonicity:
Expand All @@ -117,7 +117,7 @@ def modify_dframe_monotonicity(
), "Too many iterations for monotonicity fix"

dframe.loc[constants, col] = (
dframe.loc[constants, col] + sign / 10.0 ** digits - epsilon
dframe.loc[constants, col] + sign / 10.0**digits - epsilon
)

# Ensure nonstrict monotonicity and clips after each modification:
Expand All @@ -138,7 +138,7 @@ def modify_dframe_monotonicity(
)

# Assert that we have successfully managed to force monotonicity
allowance = 1.0 / 10.0 ** digits
allowance = 1.0 / 10.0**digits
if sign > 0:
assert not (
dframe[col].round(digits).diff() < -allowance
Expand Down Expand Up @@ -227,7 +227,7 @@ def rows_to_be_fixed(
series = pd.Series(series, dtype="float64")

# minus epsilon is critical to avoid being greedy
accuracy = 1.0 / 10.0 ** digits - epsilon
accuracy = 1.0 / 10.0**digits - epsilon
if monotonicity["sign"] > 0:
constants = series.round(digits + 1).diff() < accuracy
else:
Expand Down
2 changes: 1 addition & 1 deletion test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
autoapi
black>=20.8b0
black
flake8
hypothesis
isort
Expand Down
10 changes: 5 additions & 5 deletions tests/test_gasoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_plotting(mocker):
gasoil.plotkrgkrog(logyscale=True, mpl_ax=None)


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


@settings(deadline=500)
@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 @@ -159,7 +159,7 @@ def test_gasoil_normalization(swl, sgcr, sorg, h, tag):
assert float_df_checker(gasoil.table, "SG", gasoil.sgcr, "SGN", 0)


@settings(deadline=1000)
@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 @@ -360,7 +360,7 @@ def test_kroend():
assert gasoil.table["KROG"].max() == 0.5


@settings(deadline=1500)
@settings(deadline=2000)
@given(st.floats(), st.floats())
def test_gasoil_corey1(ng, nog):
"""Test the Corey formulation for gasoil"""
Expand Down Expand Up @@ -428,7 +428,7 @@ def test_comments():
assert "PC" in sgof


@settings(deadline=1500)
@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
8 changes: 4 additions & 4 deletions tests/test_gaswater.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_fast():
assert "krw = krg" not in sgfn # Crosspoint should not be present


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


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


@settings(deadline=1000)
@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 +140,7 @@ def test_gaswater_let1(l, e, t, krwend, krwmax):
assert len(sgfnstr) > 100


@settings(deadline=500)
@settings(deadline=2000)
@given(
st.floats(min_value=0, max_value=0.3),
st.floats(min_value=0, max_value=0.3),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_slgof.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def check_table(dframe):
assert dframe["PC"].is_monotonic_decreasing


@settings(deadline=1000)
@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
2 changes: 1 addition & 1 deletion tests/test_utils_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ 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=1000)
@settings(max_examples=40, deadline=2000)
@given(
st.floats(min_value=0, max_value=0.1), # swl
st.floats(min_value=0, max_value=0.1), # sgcr
Expand Down
7 changes: 4 additions & 3 deletions tests/test_wateroil.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ 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 @@ -54,7 +55,7 @@ def test_wateroil_tag(tag):
sat_table_str_ok(wateroil.SWFN())


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


@settings(deadline=1000)
@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 @@ -95,7 +96,7 @@ def test_wateroil_let1(l, e, t, krwend, krwmax):
assert len(swofstr) > 100


@settings(deadline=500)
@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: 2 additions & 2 deletions tests/test_wateroil_pc.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_simple_j_petro():
wateroil.add_simple_J_petro(a=1, b=2)


@settings(deadline=500)
@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 +139,7 @@ def test_normalized_j(caplog):
assert "a parameter is very high" in caplog.text


@settings(deadline=500)
@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
4 changes: 3 additions & 1 deletion tests/test_wateroil_saturation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pyscal.utils.testing import check_table, float_df_checker


@settings(deadline=2000)
@given(
st.floats(),
st.floats(),
Expand All @@ -26,6 +27,7 @@ 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 @@ -102,7 +104,7 @@ def test_wateroil_socr(socr):
check_table(wateroil.table)


@settings(deadline=1000)
@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 8459917

Please sign in to comment.