Skip to content

Commit

Permalink
Merge pull request #74 from bcipolli/fix_coverage
Browse files Browse the repository at this point in the history
TST: fix coverage
  • Loading branch information
bcipolli committed Dec 30, 2015
2 parents 354d21f + 0425e10 commit eba467f
Show file tree
Hide file tree
Showing 25 changed files with 101 additions and 157 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Expand Up @@ -10,4 +10,5 @@ omit =
nidata/*/*/tests.py
nidata/core/_utils/niimg.py
nidata/core/_utils/numpy_conversions.py
nidata/core/_utils/testing.py
nidata/core/fetchers/http_fetcher.py
7 changes: 5 additions & 2 deletions .travis.yml
Expand Up @@ -15,7 +15,7 @@ notifications:

before_install:
# Setup anaconda
- pip install -U --upgrade pip
- pip install --upgrade pip
- wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh
- chmod +x miniconda.sh
- ./miniconda.sh -b
Expand All @@ -27,7 +27,9 @@ install: # Install packages
- echo $PATH
- echo $PYTHONPATH
- conda install --yes python=$TRAVIS_PYTHON_VERSION numpy h5py scipy virtualenv
- pip install nose setuptools pep8 pyflakes coverage python-coveralls nose-cov
- pip install --upgrade pip setuptools
- pip install nose pep8 pyflakes
- pip install coverage==3.7.1 python-coveralls nose-cov
- pip install profilehooks
- python setup.py install

Expand All @@ -38,3 +40,4 @@ script: # Run test

after_success: # Calculate coverage
- coveralls

8 changes: 2 additions & 6 deletions nidata/anatomical/oasis_vbm/tests.py
Expand Up @@ -2,14 +2,10 @@
from unittest import TestCase

from nidata.anatomical import OasisVbmDataset
from nidata.core._utils.testing import DownloadTestMixin, InstallTestMixin
from nidata.core._utils.testing import InstallThenDownloadTestMixin


class OasisVbmDownloadTest(DownloadTestMixin, TestCase):
dataset_class = OasisVbmDataset


class OasisVbmInstallTest(InstallTestMixin, TestCase):
class OasisVbmTest(InstallThenDownloadTestMixin, TestCase):
dataset_class = OasisVbmDataset

def test_doc(self):
Expand Down
9 changes: 3 additions & 6 deletions nidata/atlas/craddock_2012/tests.py
@@ -1,11 +1,8 @@
from unittest import TestCase
from nidata.atlas import Craddock2012Dataset
from nidata.core._utils.testing import DownloadTestMixin, InstallTestMixin


class Craddock2012DownloadTest(DownloadTestMixin, TestCase):
dataset_class = Craddock2012Dataset
from nidata.atlas import Craddock2012Dataset
from nidata.core._utils.testing import InstallThenDownloadTestMixin


class Craddock2012InstallTest(InstallTestMixin, TestCase):
class Craddock2012Test(InstallThenDownloadTestMixin, TestCase):
dataset_class = Craddock2012Dataset
11 changes: 4 additions & 7 deletions nidata/atlas/harvard_oxford/tests.py
@@ -1,15 +1,12 @@
from unittest import TestCase

from nidata.atlas import HarvardOxfordDataset
from nidata.core._utils.testing import DownloadTestMixin, InstallTestMixin
from nidata.core._utils.testing import InstallThenDownloadTestMixin


class HarvardOxfordDownloadTest(DownloadTestMixin, TestCase):
class HarvardOxfordTest(InstallThenDownloadTestMixin, TestCase):
dataset_class = HarvardOxfordDataset

def fetch(self, atlas_name='cort-maxprob-thr0-1mm', *args, **kwargs):
super(HarvardOxfordDownloadTest, self).fetch(
super(HarvardOxfordTest, self).fetch(
atlas_name=atlas_name, *args, **kwargs)


class HarvardOxfordInstallTest(InstallTestMixin, TestCase):
dataset_class = HarvardOxfordDataset
9 changes: 3 additions & 6 deletions nidata/atlas/icbm152_2009/tests.py
@@ -1,11 +1,8 @@
from unittest import TestCase
from nidata.atlas import ICBM152Dataset
from nidata.core._utils.testing import DownloadTestMixin, InstallTestMixin


class ICBM152DownloadTest(DownloadTestMixin, TestCase):
dataset_class = ICBM152Dataset
from nidata.atlas import ICBM152Dataset
from nidata.core._utils.testing import InstallThenDownloadTestMixin


class ICBM152InstallTest(InstallTestMixin, TestCase):
class ICBM152Test(InstallThenDownloadTestMixin, TestCase):
dataset_class = ICBM152Dataset
9 changes: 3 additions & 6 deletions nidata/atlas/mni152_template/tests.py
@@ -1,11 +1,8 @@
from unittest import TestCase
from nidata.atlas import MNI152Dataset
from nidata.core._utils.testing import DownloadTestMixin, InstallTestMixin


class MNI152DownloadTest(DownloadTestMixin, TestCase):
dataset_class = MNI152Dataset
from nidata.atlas import MNI152Dataset
from nidata.core._utils.testing import InstallThenDownloadTestMixin


class MNI152InstallTest(InstallTestMixin, TestCase):
class MNI152Test(InstallThenDownloadTestMixin, TestCase):
dataset_class = MNI152Dataset
9 changes: 3 additions & 6 deletions nidata/atlas/power_2011/tests.py
@@ -1,11 +1,8 @@
from unittest import TestCase
from nidata.atlas import Power2011Dataset
from nidata.core._utils.testing import DownloadTestMixin, InstallTestMixin


class Power2011DownloadTest(DownloadTestMixin, TestCase):
dataset_class = Power2011Dataset
from nidata.atlas import Power2011Dataset
from nidata.core._utils.testing import InstallThenDownloadTestMixin


class Power2011InstallTest(InstallTestMixin, TestCase):
class Power2011Test(InstallThenDownloadTestMixin, TestCase):
dataset_class = Power2011Dataset
9 changes: 3 additions & 6 deletions nidata/atlas/smith_2009/tests.py
@@ -1,11 +1,8 @@
from unittest import TestCase
from nidata.atlas import Smith2009Dataset
from nidata.core._utils.testing import DownloadTestMixin, InstallTestMixin


class Smith2009DownloadTest(DownloadTestMixin, TestCase):
dataset_class = Smith2009Dataset
from nidata.atlas import Smith2009Dataset
from nidata.core._utils.testing import InstallThenDownloadTestMixin


class Smith2009InstallTest(InstallTestMixin, TestCase):
class Smith2009Test(InstallThenDownloadTestMixin, TestCase):
dataset_class = Smith2009Dataset
9 changes: 3 additions & 6 deletions nidata/atlas/yeo_2011/tests.py
@@ -1,11 +1,8 @@
from unittest import TestCase
from nidata.atlas import Yeo2011Dataset
from nidata.core._utils.testing import DownloadTestMixin, InstallTestMixin


class Yeo2011DownloadTest(DownloadTestMixin, TestCase):
dataset_class = Yeo2011Dataset
from nidata.atlas import Yeo2011Dataset
from nidata.core._utils.testing import InstallThenDownloadTestMixin


class Yeo2011InstallTest(InstallTestMixin, TestCase):
class Yeo2011Test(InstallThenDownloadTestMixin, TestCase):
dataset_class = Yeo2011Dataset
30 changes: 25 additions & 5 deletions nidata/core/_utils/testing.py
Expand Up @@ -87,16 +87,17 @@ def setUp(self):
self.tmp_dir = tempfile.mkdtemp()
self.data_dir = op.join(self.tmp_dir,
op.basename(tempfile.mkstemp()[1]))
missing_dependencies = self.dataset_class.get_missing_dependencies()
if len(missing_dependencies) > 0:
raise SkipTest('Missing dependencies: %s' % (
','.join(self.dataset_class.dependencies)))

def tearDown(self):
if op.exists(self.data_dir):
shutil.rmtree(self.data_dir)

def fetch(self, *args, **kwargs):
missing_dependencies = self.dataset_class.get_missing_dependencies()
if len(missing_dependencies) > 0:
raise SkipTest('Missing dependencies: %s' % (
','.join(self.dataset_class.dependencies)))

dset = self.dataset_class(data_dir=self.data_dir)

# Replace the fetcher (or fetch function itself)
Expand All @@ -108,7 +109,7 @@ def fetch(self, *args, **kwargs):
dset.fetch = instancemethod(func, dset)
else:
func = func.__func__
dset.fetch = instancemethod(func, dset, dset.__class)
dset.fetch = instancemethod(func, dset, dset.__class__)
else:
instancemethod = dset.fetcher.fetch.__class__
func = _DummyFetcher.fetch
Expand Down Expand Up @@ -219,6 +220,25 @@ def test_install(self):
','.join(self.dataset_class.get_missing_dependencies()))


class InstallThenDownloadTestMixin(InstallTestMixin, DownloadTestMixin):
def setUp(self):
InstallTestMixin.setUp(self)

# Instantiate the object to trigger the install.
self.dataset_class()

DownloadTestMixin.setUp(self)

def tearDown(self):
DownloadTestMixin.tearDown(self)
InstallTestMixin.tearDown(self)

def test_install(self):
# check dependencies now!
assert_equal(0, len(self.dataset_class.get_missing_dependencies()),
','.join(self.dataset_class.get_missing_dependencies()))


@contextlib.contextmanager
def write_tmp_imgs(*imgs, **kwargs):
"""Context manager for writing Nifti images.
Expand Down
37 changes: 0 additions & 37 deletions nidata/core/_utils/threads.py

This file was deleted.

7 changes: 5 additions & 2 deletions nidata/core/datasets/__init__.py
Expand Up @@ -5,7 +5,6 @@
import inspect
import os
import os.path as op
import warnings

from six import with_metaclass

Expand Down Expand Up @@ -127,7 +126,6 @@ def get_dataset_descr(cls):
with open(rst_path) as fp:
return fp.read()
except IOError:
warnings.warn("Could not find dataset description: %s" % rst_path)
return ''

def __init__(self, data_dir=None):
Expand Down Expand Up @@ -210,11 +208,16 @@ class NilearnDataset(FetcherFunctionDataset):

@classmethod
def get_dataset_descr_path(cls):
# Grab it from nilearn.
import nilearn.datasets.description as descr
class_path = op.dirname(inspect.getfile(cls))
name = getattr(cls, 'nilearn_name', op.basename(class_path))
descr_path = op.dirname(descr.__file__)
cls.rst_path = op.join(descr_path, '%s.rst' % name)

# ...or locally.
if not op.exists(cls.rst_path):
cls.rst_path = FetcherFunctionDataset.get_dataset_descr_path()
return cls.rst_path


Expand Down
2 changes: 1 addition & 1 deletion nidata/core/objdep.py
Expand Up @@ -19,7 +19,7 @@ def install_dependency(module_name, install_info=None, verify=False):
# Install it.
try:
print("Installing %s from %s..." % (module_name, install_info))
rv = pip.main(['install', install_info])
rv = pip.main(['install', '-q', install_info])
if rv != 0:
warnings.warn('Pip returned %d' % rv)
except Exception as ex:
Expand Down
11 changes: 4 additions & 7 deletions nidata/localizer/brainomics/tests.py
@@ -1,15 +1,12 @@
from unittest import TestCase

from nidata.localizer import BrainomicsDataset
from nidata.core._utils.testing import DownloadTestMixin, InstallTestMixin
from nidata.core._utils.testing import InstallThenDownloadTestMixin


class BrainomicsDownloadTest(DownloadTestMixin, TestCase):
class BrainomicsTest(InstallThenDownloadTestMixin, TestCase):
dataset_class = BrainomicsDataset

def fetch(self, contrasts=('checkerboard',), *args, **kwargs):
super(BrainomicsDownloadTest, self).fetch(
super(BrainomicsTest, self).fetch(
contrasts=contrasts, *args, **kwargs)


class BrainomicsTest(InstallTestMixin, TestCase):
dataset_class = BrainomicsDataset
2 changes: 1 addition & 1 deletion nidata/multimodal/hcp/tests.py
Expand Up @@ -5,7 +5,7 @@
from unittest import TestCase

from nidata.multimodal import HcpDataset
from nidata.core._utils.testing import DownloadTestMixin, InstallTestMixin
from nidata.core._utils.testing import (DownloadTestMixin, InstallTestMixin)


@unittest.skipIf(os.environ.get('NIDATA_HCP_USERNAME') is None,
Expand Down
9 changes: 3 additions & 6 deletions nidata/multimodal/my_connectome_2015/tests.py
@@ -1,11 +1,8 @@
from unittest import TestCase
from nidata.multimodal import MyConnectome2015Dataset
from nidata.core._utils.testing import DownloadTestMixin, InstallTestMixin


class MyConnectomeDownloadTest(DownloadTestMixin, TestCase):
dataset_class = MyConnectome2015Dataset
from nidata.multimodal import MyConnectome2015Dataset
from nidata.core._utils.testing import InstallThenDownloadTestMixin


class MyConnectomeInstallTest(InstallTestMixin, TestCase):
class MyConnectome2015Test(InstallThenDownloadTestMixin, TestCase):
dataset_class = MyConnectome2015Dataset
9 changes: 3 additions & 6 deletions nidata/resting_state/ABIDE_pcp/tests.py
@@ -1,11 +1,8 @@
from unittest import TestCase
from nidata.resting_state import AbidePcpDataset
from nidata.core._utils.testing import DownloadTestMixin, InstallTestMixin


class AbidePcpDownloadTest(DownloadTestMixin, TestCase):
dataset_class = AbidePcpDataset
from nidata.resting_state import AbidePcpDataset
from nidata.core._utils.testing import InstallThenDownloadTestMixin


class AbidePcpInstallTest(InstallTestMixin, TestCase):
class AbidePcpTest(InstallThenDownloadTestMixin, TestCase):
dataset_class = AbidePcpDataset
9 changes: 3 additions & 6 deletions nidata/resting_state/adhd/tests.py
@@ -1,11 +1,8 @@
from nidata.resting_state import AdhdRestDataset
from unittest import TestCase
from nidata.core._utils.testing import DownloadTestMixin, InstallTestMixin


class AdhdRestDownloadTest(DownloadTestMixin, TestCase):
dataset_class = AdhdRestDataset
from nidata.resting_state import AdhdRestDataset
from nidata.core._utils.testing import InstallThenDownloadTestMixin


class AdhdRestInstallTest(InstallTestMixin, TestCase):
class AdhdRestTest(InstallThenDownloadTestMixin, TestCase):
dataset_class = AdhdRestDataset
9 changes: 3 additions & 6 deletions nidata/resting_state/nyu/tests.py
@@ -1,11 +1,8 @@
from unittest import TestCase
from nidata.resting_state import NyuRestDataset
from nidata.core._utils.testing import DownloadTestMixin, InstallTestMixin


class NyuRestDownloadTest(DownloadTestMixin, TestCase):
dataset_class = NyuRestDataset
from nidata.resting_state import NyuRestDataset
from nidata.core._utils.testing import InstallThenDownloadTestMixin


class NyuRestInstallTest(InstallTestMixin, TestCase):
class NyuRestTest(InstallThenDownloadTestMixin, TestCase):
dataset_class = NyuRestDataset
9 changes: 3 additions & 6 deletions nidata/task/haxby_etal_2001/tests.py
@@ -1,11 +1,8 @@
from unittest import TestCase
from nidata.task import Haxby2001Dataset
from nidata.core._utils.testing import DownloadTestMixin, InstallTestMixin


class Haxby2001DownloadTest(DownloadTestMixin, TestCase):
dataset_class = Haxby2001Dataset
from nidata.task import Haxby2001Dataset
from nidata.core._utils.testing import InstallThenDownloadTestMixin


class Haxby2001InstallTest(InstallTestMixin, TestCase):
class Haxby2001Test(InstallThenDownloadTestMixin, TestCase):
dataset_class = Haxby2001Dataset

0 comments on commit eba467f

Please sign in to comment.