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

[ENH] differential testing for CI tests #435

Merged
merged 6 commits into from
Jul 27, 2024
Merged
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
5 changes: 5 additions & 0 deletions skpro/benchmarking/tests/test_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from skpro.benchmarking.evaluate import evaluate
from skpro.metrics import CRPS, EmpiricalCoverage, LogLoss, PinballLoss
from skpro.regression.residual import ResidualDouble
from skpro.tests.test_switch import run_test_module_changed
from skpro.utils.validation._dependencies import _check_soft_dependencies


Expand Down Expand Up @@ -70,6 +71,10 @@ def _get_pred_method(scoring):
METRICS = [CRPS, EmpiricalCoverage, LogLoss, PinballLoss]


@pytest.mark.skipif(
not run_test_module_changed(["skpro.benchmarking", "skpro.metrics"]),
reason="Test only if skpro.benchmarking or skpro.metrics has been changed",
)
@pytest.mark.parametrize("cv", CVs)
@pytest.mark.parametrize("scoring", METRICS)
@pytest.mark.parametrize("backend", [None, "dask", "loky", "threading"])
Expand Down
26 changes: 26 additions & 0 deletions skpro/datatypes/tests/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
__author__ = ["fkiraly"]

import numpy as np
import pytest

from skpro.datatypes._check import (
AMBIGUOUS_MTYPES,
Expand All @@ -14,6 +15,7 @@
from skpro.datatypes._check import scitype as infer_scitype
from skpro.datatypes._examples import get_examples
from skpro.datatypes._registry import SCITYPE_LIST, scitype_to_mtype
from skpro.tests.test_switch import run_test_module_changed

SCITYPES = SCITYPE_LIST

Expand Down Expand Up @@ -104,6 +106,10 @@ def pytest_generate_tests(metafunc):
metafunc.parametrize("scitype,mtype", keys, ids=ids)


@pytest.mark.skipif(
not run_test_module_changed("skpro.datatypes"),
reason="Test only if skpro.datatypes has been changed",
)
def test_check_positive(scitype, mtype, fixture_index):
"""Tests that check_is_mtype correctly confirms the mtype of examples.

Expand Down Expand Up @@ -152,6 +158,10 @@ def test_check_positive(scitype, mtype, fixture_index):
assert check_result[0], msg


@pytest.mark.skipif(
not run_test_module_changed("skpro.datatypes"),
reason="Test only if skpro.datatypes has been changed",
)
def test_check_positive_check_scitype(scitype, mtype, fixture_index):
"""Tests that check_is_scitype correctly confirms the scitype of examples.

Expand Down Expand Up @@ -201,6 +211,10 @@ def test_check_positive_check_scitype(scitype, mtype, fixture_index):
assert check_result[2]["mtype"] == mtype


@pytest.mark.skipif(
not run_test_module_changed("skpro.datatypes"),
reason="Test only if skpro.datatypes has been changed",
)
def test_check_metadata_inference(scitype, mtype, fixture_index):
"""Tests that check_is_mtype correctly infers metadata of examples.

Expand Down Expand Up @@ -304,6 +318,10 @@ def test_check_metadata_inference(scitype, mtype, fixture_index):
assert metadata[metadata_key] == expected_metadata[metadata_key], msg


@pytest.mark.skipif(
not run_test_module_changed("skpro.datatypes"),
reason="Test only if skpro.datatypes has been changed",
)
def test_check_negative(scitype, mtype):
"""Tests that check_is_mtype correctly identifies wrong mtypes of examples.

Expand Down Expand Up @@ -369,6 +387,10 @@ def test_check_negative(scitype, mtype):
)


@pytest.mark.skipif(
not run_test_module_changed("skpro.datatypes"),
reason="Test only if skpro.datatypes has been changed",
)
def test_mtype_infer(scitype, mtype, fixture_index):
"""Tests that mtype correctly infers the mtype of examples.

Expand Down Expand Up @@ -417,6 +439,10 @@ def test_mtype_infer(scitype, mtype, fixture_index):
SCITYPES_FOR_INFER_TEST = list(set(SCITYPE_LIST).difference(SKIP_SCITYPES))


@pytest.mark.skipif(
not run_test_module_changed("skpro.datatypes"),
reason="Test only if skpro.datatypes has been changed",
)
def test_scitype_infer(scitype, mtype, fixture_index):
"""Tests that scitype correctly infers the mtype of examples.

Expand Down
7 changes: 7 additions & 0 deletions skpro/datatypes/tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

__author__ = ["fkiraly"]

import pytest

from skpro.datatypes import SCITYPE_REGISTER, scitype_to_mtype
from skpro.datatypes._convert import _conversions_defined, convert
from skpro.datatypes._examples import get_examples
from skpro.tests.test_switch import run_test_module_changed
from skpro.utils import deep_equals

SCITYPES = [sci[0] for sci in SCITYPE_REGISTER]
Expand Down Expand Up @@ -71,6 +74,10 @@ def pytest_generate_tests(metafunc):
metafunc.parametrize("scitype,from_mtype,to_mtype,fixture_index", keys, ids=ids)


@pytest.mark.skipif(
not run_test_module_changed(["skpro.datatypes", "skpro.utils"]),
reason="Test only if skpro.datatypes has been changed",
)
def test_convert(scitype, from_mtype, to_mtype, fixture_index):
"""Tests that conversions for scitype agree with from/to example fixtures.

Expand Down
15 changes: 15 additions & 0 deletions skpro/datatypes/tests/test_convert_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

__author__ = ["fkiraly"]

import pytest

from skpro.datatypes._convert import convert_to
from skpro.datatypes._examples import get_examples
from skpro.tests.test_switch import run_test_module_changed
from skpro.utils import deep_equals

# hard-coded scitypes/mtypes to use in test_convert_to
Expand All @@ -13,6 +16,10 @@
MTYPES_TABLE = ["list_of_dict", "pd_Series_Table", "numpy2D"]


@pytest.mark.skipif(
not run_test_module_changed(["skpro.datatypes", "skpro.utils"]),
reason="Test only if skpro.datatypes has been changed",
)
def test_convert_to_simple():
"""Testing convert_to basic call works."""
scitype = SCITYPES[0]
Expand All @@ -29,6 +36,10 @@ def test_convert_to_simple():
assert deep_equals(converted, exp_fixt), msg


@pytest.mark.skipif(
not run_test_module_changed(["skpro.datatypes", "skpro.utils"]),
reason="Test only if skpro.datatypes has been changed",
)
def test_convert_to_without_scitype():
"""Testing convert_to call without scitype specification."""
scitype = SCITYPES[0]
Expand All @@ -45,6 +56,10 @@ def test_convert_to_without_scitype():
assert deep_equals(converted, exp_fixt), msg


@pytest.mark.skipif(
not run_test_module_changed(["skpro.datatypes", "skpro.utils"]),
reason="Test only if skpro.datatypes has been changed",
)
def test_convert_to_mtype_list():
"""Testing convert_to call to_type being a list, of same scitype."""
# convert_to list
Expand Down
13 changes: 13 additions & 0 deletions skpro/datatypes/tests/test_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
mtype_to_scitype,
scitype_to_mtype,
)
from skpro.tests.test_switch import run_test_module_changed
from skpro.utils.validation._dependencies import _check_soft_dependencies

MTYPE_SCITYPE_PAIRS = [(k[0], k[1]) for k in MTYPE_REGISTER]


@pytest.mark.skipif(
not run_test_module_changed("skpro.datatypes"),
reason="Test only if skpro.datatypes has been changed",
)
@pytest.mark.parametrize("mtype, scitype", MTYPE_SCITYPE_PAIRS)
def test_mtype_to_scitype(mtype, scitype):
"""Tests that mtype_to_scitype yields the correct output for a string.
Expand All @@ -37,6 +42,10 @@ def test_mtype_to_scitype(mtype, scitype):
assert result == scitype, msg


@pytest.mark.skipif(
not run_test_module_changed("skpro.datatypes"),
reason="Test only if skpro.datatypes has been changed",
)
def test_mtype_to_scitype_list():
"""Tests that mtype_to_scitype yields the correct output for a list.

Expand All @@ -60,6 +69,10 @@ def test_mtype_to_scitype_list():
assert result == expected_scitype_list, msg


@pytest.mark.skipif(
not run_test_module_changed("skpro.datatypes"),
reason="Test only if skpro.datatypes has been changed",
)
@pytest.mark.parametrize("mtype, scitype", MTYPE_SCITYPE_PAIRS)
def test_scitype_to_mtype(mtype, scitype):
"""Tests that scitype_to_mtype yields the correct output for a string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from sklearn.datasets import load_diabetes
from sklearn.model_selection import train_test_split

from skpro.tests.test_switch import run_test_module_changed
from skpro.utils.validation._dependencies import _check_soft_dependencies

if _check_soft_dependencies(["polars", "pyarrow"], severity="none"):
Expand Down Expand Up @@ -53,7 +54,8 @@ def polars_load_diabetes_polars(polars_load_diabetes_pandas):


@pytest.mark.skipif(
not _check_soft_dependencies(["polars", "pyarrow"], severity="none"),
not run_test_module_changed("skpro.datatypes")
or not _check_soft_dependencies(["polars", "pyarrow"], severity="none"),
reason="skip test if polars/pyarrow is not installed in environment",
)
def test_polars_eager_conversion_methods(
Expand All @@ -76,7 +78,8 @@ def test_polars_eager_conversion_methods(


@pytest.mark.skipif(
not _check_soft_dependencies(["polars", "pyarrow"], severity="none"),
not run_test_module_changed("skpro.datatypes")
or not _check_soft_dependencies(["polars", "pyarrow"], severity="none"),
reason="skip test if polars/pyarrow is not installed in environment",
)
def test_polars_eager_regressor_in_fit_predict(
Expand Down Expand Up @@ -112,7 +115,8 @@ def test_polars_eager_regressor_in_fit_predict(


@pytest.mark.skipif(
not _check_soft_dependencies(["polars", "pyarrow"], severity="none"),
not run_test_module_changed("skpro.datatypes")
or not _check_soft_dependencies(["polars", "pyarrow"], severity="none"),
reason="skip test if polars/pyarrow is not installed in environment",
)
def test_polars_eager_regressor_in_predict_interval(
Expand All @@ -129,7 +133,8 @@ def test_polars_eager_regressor_in_predict_interval(


@pytest.mark.skipif(
not _check_soft_dependencies(["polars", "pyarrow"], severity="none"),
not run_test_module_changed("skpro.datatypes")
or not _check_soft_dependencies(["polars", "pyarrow"], severity="none"),
reason="skip test if polars/pyarrow is not installed in environment",
)
def test_polars_eager_regressor_in_predict_quantiles(
Expand Down
6 changes: 6 additions & 0 deletions skpro/distributions/tests/test_base_default_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

import numpy as np
import pandas as pd
import pytest
from scipy.special import erfinv

from skpro.distributions.base import BaseDistribution
from skpro.tests.test_switch import run_test_module_changed
from skpro.utils.estimator_checks import check_estimator


Expand Down Expand Up @@ -92,6 +94,10 @@ def get_test_params(cls, parameter_set="default"):
return [params1, params2, params3]


@pytest.mark.skipif(
not run_test_module_changed("skpro.distributions"),
reason="run only if skpro.distributions has been changed",
)
def test_base_default():
"""Test default methods.

Expand Down
10 changes: 10 additions & 0 deletions skpro/distributions/tests/test_base_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@

import numpy as np
import pandas as pd
import pytest

from skpro.distributions.normal import Normal
from skpro.tests.test_switch import run_test_module_changed


@pytest.mark.skipif(
not run_test_module_changed("skpro.distributions"),
reason="run only if skpro.distributions has been changed",
)
def test_scalar_distribution():
"""Test scalar distribution logic."""
# test params
Expand Down Expand Up @@ -47,6 +53,10 @@ def test_scalar_distribution():
assert spl_mult.index.equals(pd.RangeIndex(5))


@pytest.mark.skipif(
not run_test_module_changed("skpro.distributions"),
reason="run only if skpro.distributions has been changed",
)
def test_broadcast_ambiguous():
"""Test broadcasting in cases of ambiguous parameter dimensions."""
mu = [1]
Expand Down
6 changes: 6 additions & 0 deletions skpro/distributions/tests/test_empirical.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
"""Tests for Empirical distributions."""

import pandas as pd
import pytest

from skpro.distributions.empirical import Empirical
from skpro.tests.test_switch import run_test_module_changed


@pytest.mark.skipif(
not run_test_module_changed("skpro.distributions"),
reason="run only if skpro.distributions has been changed",
)
def test_empirical_iat_index():
"""Test that the index is correctly set after iat call."""
spl_idx = pd.MultiIndex.from_product([[0, 1], [0, 1, 2]], names=["sample", "time"])
Expand Down
5 changes: 5 additions & 0 deletions skpro/distributions/tests/test_proba_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
import pandas as pd
import pytest

from skpro.tests.test_switch import run_test_module_changed
from skpro.utils.validation._dependencies import _check_soft_dependencies


@pytest.mark.skipif(
not run_test_module_changed("skpro.distributions"),
reason="run only if skpro.distributions has been changed",
)
def test_proba_example():
"""Test one subsetting case for BaseDistribution."""
from skpro.distributions.normal import Normal
Expand Down
4 changes: 4 additions & 0 deletions skpro/distributions/tests/test_qpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def test_qpd_b_simple_use():
qpd.mean()


@pytest.mark.skipif(
not run_test_for_class(QPD_B),
reason="run test only if softdeps are present and incrementally (if requested)", #
)
def test_qpd_b_pdf():
"""Test pdf of qpd with bounded mode."""
# these parameters should produce a uniform on -0.5, 0.5
Expand Down
Loading
Loading