Skip to content

Commit

Permalink
finish tests on init
Browse files Browse the repository at this point in the history
  • Loading branch information
veni-vidi-vici-dormivi committed Oct 3, 2024
1 parent 55d71d3 commit fb8d7c9
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 10 deletions.
18 changes: 8 additions & 10 deletions mesmer/mesmer_x/train_l_distrib_mesmerx.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,21 +544,19 @@ def __init__(
elif isinstance(options_solver, dict):
default_options_solver.update(options_solver)
else:
raise ValueError("options_solver must be a dictionary")
raise ValueError("`options_solver` must be a dictionary")
self.xtol_req = default_options_solver["xtol_req"]
self.ftol_req = default_options_solver["ftol_req"]
self.maxiter = default_options_solver["maxiter"]
self.maxfev = default_options_solver["maxfev"]
self.method_fit = default_options_solver["method_fit"]
if self.method_fit in [
"dogleg",
"trust-ncg",
"trust-krylov",
"trust-exact",
"COBYLA",
"SLSQP",
"CG",
"Newton-CG",
if self.method_fit not in [
"BFGS",
"L-BFGS-B",
"Nelder-Mead",
"Powell",
"TNC",
"trust-constr",
]:
raise ValueError("method for this fit not prepared, to avoid")
else:
Expand Down
85 changes: 85 additions & 0 deletions tests/unit/test_mesmer_x_distrib_cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,88 @@ def test_distrib_cov_init_errors():
{"tas": np.array([1, 2, np.inf]), "tas2": np.array([1, 2, np.nan])},
expression,
)

with pytest.raises(ValueError, match="Only one of "):
distrib_cov(
np.array([1, 2, 3]),
{"tas": np.array([1, 2, 3])},
expression,
data_targ_addtest=np.array([1, 2, 3]),
)

with pytest.raises(ValueError, match="Only one of "):
distrib_cov(
np.array([1, 2, 3]),
{"tas": np.array([1, 2, 3])},
expression,
data_preds_addtest={"tas": np.array([1, 2, 3])},
)

with pytest.raises(ValueError, match="`threshold_min_proba` must be in"):
distrib_cov(
np.array([1, 2, 3]),
{"tas": np.array([1, 2, 3])},
expression,
threshold_min_proba=-1,
)
with pytest.raises(ValueError, match="`threshold_min_proba` must be in"):
distrib_cov(
np.array([1, 2, 3]),
{"tas": np.array([1, 2, 3])},
expression,
threshold_min_proba=2,
)

with pytest.raises(
ValueError, match="The provided first guess does not have the correct shape:"
):
distrib_cov(
np.array([1, 2, 3]),
{"tas": np.array([1, 2, 3])},
expression,
first_guess=np.array([1, 2, 3]),
)

with pytest.raises(ValueError, match="`options_solver` must be a dictionary"):
distrib_cov(
np.array([1, 2, 3]),
{"tas": np.array([1, 2, 3])},
expression,
options_solver="this is not a dictionary",
)

with pytest.raises(ValueError, match="`options_optim` must be a dictionary"):
distrib_cov(
np.array([1, 2, 3]),
{"tas": np.array([1, 2, 3])},
expression,
options_optim="this is not a dictionary",
)

with pytest.raises(ValueError, match="method for this fit not prepared, to avoid"):
distrib_cov(
np.array([1, 2, 3]),
{"tas": np.array([1, 2, 3])},
expression,
options_solver={"method_fit": "this is not a method"},
)

with pytest.raises(
ValueError, match="Lack of consistency on the options 'type_fun_optim'"
):
distrib_cov(
np.array([1, 2, 3]),
{"tas": np.array([1, 2, 3])},
expression,
options_optim={"type_fun_optim": "NLL", "threshold_stopping_rule": 0.1},
)

with pytest.raises(
ValueError, match="Lack of consistency on the options 'type_fun_optim'"
):
distrib_cov(
np.array([1, 2, 3]),
{"tas": np.array([1, 2, 3])},
expression,
options_optim={"type_fun_optim": "fcNLL", "threshold_stopping_rule": None},
)

0 comments on commit fb8d7c9

Please sign in to comment.