Exemple #1
0
def test_sleep_physionet_age(physionet_tmpdir, monkeypatch, download_is_error):
    """Test Sleep Physionet URL handling."""
    # check download_is_error patching
    with pytest.raises(AssertionError, match='Test should not download'):
        age.fetch_data(subjects=[0], recording=[1], path=physionet_tmpdir)
    # then patch
    my_func = _FakeFetch()
    monkeypatch.setattr(pooch, 'retrieve', my_func)

    paths = age.fetch_data(subjects=[0], recording=[1], path=physionet_tmpdir)
    assert_array_equal(_keep_basename_only(paths),
                       [['SC4001E0-PSG.edf', 'SC4001EC-Hypnogram.edf']])

    paths = age.fetch_data(subjects=[0, 1],
                           recording=[1],
                           path=physionet_tmpdir)
    assert_array_equal(_keep_basename_only(paths),
                       [['SC4001E0-PSG.edf', 'SC4001EC-Hypnogram.edf'],
                        ['SC4011E0-PSG.edf', 'SC4011EH-Hypnogram.edf']])

    paths = age.fetch_data(subjects=[0],
                           recording=[1, 2],
                           path=physionet_tmpdir)
    assert_array_equal(_keep_basename_only(paths),
                       [['SC4001E0-PSG.edf', 'SC4001EC-Hypnogram.edf'],
                        ['SC4002E0-PSG.edf', 'SC4002EC-Hypnogram.edf']])

    EXPECTED_CALLS = ({
        'name': 'SC4001E0-PSG.edf',
        'hash': 'adabd3b01fc7bb75c523a974f38ee3ae4e57b40f'
    }, {
        'name': 'SC4001EC-Hypnogram.edf',
        'hash': '21c998eadc8b1e3ea6727d3585186b8f76e7e70b'
    }, {
        'name': 'SC4001E0-PSG.edf',
        'hash': 'adabd3b01fc7bb75c523a974f38ee3ae4e57b40f'
    }, {
        'name': 'SC4001EC-Hypnogram.edf',
        'hash': '21c998eadc8b1e3ea6727d3585186b8f76e7e70b'
    }, {
        'name': 'SC4011E0-PSG.edf',
        'hash': '4d17451f7847355bcab17584de05e7e1df58c660'
    }, {
        'name': 'SC4011EH-Hypnogram.edf',
        'hash': 'd582a3cbe2db481a362af890bc5a2f5ca7c878dc'
    }, {
        'name': 'SC4001E0-PSG.edf',
        'hash': 'adabd3b01fc7bb75c523a974f38ee3ae4e57b40f'
    }, {
        'name': 'SC4001EC-Hypnogram.edf',
        'hash': '21c998eadc8b1e3ea6727d3585186b8f76e7e70b'
    }, {
        'name': 'SC4002E0-PSG.edf',
        'hash': 'c6b6d7a8605cc7e7602b6028ee77f6fbf5f7581d'
    }, {
        'name': 'SC4002EC-Hypnogram.edf',
        'hash': '386230188a3552b1fc90bba0fb7476ceaca174b6'
    })
    base_path = age.data_path(path=physionet_tmpdir)
    _check_mocked_function_calls(my_func, EXPECTED_CALLS, base_path)
Exemple #2
0
def test_sleep_physionet_age(physionet_tmpdir, mocker):
    """Test Sleep Physionet URL handling."""
    my_func = mocker.patch('mne.datasets.sleep_physionet._utils._fetch_file',
                           side_effect=_fake_fetch_file)

    params = {'path': physionet_tmpdir, 'update_path': False}

    with pytest.raises(ValueError, match='Only subjects 0 to 19 are'):
        paths = age.fetch_data(subjects=[20], recording=[1], **params)

    paths = age.fetch_data(subjects=[0], recording=[1], **params)
    assert_array_equal(_keep_basename_only(paths),
                       [['SC4001E0-PSG.edf', 'SC4001EC-Hypnogram.edf']])

    paths = age.fetch_data(subjects=[0, 1], recording=[1], **params)
    assert_array_equal(_keep_basename_only(paths),
                       [['SC4001E0-PSG.edf', 'SC4001EC-Hypnogram.edf'],
                        ['SC4011E0-PSG.edf', 'SC4011EH-Hypnogram.edf']])

    paths = age.fetch_data(subjects=[0], recording=[1, 2], **params)
    assert_array_equal(_keep_basename_only(paths),
                       [['SC4001E0-PSG.edf', 'SC4001EC-Hypnogram.edf'],
                        ['SC4002E0-PSG.edf', 'SC4002EC-Hypnogram.edf']])

    EXPECTED_CALLS = ({
        'name': 'SC4001E0-PSG.edf',
        'hash': 'adabd3b01fc7bb75c523a974f38ee3ae4e57b40f'
    }, {
        'name': 'SC4001EC-Hypnogram.edf',
        'hash': '21c998eadc8b1e3ea6727d3585186b8f76e7e70b'
    }, {
        'name': 'SC4001E0-PSG.edf',
        'hash': 'adabd3b01fc7bb75c523a974f38ee3ae4e57b40f'
    }, {
        'name': 'SC4001EC-Hypnogram.edf',
        'hash': '21c998eadc8b1e3ea6727d3585186b8f76e7e70b'
    }, {
        'name': 'SC4011E0-PSG.edf',
        'hash': '4d17451f7847355bcab17584de05e7e1df58c660'
    }, {
        'name': 'SC4011EH-Hypnogram.edf',
        'hash': 'd582a3cbe2db481a362af890bc5a2f5ca7c878dc'
    }, {
        'name': 'SC4001E0-PSG.edf',
        'hash': 'adabd3b01fc7bb75c523a974f38ee3ae4e57b40f'
    }, {
        'name': 'SC4001EC-Hypnogram.edf',
        'hash': '21c998eadc8b1e3ea6727d3585186b8f76e7e70b'
    }, {
        'name': 'SC4002E0-PSG.edf',
        'hash': 'c6b6d7a8605cc7e7602b6028ee77f6fbf5f7581d'
    }, {
        'name': 'SC4002EC-Hypnogram.edf',
        'hash': '386230188a3552b1fc90bba0fb7476ceaca174b6'
    })
    base_path = age.data_path(path=physionet_tmpdir)
    _check_mocked_function_calls(mocked_func=my_func,
                                 call_fname_hash_pairs=EXPECTED_CALLS,
                                 base_path=base_path)
def test_sleep_physionet_age(physionet_tmpdir, mocker):
    """Test Sleep Physionet URL handling."""
    my_func = mocker.patch('mne.datasets.sleep_physionet._utils._fetch_file',
                           side_effect=_fake_fetch_file)

    params = {'path': physionet_tmpdir, 'update_path': False}

    with pytest.raises(ValueError, match='Only subjects 0 to 19 are'):
        paths = age.fetch_data(subjects=[20], recording=[1], **params)

    paths = age.fetch_data(subjects=[0], recording=[1], **params)
    assert_array_equal(_keep_basename_only(paths),
                       [['SC4001E0-PSG.edf', 'SC4001EC-Hypnogram.edf']])

    paths = age.fetch_data(subjects=[0, 1], recording=[1], **params)
    assert_array_equal(_keep_basename_only(paths),
                       [['SC4001E0-PSG.edf', 'SC4001EC-Hypnogram.edf'],
                        ['SC4011E0-PSG.edf', 'SC4011EH-Hypnogram.edf']])

    paths = age.fetch_data(subjects=[0], recording=[1, 2], **params)
    assert_array_equal(_keep_basename_only(paths),
                       [['SC4001E0-PSG.edf', 'SC4001EC-Hypnogram.edf'],
                        ['SC4002E0-PSG.edf', 'SC4002EC-Hypnogram.edf']])

    EXPECTED_CALLS = (
        {'name': 'SC4001E0-PSG.edf',
         'hash': 'adabd3b01fc7bb75c523a974f38ee3ae4e57b40f'},
        {'name': 'SC4001EC-Hypnogram.edf',
         'hash': '21c998eadc8b1e3ea6727d3585186b8f76e7e70b'},
        {'name': 'SC4001E0-PSG.edf',
         'hash': 'adabd3b01fc7bb75c523a974f38ee3ae4e57b40f'},
        {'name': 'SC4001EC-Hypnogram.edf',
         'hash': '21c998eadc8b1e3ea6727d3585186b8f76e7e70b'},
        {'name': 'SC4011E0-PSG.edf',
         'hash': '4d17451f7847355bcab17584de05e7e1df58c660'},
        {'name': 'SC4011EH-Hypnogram.edf',
         'hash': 'd582a3cbe2db481a362af890bc5a2f5ca7c878dc'},
        {'name': 'SC4001E0-PSG.edf',
         'hash': 'adabd3b01fc7bb75c523a974f38ee3ae4e57b40f'},
        {'name': 'SC4001EC-Hypnogram.edf',
         'hash': '21c998eadc8b1e3ea6727d3585186b8f76e7e70b'},
        {'name': 'SC4002E0-PSG.edf',
         'hash': 'c6b6d7a8605cc7e7602b6028ee77f6fbf5f7581d'},
        {'name': 'SC4002EC-Hypnogram.edf',
         'hash': '386230188a3552b1fc90bba0fb7476ceaca174b6'})
    base_path = age.data_path(path=physionet_tmpdir)
    _check_mocked_function_calls(mocked_func=my_func,
                                 call_fname_hash_pairs=EXPECTED_CALLS,
                                 base_path=base_path)