Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: Ensure we dont download without permission #1073

Merged
merged 12 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ jobs:
- name: Install MNE (stable)
if: "matrix.mne-version == 'mne-stable'"
run: |
git clone --depth 1 https://github.com/mne-tools/mne-python.git -b maint/1.0
git clone --depth 1 --single-branch --branch maint/1.0 https://github.com/mne-tools/mne-python.git -b maint/1.0
python -m pip install -e ./mne-python

- name: Install MNE (main)
if: "matrix.mne-version == 'mne-main'"
run: |
git clone --depth 1 https://github.com/mne-tools/mne-python.git -b main
git clone --depth 1 --single-branch --branch main https://github.com/mne-tools/mne-python.git -b main
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we keep this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's just more specific/explicit and a tiny bit faster

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but we should probably remove the trailing -b main, right? that's just a single flag specified twice?

python -m pip install -e ./mne-python

- name: Install BIDS validator (stable)
Expand Down Expand Up @@ -210,6 +210,27 @@ jobs:
- name: Install MNE-BIDS
run: python -m pip install -e .

# Only run on a limited set of jobs
- name: Run pytest without testing data
run: make test
if: ${{ matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest' && matrix.mne-version == 'mne-main' }}

# Get testing data
- run: ./tools/get_testing_version.sh
working-directory: mne-python
shell: bash
name: 'Get testing version'

- uses: actions/cache@v3
with:
key: ${{ env.TESTING_VERSION }}
path: ~/mne_data
name: 'Cache testing data'

- run: ./tools/github_actions_download.sh
shell: bash
working-directory: mne-python

- name: Run pytest
shell: bash
run: make test
Expand Down
20 changes: 10 additions & 10 deletions mne_bids/commands/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import mne

from mne.datasets import testing
from mne.utils import ArgvSetter, requires_pandas, requires_version
from mne.utils import ArgvSetter, requires_pandas
from mne.utils._testing import requires_module

from mne_bids.commands import (mne_bids_raw_to_bids,
Expand All @@ -34,7 +34,7 @@
requires_matplotlib = partial(requires_module, name='matplotlib',
call='import matplotlib')


data_path = testing.data_path(download=False)
base_path = op.join(op.dirname(mne.__file__), 'io')
subject_id = '01'
task = 'testing'
Expand All @@ -52,10 +52,10 @@ def check_usage(module, force_help=False):
assert 'Usage: ' in out.stdout.getvalue()


@testing.requires_testing_data
def test_raw_to_bids(tmp_path):
"""Test mne_bids raw_to_bids."""
output_path = str(tmp_path)
data_path = testing.data_path()
raw_fname = op.join(data_path, 'MEG', 'sample',
'sample_audvis_trunc_raw.fif')
# Check that help is printed
Expand Down Expand Up @@ -87,6 +87,7 @@ def test_raw_to_bids(tmp_path):
mne_bids_cp.run()


@testing.requires_testing_data
def test_cp(tmp_path):
"""Test mne_bids cp."""
output_path = str(tmp_path)
Expand All @@ -107,14 +108,14 @@ def test_cp(tmp_path):
mne_bids_cp.run()


@testing.requires_testing_data
def test_mark_bad_chanels_single_file(tmp_path):
"""Test mne_bids mark_channels."""
# Check that help is printed
check_usage(mne_bids_mark_channels)

# Create test dataset.
output_path = str(tmp_path)
data_path = testing.data_path()
raw_fname = op.join(data_path, 'MEG', 'sample',
'sample_audvis_trunc_raw.fif')
old_bads = mne.io.read_raw_fif(raw_fname).info['bads']
Expand Down Expand Up @@ -159,14 +160,14 @@ def test_mark_bad_chanels_single_file(tmp_path):
assert raw.info['bads'] == []


@testing.requires_testing_data
def test_mark_bad_chanels_multiple_files(tmp_path):
"""Test mne_bids mark_channels."""
# Check that help is printed
check_usage(mne_bids_mark_channels)

# Create test dataset.
output_path = str(tmp_path)
data_path = testing.data_path()
raw_fname = op.join(data_path, 'MEG', 'sample',
'sample_audvis_trunc_raw.fif')
old_bads = mne.io.read_raw_fif(raw_fname).info['bads']
Expand Down Expand Up @@ -200,13 +201,13 @@ def test_mark_bad_chanels_multiple_files(tmp_path):
assert set(old_bads + ch_names) == set(raw.info['bads'])


@testing.requires_testing_data
def test_calibration_to_bids(tmp_path):
"""Test mne_bids calibration_to_bids."""
# Check that help is printed
check_usage(mne_bids_calibration_to_bids)

output_path = str(tmp_path)
data_path = Path(testing.data_path())
fine_cal_fname = data_path / 'SSS' / 'sss_cal_mgh.dat'
bids_path = BIDSPath(subject=subject_id, root=output_path)

Expand All @@ -219,13 +220,13 @@ def test_calibration_to_bids(tmp_path):
assert bids_path.meg_calibration_fpath.exists()


@testing.requires_testing_data
def test_crosstalk_to_bids(tmp_path):
"""Test mne_bids crosstalk_to_bids."""
# Check that help is printed
check_usage(mne_bids_crosstalk_to_bids)

output_path = str(tmp_path)
data_path = Path(testing.data_path())
crosstalk_fname = data_path / 'SSS' / 'ct_sparse.fif'
bids_path = BIDSPath(subject=subject_id, root=output_path)

Expand All @@ -239,14 +240,14 @@ def test_crosstalk_to_bids(tmp_path):


@requires_pandas
@testing.requires_testing_data
def test_count_events(tmp_path):
"""Test mne_bids count_events."""
# Check that help is printed
check_usage(mne_bids_count_events)

# Create test dataset.
output_path = str(tmp_path)
data_path = testing.data_path()
raw_fname = op.join(data_path, 'MEG', 'sample',
'sample_audvis_trunc_raw.fif')

Expand Down Expand Up @@ -282,15 +283,14 @@ def test_count_events(tmp_path):


@requires_matplotlib
@requires_version('mne', '0.22')
@testing.requires_testing_data
def test_inspect(tmp_path):
"""Test mne_bids inspect."""
# Check that help is printed
check_usage(mne_bids_inspect)

# Create test dataset.
bids_root = str(tmp_path)
data_path = testing.data_path()
subject = '01'
task = 'test'
datatype = 'meg'
Expand Down
16 changes: 16 additions & 0 deletions mne_bids/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Configure all tests."""
import mne
import pytest


def pytest_configure(config):
"""Configure pytest options."""
# Fixtures
config.addinivalue_line('usefixtures', 'monkeypatch_mne')


@pytest.fixture(scope='session')
def monkeypatch_mne():
"""Monkeypatch MNE to ensure we have download=False everywhere in tests."""
mne.datasets.utils._MODULES_TO_ENSURE_DOWNLOAD_IS_FALSE_IN_TESTS = \
('mne', 'mne_bids')
3 changes: 2 additions & 1 deletion mne_bids/tests/data/tiny_bids/code/make_tiny_bids_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import mne_bids
from mne_bids import BIDSPath, write_raw_bids

data_path = mne.datasets.testing.data_path()
data_path = mne.datasets.testing.data_path(download=False)
assert mne.datasets.has_dataset('testing'), 'Download testing data'
vhdr_path = data_path / "montage" / "bv_dig_test.vhdr"
captrak_path = data_path / "montage" / "captrak_coords.bvct"

Expand Down
6 changes: 4 additions & 2 deletions mne_bids/tests/test_copyfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
copyfile_eeglab,
copyfile_kit)


testing_path = testing.data_path(download=False)
base_path = op.join(op.dirname(mne.__file__), 'io')


@testing.requires_testing_data
def test_get_brainvision_encoding():
"""Test getting the file-encoding from a BrainVision header."""
data_path = op.join(base_path, 'brainvision', 'tests', 'data')
Expand Down Expand Up @@ -195,10 +196,11 @@ def test_copyfile_edfbdf_uppercase(tmp_path):
@pytest.mark.parametrize('fname',
('test_raw.set', 'test_raw_chanloc.set',
'test_raw_2021.set'))
@testing.requires_testing_data
def test_copyfile_eeglab(tmp_path, fname):
"""Test the copying of EEGlab set and fdt files."""
bids_root = str(tmp_path)
data_path = op.join(testing.data_path(), 'EEGLAB')
data_path = op.join(testing_path, 'EEGLAB')
raw_fname = op.join(data_path, fname)
new_name = op.join(bids_root, f'CONVERTED_{fname}.set')

Expand Down
8 changes: 7 additions & 1 deletion mne_bids/tests/test_dig.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
subject=subject_id, session=session_id, run=run, acquisition=acq,
task=task)

data_path = testing.data_path()
data_path = testing.data_path(download=False)


def _load_raw():
Expand All @@ -47,6 +47,7 @@ def _load_raw():
return raw


@testing.requires_testing_data
def test_dig_io(tmp_path):
"""Test passing different coordinate frames give proper warnings."""
bids_root = tmp_path / 'bids1'
Expand Down Expand Up @@ -83,6 +84,7 @@ def test_dig_io(tmp_path):
write_raw_bids(raw, bids_path)


@testing.requires_testing_data
def test_dig_pixels(tmp_path):
"""Test dig stored correctly for the Pixels coordinate frame."""
bids_root = tmp_path / 'bids1'
Expand Down Expand Up @@ -118,6 +120,7 @@ def test_dig_pixels(tmp_path):


@pytest.mark.filterwarnings('ignore:The unit for chann*.:RuntimeWarning:mne')
@testing.requires_testing_data
def test_dig_template(tmp_path):
"""Test that eeg and ieeg dig are stored properly."""
bids_root = tmp_path / 'bids1'
Expand Down Expand Up @@ -203,6 +206,7 @@ def _test_montage_trans(raw, montage, pos_test, space='fsaverage',
np.array(list(montage_test.get_positions()['ch_pos'].values())))


@testing.requires_testing_data
def test_template_to_head():
"""Test transforming a template montage to head."""
# test no montage
Expand Down Expand Up @@ -295,6 +299,7 @@ def test_template_to_head():
coord_frame='ras', unit='auto')


@testing.requires_testing_data
def test_convert_montage():
"""Test the montage RAS conversion."""
raw = _load_raw()
Expand Down Expand Up @@ -327,6 +332,7 @@ def test_convert_montage():
[-0.0313669, 0.0540269, 0.0949191])


@testing.requires_testing_data
def test_electrodes_io(tmp_path):
"""Ensure only electrodes end up in *_electrodes.json."""
raw = _load_raw()
Expand Down
21 changes: 10 additions & 11 deletions mne_bids/tests/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import mne
from mne.datasets import testing
from mne.utils import requires_version
from mne.utils._testing import requires_module
from mne.viz.utils import _fake_click

Expand All @@ -25,11 +24,11 @@

_bids_path = BIDSPath(subject='01', session='01', run='01', task='testing',
datatype='meg')
data_path = testing.data_path(download=False)


def setup_bids_test_dir(bids_root):
"""Return path to a written test BIDS dir."""
data_path = testing.data_path()
raw_fname = op.join(data_path, 'MEG', 'sample',
'sample_audvis_trunc_raw.fif')

Expand Down Expand Up @@ -57,7 +56,7 @@ def setup_bids_test_dir(bids_root):


@requires_matplotlib
@requires_version('mne', '0.22')
@testing.requires_testing_data
@pytest.mark.parametrize('save_changes', (True, False))
@pytest.mark.filterwarnings(warning_str['channel_unit_changed'])
def test_inspect_single_file(tmp_path, save_changes):
Expand Down Expand Up @@ -105,7 +104,7 @@ def test_inspect_single_file(tmp_path, save_changes):


@requires_matplotlib
@requires_version('mne', '0.22')
@testing.requires_testing_data
@pytest.mark.filterwarnings(warning_str['channel_unit_changed'])
def test_inspect_multiple_files(tmp_path):
"""Test inspecting a dataset consisting of more than one file."""
Expand Down Expand Up @@ -134,7 +133,7 @@ def test_inspect_multiple_files(tmp_path):


@requires_matplotlib
@requires_version('mne', '0.22')
@testing.requires_testing_data
@pytest.mark.filterwarnings(warning_str['channel_unit_changed'])
def test_inspect_set_and_unset_bads(tmp_path):
"""Test marking channels as bad and later marking them as good again."""
Expand Down Expand Up @@ -216,7 +215,7 @@ def _add_annotation(raw_fig):


@requires_matplotlib
@requires_version('mne', '0.22')
@testing.requires_testing_data
@pytest.mark.filterwarnings(warning_str['channel_unit_changed'])
def test_inspect_annotations(tmp_path):
"""Test inspection of Annotations."""
Expand Down Expand Up @@ -277,7 +276,7 @@ def test_inspect_annotations(tmp_path):


@requires_matplotlib
@requires_version('mne', '0.22')
@testing.requires_testing_data
@pytest.mark.filterwarnings(warning_str['channel_unit_changed'])
def test_inspect_annotations_remove_all(tmp_path):
"""Test behavior if all Annotations are removed by the user."""
Expand Down Expand Up @@ -346,7 +345,7 @@ def test_inspect_annotations_remove_all(tmp_path):


@requires_matplotlib
@requires_version('mne', '0.22')
@testing.requires_testing_data
@pytest.mark.filterwarnings(warning_str['channel_unit_changed'])
def test_inspect_dont_show_annotations(tmp_path):
"""Test if show_annotations=False works."""
Expand All @@ -363,7 +362,7 @@ def test_inspect_dont_show_annotations(tmp_path):


@requires_matplotlib
@requires_version('mne', '0.22')
@testing.requires_testing_data
@pytest.mark.filterwarnings(warning_str['channel_unit_changed'])
def test_inspect_bads_and_annotations(tmp_path):
"""Test adding bads and Annotations in one go."""
Expand Down Expand Up @@ -406,7 +405,7 @@ def test_inspect_bads_and_annotations(tmp_path):


@requires_matplotlib
@requires_version('mne', '0.22')
@testing.requires_testing_data
@pytest.mark.parametrize('save_changes', (True, False))
@pytest.mark.filterwarnings(warning_str['channel_unit_changed'])
def test_inspect_auto_flats(tmp_path, save_changes):
Expand Down Expand Up @@ -466,7 +465,7 @@ def test_inspect_auto_flats(tmp_path, save_changes):


@requires_matplotlib
@requires_version('mne', '0.22')
@testing.requires_testing_data
@pytest.mark.parametrize(('l_freq', 'h_freq'),
[(None, None),
(1, None),
Expand Down
Loading