code: def test_thresholds(numba_conditional):
      """Test automatic threshold calculations."""
      # within subjects
      rng = np.random.RandomState(0)
      X = rng.randn(10, 1, 1) + 0.08
      want_thresh = -stats.t.ppf(0.025, len(X) - 1)
      assert 0.03 < stats.ttest_1samp(X[:, 0, 0], 0)[1] < 0.05
      my_fun = partial(ttest_1samp_no_p)
      with catch_logging() as log:
          with pytest.warns(
              RuntimeWarning, match="threshold is only valid"
          ):
              out = permutation_cluster_1samp_test(
                  X,
                  stat_fun=my_fun,
                  seed=0,
                  verbose=True,
                  out_type="mask",
              )
      log = log.getvalue()
      assert str(want_thresh)[:6] in log
      assert len(out[1]) == 1  # 1 cluster
      assert_allclose(out[2], 0.033203, atol=1e-6)
      # between subjects
      Y = rng.randn(10, 1, 1)
      Z = rng.randn(10, 1, 1) - 0.7
      X = [X, Y, Z]
      want_thresh = stats.f.ppf(
          1.0 - 0.05, 2, sum(len(a) for a in X) - len(X)
      )
      p = stats.f_oneway(*X)[1]
      assert 0.03 < p < 0.05
      my_fun = partial(f_oneway)  # just to make the check fail
      with catch_logging() as log:
          with pytest.warns(
              RuntimeWarning, match="threshold is only valid"
          ):
              out = permutation_cluster_test(
                  X,
                  tail=1,
                  stat_fun=my_fun,
                  seed=0,
                  verbose=True,
                  out_type="mask",
              )
      log = log.getvalue()
      assert str(want_thresh)[:6] in log
      assert len(out[1]) == 1  # 1 cluster
      assert_allclose(out[2], 0.041992, atol=1e-6)
      with pytest.warns(
          RuntimeWarning, match='Ignoring argument "tail"'
      ):
          permutation_cluster_test(X, tail=0, out_type="mask")
  
      # nan handling in TFCE
      X = np.repeat(X[0], 2, axis=1)
      X[:, 1] = 0
      with pytest.warns(RuntimeWarning, match="invalid value"):  # NumPy
          out = permutation_cluster_1samp_test(
              X,
              seed=0,
              threshold=dict(start=0, step=0.1),
              out_type="mask",
          )
      assert (out[2] < 0.05).any()
      assert not (out[2] < 0.05).all()
      X[:, 0] = 0
      with pytest.raises(RuntimeError, match="finite"):
          with np.errstate(invalid="ignore"):
              permutation_cluster_1samp_test(
                  X,
                  seed=0,
                  threshold=dict(start=0, step=0.1),
                  buffer_size=None,
                  out_type="mask",
              )
  
imports: import os
  from functools import partial
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_equal
  from scipy import linalg, sparse, stats
  from mne import MixedSourceEstimate, SourceEstimate, SourceSpaces, VolSourceEstimate
  from mne.stats import combine_adjacency, ttest_ind_no_p
  from mne.stats.cluster_level import f_oneway, permutation_cluster_1samp_test, permutation_cluster_test, spatio_temporal_cluster_1samp_test, spatio_temporal_cluster_test, summarize_clusters_stc, ttest_1samp_no_p
  from mne.utils import _record_warnings, catch_logging
label_desc: Use image node_id 2 for calling a global function with example usage: test_thresholds(numba_conditional) without return types