MCPcopy
hub / github.com/mne-tools/mne-python / test_progressbar_parallel_more

Function test_progressbar_parallel_more

mne/utils/tests/test_progressbar.py:107–130  ·  view source on GitHub ↗

Test ProgressBar with parallel computing, advanced version.

(capsys)

Source from the content-addressed store, hash-verified

105
106
107def test_progressbar_parallel_more(capsys):
108 """Test ProgressBar with parallel computing, advanced version."""
109 assert capsys.readouterr().out == ""
110 # This must be "1" because "capsys" won't get stdout properly otherwise
111 parallel, p_fun, _ = parallel_func(_identity_block_wide, n_jobs=1, verbose=False)
112 arr = np.arange(10)
113 with use_log_level(True):
114 with ProgressBar(len(arr) * 2) as pb:
115 out = parallel(
116 p_fun(x, pb.subset(pb_idx))
117 for pb_idx, x in array_split_idx(arr, 2, n_per_split=2)
118 )
119 idxs = np.concatenate([o[1] for o in out])
120 assert_array_equal(idxs, np.arange(len(arr) * 2))
121 out = np.concatenate([o[0] for o in out])
122 assert Path(pb._mmap_fname).is_file()
123 sum_ = np.memmap(
124 pb._mmap_fname, dtype="bool", mode="r", shape=len(arr) * 2
125 ).sum()
126 assert sum_ == len(arr) * 2
127 assert not Path(pb._mmap_fname).is_file(), "__exit__ not called?"
128 cap = capsys.readouterr()
129 out = cap.err
130 assert "100%" in out

Callers

nothing calls this directly

Calls 6

parallel_funcFunction · 0.90
use_log_levelClass · 0.90
ProgressBarClass · 0.90
array_split_idxFunction · 0.90
subsetMethod · 0.80
sumMethod · 0.45

Tested by

no test coverage detected