File: test_apply_function.py

package info (click to toggle)
python-mne 0.17%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 95,104 kB
  • sloc: python: 110,639; makefile: 222; sh: 15
file content (52 lines) | stat: -rw-r--r-- 1,324 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Authors: Eric Larson <larson.eric.d@gmail.com>
#
# License: BSD (3-clause)

import numpy as np
import pytest

from mne import create_info
from mne.io import RawArray
from mne.utils import logger, catch_logging, run_tests_if_main


def bad_1(x):
    """Fail."""
    return  # bad return type


def bad_2(x):
    """Fail."""
    return x[:-1]  # bad shape


def printer(x):
    """Print."""
    logger.info('exec')
    return x


@pytest.mark.slowtest
def test_apply_function_verbose():
    """Test apply function verbosity."""
    n_chan = 2
    n_times = 3
    ch_names = [str(ii) for ii in range(n_chan)]
    raw = RawArray(np.zeros((n_chan, n_times)),
                   create_info(ch_names, 1., 'mag'))
    # test return types in both code paths (parallel / 1 job)
    pytest.raises(TypeError, raw.apply_function, bad_1)
    pytest.raises(ValueError, raw.apply_function, bad_2)
    pytest.raises(TypeError, raw.apply_function, bad_1, n_jobs=2)
    pytest.raises(ValueError, raw.apply_function, bad_2, n_jobs=2)

    # check our arguments
    with catch_logging() as sio:
        out = raw.apply_function(printer, verbose=False)
        assert len(sio.getvalue()) == 0
        assert out is raw
        raw.apply_function(printer, verbose=True)
        assert sio.getvalue().count('\n') == n_chan


run_tests_if_main()