def _check_load_fold(fold_files, atlas): _validate_type(fold_files, (list, 'path-like', None), 'fold_files') if fold_files is None: fold_files = mne.get_config('MNE_NIRS_FOLD_PATH') if fold_files is None: raise ValueError( 'MNE_NIRS_FOLD_PATH not set, either set it using ' 'mne.set_config or pass fold_files as str or list') if not isinstance(fold_files, list): # path-like fold_files = _check_fname(fold_files, overwrite='read', must_exist=True, name='fold_files', need_dir=True) fold_files = [op.join(fold_files, f'10-{x}.xls') for x in (5, 10)] fold_tbl = pd.DataFrame() for fi, fname in enumerate(fold_files): fname = _check_fname(fname, overwrite='read', must_exist=True, name=f'fold_files[{fi}]') fold_tbl = pd.concat( [fold_tbl, _read_fold_xls(fname, atlas=atlas)], ignore_index=True) return fold_tbl
def test_check(): """Test checking functions.""" pytest.raises(ValueError, check_random_state, 'foo') pytest.raises(TypeError, _check_fname, 1) _check_fname(Path('./')) pytest.raises(IOError, check_fname, 'foo', 'tets-dip.x', (), ('.fif', )) pytest.raises(ValueError, _check_subject, None, None) pytest.raises(TypeError, _check_subject, None, 1) pytest.raises(TypeError, _check_subject, 1, None) # smoke tests for permitted types check_random_state(None).choice(1) check_random_state(0).choice(1) check_random_state(np.random.RandomState(0)).choice(1) if check_version('numpy', '1.17'): check_random_state(np.random.default_rng(0)).choice(1) # _meg.fif is a valid ending and should not raise an error shutil.copyfile(fname_raw, fname_raw.replace('_raw.', '_meg.')) mne.io.read_raw_fif(fname_raw.replace('_raw.', '_meg.'))
def test_check(tmpdir): """Test checking functions.""" pytest.raises(ValueError, check_random_state, 'foo') pytest.raises(TypeError, _check_fname, 1) _check_fname(Path('./')) fname = str(tmpdir.join('foo')) with open(fname, 'wb'): pass assert op.isfile(fname) _check_fname(fname, overwrite='read', must_exist=True) orig_perms = os.stat(fname).st_mode os.chmod(fname, 0) if not sys.platform.startswith('win'): with pytest.raises(PermissionError, match='read permissions'): _check_fname(fname, overwrite='read', must_exist=True) os.chmod(fname, orig_perms) os.remove(fname) assert not op.isfile(fname) pytest.raises(IOError, check_fname, 'foo', 'tets-dip.x', (), ('.fif', )) pytest.raises(ValueError, _check_subject, None, None) pytest.raises(TypeError, _check_subject, None, 1) pytest.raises(TypeError, _check_subject, 1, None) # smoke tests for permitted types check_random_state(None).choice(1) check_random_state(0).choice(1) check_random_state(np.random.RandomState(0)).choice(1) if check_version('numpy', '1.17'): check_random_state(np.random.default_rng(0)).choice(1) # _meg.fif is a valid ending and should not raise an error new_fname = str( tmpdir.join(op.basename(fname_raw).replace('_raw.', '_meg.'))) shutil.copyfile(fname_raw, new_fname) mne.io.read_raw_fif(new_fname)
def test_check(tmp_path): """Test checking functions.""" pytest.raises(ValueError, check_random_state, 'foo') pytest.raises(TypeError, _check_fname, 1) _check_fname(Path('./foo')) fname = tmp_path / 'foo' with open(fname, 'wb'): pass assert op.isfile(fname) _check_fname(fname, overwrite='read', must_exist=True) orig_perms = os.stat(fname).st_mode os.chmod(fname, 0) if not sys.platform.startswith('win'): with pytest.raises(PermissionError, match='read permissions'): _check_fname(fname, overwrite='read', must_exist=True) os.chmod(fname, orig_perms) os.remove(fname) assert not op.isfile(fname) pytest.raises(IOError, check_fname, 'foo', 'tets-dip.x', (), ('.fif', )) pytest.raises(ValueError, _check_subject, None, None) pytest.raises(TypeError, _check_subject, None, 1) pytest.raises(TypeError, _check_subject, 1, None) # smoke tests for permitted types check_random_state(None).choice(1) check_random_state(0).choice(1) check_random_state(np.random.RandomState(0)).choice(1) if check_version('numpy', '1.17'): check_random_state(np.random.default_rng(0)).choice(1)