Skip to content

Commit d869747

Browse files
committed
Refactor kwargs validation tests based on feedback
Address review feedback from OriolAbril on PR arviz-devs#314: - Only test accessor methods that accept **kwargs - Use pytest.mark.parametrize to reduce test duplication - Remove test docstrings (test names are self-explanatory) - Use importorskip pattern for minimal environment support - Use datatree fixture from conftest.py instead of redefining - Remove INVESTIGATION_SUMMARY.md from repository - Import numpy at module level instead of inside test functions - Follow the same pattern as tests in PR arviz-devs#143 The parametrized test covers 20 accessor methods, with 3 additional tests for methods that require positional arguments before **kwargs. All 23 tests pass successfully.
1 parent e46fc07 commit d869747

3 files changed

Lines changed: 40 additions & 345 deletions

File tree

INVESTIGATION_SUMMARY.md

Lines changed: 0 additions & 71 deletions
This file was deleted.

tests/base/test_stats.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,46 @@ def test_extra_kwargs_raise(centered_eight, func):
7272
getattr(accessor, func)(dims="draw")
7373

7474

75+
@pytest.mark.parametrize(
76+
"func",
77+
(
78+
"ess",
79+
"rhat",
80+
"rhat_nested",
81+
"mcse",
82+
"qds",
83+
"get_bins",
84+
"compute_ranks",
85+
"ecdf",
86+
"pareto_min_ss",
87+
"psislw",
88+
"bfmi",
89+
"pareto_khat",
90+
"loo_expectation",
91+
"loo_quantile",
92+
"power_scale_lw",
93+
"power_scale_sense",
94+
"autocorr",
95+
"mean",
96+
"median",
97+
"mode",
98+
),
99+
)
100+
def test_accessor_kwargs_raise(datatree, func):
101+
accessor = datatree.posterior.dataset.azstats
102+
with pytest.raises(TypeError, match=".*unexpected keyword argument.*"):
103+
getattr(accessor, func)(invalid_kwarg="value")
104+
105+
106+
@pytest.mark.parametrize("func", ("loo_score", "loo_pit", "loo_r2"))
107+
def test_loo_accessor_kwargs_raise(datatree, func):
108+
rng = np.random.default_rng()
109+
y_obs = xr.DataArray(rng.normal(size=8))
110+
accessor = datatree.posterior.dataset.azstats
111+
with pytest.raises(TypeError, match=".*unexpected keyword argument.*"):
112+
getattr(accessor, func)(y_obs, invalid_kwarg="value")
113+
114+
75115
def test_hdi_idata(centered_eight):
76116
accessor = centered_eight.posterior.ds.azstats
77117
result = accessor.hdi()

tests/test_kwargs_validation.py

Lines changed: 0 additions & 274 deletions
This file was deleted.

0 commit comments

Comments
 (0)