Skip to content

Commit

Permalink
MRG, ENH: Modernize tests (#29)
Browse files Browse the repository at this point in the history
* ENH: Modernize tests

* FIX: Modernize travis

* FIX: Flake
  • Loading branch information
larsoner committed May 17, 2019
1 parent afe4a64 commit 6440770
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 214 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
.DS_Store
build
*.orig
junit-results.xml
133 changes: 15 additions & 118 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,125 +1,22 @@
language: python

# Use container-based infrastructure
sudo: false

env:
# Enable python 2 and python 3 builds
# DEPS=full: build optional dependencies: pandas, nitime, statsmodels,
# scikit-learn, patsy, nibabel pillow;
# in the case of Python 2, also mayavi, traits, pysurfer
# DEPS=minimal: don't build optional dependencies; tests that require those
# dependencies are supposed to be skipped
#
# Note that we don't run coverage on Py3k anyway because it slows our tests
# by a factor of 2 (!), so we make this our "from install dir" run.
#
# Run one test (3.5) with a non-default stim channel to make sure our
# tests are explicit about channels.
#
# Must force libpng version to avoid silly libpng.so.15 error (MPL 1.1 needs it)
#
# Conda currently has packaging bug with mayavi/traits/numpy where 1.10 can't be used
# but breaks sklearn on install; hopefully eventually the NUMPY=1.9 on 2.7 full can be removed
- PYTHON=2.7 TEST_LOCATION=src NUMPY="=1.9" SCIPY="=0.17"
- PYTHON=2.7 TEST_LOCATION=install NUMPY="=1.9" SCIPY="=0.17"
- PYTHON=3.5 TEST_LOCATION=src

# Setup anaconda
global: CONDA_DEPENDENCIES="numpy scipy matplotlib scikit-learn h5py pillow pytest pytest-cov coverage"
PIP_DEPENDENCIES="pytest-sugar pytest-faulthandler joblib nibabel flake8 coveralls https://api.github.com/repos/mne-tools/mne-python/zipball/master"
MNE_LOGGING_LEVEL="warning"
matrix:
include:
- env: PYTHON_VERSION=3.6
- env: PYTHON_VERSION=3.7
before_install:
- wget -q http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh
- chmod +x miniconda.sh
- ./miniconda.sh -b -p /home/travis/miniconda
- export PATH=/home/travis/miniconda/bin:$PATH
- conda update --yes --quiet conda
# We need to create a (fake) display on Travis (allows Mayavi tests to run)
- export DISPLAY=:99.0
- /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 1400x900x24 -ac +extension GLX +render -noreset

- git clone https://github.com/astropy/ci-helpers.git
- source ci-helpers/travis/setup_conda.sh
install:
- conda create -n testenv --yes pip python=$PYTHON
- source activate testenv
- ENSURE_PACKAGES="numpy$NUMPY scipy$SCIPY matplotlib$MPL libpng$LIBPNG"
- conda install --yes --quiet $ENSURE_PACKAGES nose coverage
# We have to replicate e.g. numpy$NUMPY to ensure the recommended (higher) versions
# are not automatically installed below with multiple "conda install" calls!
- curl https://staff.washington.edu/larsoner/minimal_cmds.tar.gz | tar xz;
- export MNE_ROOT="${PWD}/minimal_cmds";
- export NEUROMAG2FT_ROOT="${PWD}/minimal_cmds/bin";
- source ${MNE_ROOT}/bin/mne_setup_sh;
- conda install --yes --quiet $ENSURE_PACKAGES pandas$PANDAS scikit-learn$SKLEARN patsy h5py pillow;
- pip install -q joblib nibabel;
- if [ "${PYTHON}" == "3.5" ]; then
conda install --yes --quiet $ENSURE_PACKAGES ipython;
else
conda install --yes --quiet $ENSURE_PACKAGES ipython==1.1.0 statsmodels pandas$PANDAS;
pip install -q nitime;
if [ "${PYTHON}" == "2.7" ]; then
conda install --yes --quiet $ENSURE_PACKAGES mayavi traits;
pip install -q pysurfer faulthandler;
fi;
fi;
- pip install -q flake8;
- pip install -q coveralls nose-timer
# check our versions for the major packages
- NP_VERSION=`python -c 'import numpy; print(numpy.__version__)'`
- if [ -n "$NUMPY" ] && [ "${NUMPY:(-3)}" != "${NP_VERSION::3}" ]; then
echo "Incorrect numpy version $NP_VERSION";
exit 1;
fi;
- SP_VERSION=`python -c 'import scipy; print(scipy.__version__)'`
- if [ -n "$SCIPY" ] && [ "${SCIPY:(-4)}" != "${SP_VERSION::4}" ]; then
echo "Incorrect scipy version $SP_VERSION";
exit 1;
fi;
- MPL_VERSION=`python -c 'import matplotlib; print(matplotlib.__version__)'`
- if [ -n "$MPL" ] && [ "${MPL:(-3)}" != "${MPL_VERSION::3}" ]; then
echo "Incorrect matplotlib version $MPL_VERSION";
exit 1;
fi;
# Install latest snapshot of MNE-Python
- pip install -q https://github.com/mne-tools/mne-python/archive/master.zip
# Suppress the parallel outputs for logging cleanliness
- export MNE_LOGGING_LEVEL=warning
- python setup.py build
# Use PIP to install, so setuptools does not produce a binary egg
- pip install .
- SRC_DIR=$(pwd)
- cd ~
# Trigger download of testing data. Note that
# the testing dataset has been constructed to contain the necessary
# files to act as a FREESURFER_HOME for the coreg tests
- python -c 'import mne; mne.datasets.testing.data_path(verbose=True)';
export FREESURFER_HOME=$(python -c 'import mne; print(mne.datasets.testing.data_path())');
- MNE_DIR=$(python -c 'import mne;print(mne.__path__[0])')
- MNE_SANDBOX_DIR=$(python -c 'import mne_sandbox;print(mne_sandbox.__path__[0])')
# We run two versions: one out of the source directory (that makes
# coveralls coverage work), and one out of the install directory (that
# ensures we have included all necessary files).
- if [ "${TEST_LOCATION}" == "install" ]; then
ln -s ${SRC_DIR}/setup.cfg ${MNE_SANDBOX_DIR}/../setup.cfg;
ln -s ${SRC_DIR}/.coveragerc ${MNE_SANDBOX_DIR}/../.coveragerc;
cd ${MNE_SANDBOX_DIR}/../;
else
cd ${SRC_DIR};
fi;
- if [ "${PYTHON}" != "3.5" ]; then
COVERAGE=--with-coverage;
else
COVERAGE=;
fi;

- pip install -e .
- python -c "import mne; mne.sys_info()"
- python -c 'import mne; mne.datasets.testing.data_path(verbose=True)'
script:
- nosetests -a '!ultra_slow_test' --with-timer --timer-top-n 30 --verbosity=2 $COVERAGE mne_sandbox
- if [ "${TEST_LOCATION}" != "install" ]; then
make flake;
fi;

- pytest mne_sandbox
- make flake
after_success:
# Need to run from source dir to exectue "git" commands
# Coverage not collected for 3.5, so don't report it
- if [ "${TEST_LOCATION}" == "src" ] && [ "${PYTHON}" != "3.5" ]; then
echo "Running coveralls";
cd ${SRC_DIR};
coveralls;
fi;
- coveralls
7 changes: 5 additions & 2 deletions mne_sandbox/connectivity/cfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import mne
import warnings

if not callable(peak_finder):
peak_finder = peak_finder.peak_finder # old MNE


# Supported PAC functions
_pac_funcs = ['plv', 'glm', 'mi_tort', 'mi_canolty', 'ozkurt', 'otc']
Expand Down Expand Up @@ -486,7 +489,7 @@ def phase_locked_amplitude(inst, freqs_phase, freqs_amp, ix_ph, ix_amp,
band_ph = band_ph.mean(0)

# Find peaks in the phase for time-locking
phase_peaks, vals = peak_finder.peak_finder(angle_ph)
phase_peaks, vals = peak_finder(angle_ph)
ixmin, ixmax = [t * sfreq for t in [tmin, tmax]]
# Remove peaks w/o buffer
phase_peaks = phase_peaks[(phase_peaks > np.abs(ixmin)) *
Expand Down Expand Up @@ -645,7 +648,7 @@ def _band_pass_pac(x, f_range, sfreq=1000, n_cycles=3):
if np.any(np.array(f_range) < 0):
raise ValueError('Filter frequencies must be positive.')

n_taps = np.floor(n_cycles * sfreq / f_range[0])
n_taps = int(np.floor(n_cycles * sfreq / f_range[0]))
if len(x) < n_taps:
raise RuntimeError(
'Length of filter is longer than data. '
Expand Down
Loading

0 comments on commit 6440770

Please sign in to comment.