Test progressbar class.
(monkeypatch)
| 13 | |
| 14 | |
| 15 | def test_progressbar(monkeypatch): |
| 16 | """Test progressbar class.""" |
| 17 | a = np.arange(10) |
| 18 | pbar = ProgressBar(a) |
| 19 | assert a is pbar.iterable |
| 20 | assert pbar.max_value == 10 |
| 21 | |
| 22 | pbar = ProgressBar(10) |
| 23 | assert pbar.max_value == 10 |
| 24 | assert pbar.iterable is None |
| 25 | |
| 26 | # Make sure that non-iterable input raises an error |
| 27 | def iter_func(a): |
| 28 | for ii in a: |
| 29 | pass |
| 30 | |
| 31 | with pytest.raises(TypeError, match="not iterable"): |
| 32 | iter_func(pbar) |
| 33 | |
| 34 | # Make sure different progress bars can be used |
| 35 | monkeypatch.setenv("MNE_TQDM", "tqdm") |
| 36 | with catch_logging("debug") as log, ProgressBar(np.arange(3)) as pbar: |
| 37 | for p in pbar: |
| 38 | pass |
| 39 | log = log.getvalue() |
| 40 | assert "Using ProgressBar with tqdm\n" in log |
| 41 | monkeypatch.setenv("MNE_TQDM", "broken") |
| 42 | with pytest.raises(ValueError, match="Invalid value for the"): |
| 43 | ProgressBar(np.arange(3)) |
| 44 | monkeypatch.setenv("MNE_TQDM", "tqdm.broken") |
| 45 | with pytest.raises(ValueError, match="Unknown tqdm"): |
| 46 | ProgressBar(np.arange(3)) |
| 47 | # off |
| 48 | monkeypatch.setenv("MNE_TQDM", "off") |
| 49 | with catch_logging("debug") as log, ProgressBar(np.arange(3)) as pbar: |
| 50 | for p in pbar: |
| 51 | pass |
| 52 | log = log.getvalue() |
| 53 | assert "Using ProgressBar with off\n" == log |
| 54 | |
| 55 | |
| 56 | def _identity(x): |
nothing calls this directly
no test coverage detected