def test_manifest_check_download(tmpdir, n_have, monkeypatch): """Test our manifest downloader.""" pooch = _soft_import('pooch', 'download datasets') monkeypatch.setattr(pooch, 'retrieve', _fake_zip_fetch) destination = op.join(str(tmpdir), 'empty') manifest_path = op.join(str(tmpdir), 'manifest.txt') with open(manifest_path, 'w') as fid: for fname in _zip_fnames: fid.write('%s\n' % fname) assert n_have in range(len(_zip_fnames) + 1) assert not op.isdir(destination) if n_have > 0: os.makedirs(op.join(destination, 'foo')) assert op.isdir(op.join(destination, 'foo')) for fname in _zip_fnames: assert not op.isfile(op.join(destination, fname)) for fname in _zip_fnames[:n_have]: with open(op.join(destination, fname), 'w'): pass with catch_logging() as log: with use_log_level(True): # we mock the pooch.retrieve so these are not used url = hash_ = '' _manifest_check_download(manifest_path, destination, url, hash_) log = log.getvalue() n_missing = 3 - n_have assert ('%d file%s missing from' % (n_missing, _pl(n_missing))) in log for want in ('Extracting missing', 'Successfully '): if n_missing > 0: assert want in log else: assert want not in log assert op.isdir(destination) for fname in _zip_fnames: assert op.isfile(op.join(destination, fname))
import shutil import zipfile import numpy as np import pytest from mne.io.constants import (FIFF, FWD, _coord_frame_named, _ch_kind_named, _ch_unit_named, _ch_unit_mul_named, _ch_coil_type_named, _dig_kind_named, _dig_cardinal_named) from mne.forward._make_forward import _read_coil_defs from mne.utils import requires_good_network from mne.utils.check import _soft_import # import pooch library for handling the dataset downloading pooch = _soft_import('pooch', 'dataset downloading', strict=True) # https://github.com/mne-tools/fiff-constants/commits/master REPO = 'mne-tools' COMMIT = 'aae5960007ee8a67dfc07535ea37d421d37dfe1b' # These are oddities that we won't address: iod_dups = (355, 359) # these are in both MEGIN and MNE files tag_dups = (3501, ) # in both MEGIN and MNE files _dir_ignore_names = ( 'clear', 'copy', 'fromkeys', 'get', 'items',