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) assert_raises(TypeError, raw.apply_function, bad_1, None, None, 1) assert_raises(ValueError, raw.apply_function, bad_2, None, None, 1) assert_raises(TypeError, raw.apply_function, bad_1, None, None, 2) assert_raises(ValueError, raw.apply_function, bad_2, None, None, 2) # check our arguments tempdir = _TempDir() test_name = op.join(tempdir, 'test.log') set_log_file(test_name) try: raw.apply_function(printer, None, None, 1, verbose=False) with open(test_name) as fid: assert_equal(len(fid.readlines()), 0) raw.apply_function(printer, None, None, 1, verbose=True) with open(test_name) as fid: assert_equal(len(fid.readlines()), n_chan) finally: set_log_file(None)
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) assert_raises(TypeError, raw.apply_function, bad_1, None, None, 1) assert_raises(ValueError, raw.apply_function, bad_2, None, None, 1) assert_raises(TypeError, raw.apply_function, bad_1, None, None, 2) assert_raises(ValueError, raw.apply_function, bad_2, None, None, 2) # check our arguments with catch_logging() as sio: raw.apply_function(printer, None, None, 1, verbose=False) assert_equal(len(sio.getvalue()), 0) raw.apply_function(printer, None, None, 1, verbose=True) assert_equal(sio.getvalue().count('\n'), n_chan)
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
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) with pytest.raises(TypeError, match='Return value must be an ndarray'): raw.apply_function(bad_1) with pytest.raises(ValueError, match='Return data must have shape'): raw.apply_function(bad_2) with pytest.raises(TypeError, match='Return value must be an ndarray'): raw.apply_function(bad_1, n_jobs=2) with pytest.raises(ValueError, match='Return data must have shape'): raw.apply_function(bad_2, n_jobs=2) # test return type when `channel_wise=False` raw.apply_function(printer, channel_wise=False) with pytest.raises(TypeError, match='Return value must be an ndarray'): raw.apply_function(bad_1, channel_wise=False) with pytest.raises(ValueError, match='Return data must have shape'): raw.apply_function(bad_3, channel_wise=False) # check our arguments with catch_logging() as sio: out = raw.apply_function(printer, verbose=False) assert len(sio.getvalue(close=False)) == 0 assert out is raw raw.apply_function(printer, verbose=True) assert sio.getvalue().count('\n') == n_chan