Skip to content

Commit 6d160c3

Browse files
authored
Merge pull request #3195 from effigies/test/fixes
TEST: Clean up tests
2 parents fe15295 + e6ed8c6 commit 6d160c3

File tree

13 files changed

+62
-106
lines changed

13 files changed

+62
-106
lines changed

.travis.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
os: linux
12
dist: xenial
2-
sudo: true
33

44
language: python
55
# our build matrix
@@ -8,15 +8,13 @@ python:
88
- 3.6
99
- 3.7
1010

11-
# NOTE: Any changes to the matrix section should be duplicated below for
12-
# Python 3.4
1311
env:
1412
global:
1513
- EXTRA_WHEELS="https://5cf40426d9f06eb7461d-6fe47d9331aba7cd62fc36c7196769e4.ssl.cf2.rackcdn.com"
1614
- PRE_WHEELS="https://7933911d6844c6c53a7d-47bd50c35cd79bd838daf386af554a83.ssl.cf2.rackcdn.com"
1715
- EXTRA_PIP_FLAGS="--find-links=$EXTRA_WHEELS"
1816
- CHECK_TYPE=test
19-
matrix:
17+
jobs:
2018
- INSTALL_DEB_DEPENDECIES=true
2119
NIPYPE_EXTRAS="doc,tests,nipy,profiler"
2220
CI_SKIP_TEST=1
@@ -31,7 +29,7 @@ env:
3129
EXTRA_PIP_FLAGS="--pre $EXTRA_PIP_FLAGS --find-links $PRE_WHEELS --upgrade"
3230
CI_SKIP_TEST=1
3331

34-
matrix:
32+
jobs:
3533
include:
3634
- python: 3.7
3735
env:

nipype/__init__.py

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -83,41 +83,9 @@ def check_latest_version(raise_exception=False):
8383
import etelemetry
8484

8585
logger = logging.getLogger("nipype.utils")
86-
87-
INIT_MSG = "Running {packname} version {version} (latest: {latest})".format
88-
89-
latest = {"version": "Unknown", "bad_versions": []}
90-
result = None
91-
try:
92-
result = etelemetry.get_project("nipy/nipype")
93-
except Exception as e:
94-
logger.warning("Could not check for version updates: \n%s", e)
95-
finally:
96-
if result:
97-
latest.update(**result)
98-
if LooseVersion(__version__) != LooseVersion(latest["version"]):
99-
logger.info(
100-
INIT_MSG(
101-
packname="nipype", version=__version__, latest=latest["version"]
102-
)
103-
)
104-
else:
105-
logger.info("No new version available.")
106-
if latest["bad_versions"] and any(
107-
[
108-
LooseVersion(__version__) == LooseVersion(ver)
109-
for ver in latest["bad_versions"]
110-
]
111-
):
112-
message = (
113-
"You are using a version of Nipype with a critical "
114-
"bug. Please use a different version."
115-
)
116-
if raise_exception:
117-
raise RuntimeError(message)
118-
else:
119-
logger.critical(message)
120-
return latest
86+
return etelemetry.check_available_version(
87+
"nipy/nipype", __version__, logger, raise_exception
88+
)
12189

12290

12391
# Run telemetry on import for interactive sessions, such as IPython, Jupyter notebooks, Python REPL

nipype/algorithms/tests/test_TSNR.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import pytest
99
import numpy.testing as npt
10-
import mock
10+
from unittest import mock
1111
import nibabel as nb
1212
import numpy as np
1313
import os
@@ -16,9 +16,7 @@
1616
class TestTSNR:
1717
""" Note: Tests currently do a poor job of testing functionality """
1818

19-
in_filenames = {
20-
"in_file": "tsnrinfile.nii",
21-
}
19+
in_filenames = {"in_file": "tsnrinfile.nii"}
2220

2321
out_filenames = { # default output file names
2422
"detrended_file": "detrend.nii.gz",

nipype/info.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def get_nipype_gitversion():
148148
"simplejson>=%s" % SIMPLEJSON_MIN_VERSION,
149149
"traits>=%s,!=5.0" % TRAITS_MIN_VERSION,
150150
"filelock>=3.0.0",
151-
"etelemetry",
151+
"etelemetry>=0.2.0",
152152
]
153153

154154
# neurdflib has to come after prov
@@ -158,7 +158,6 @@ def get_nipype_gitversion():
158158
TESTS_REQUIRES = [
159159
"codecov",
160160
"coverage<5",
161-
"mock",
162161
"pytest",
163162
"pytest-cov",
164163
"pytest-env",

nipype/interfaces/fsl/tests/test_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
@pytest.mark.skipif(no_fsl(), reason="fsl is not installed")
1414
def test_fslversion():
1515
ver = fsl.Info.version()
16-
ver = ver.split(".")
17-
assert ver[0] in ["4", "5"]
16+
assert ver.split(".", 1)[0].isdigit()
1817

1918

2019
@pytest.mark.skipif(no_fsl(), reason="fsl is not installed")

nipype/pipeline/plugins/tests/test_oar.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
import os
3-
from shutil import rmtree
4-
from tempfile import mkdtemp
2+
from shutil import which
53

64
import nipype.interfaces.base as nib
75
import pytest
@@ -31,13 +29,9 @@ def _list_outputs(self):
3129
return outputs
3230

3331

34-
@pytest.mark.xfail(reason="not known")
35-
def test_run_oar():
36-
cur_dir = os.getcwd()
37-
temp_dir = mkdtemp(prefix="test_engine_", dir=os.getcwd())
38-
os.chdir(temp_dir)
39-
40-
pipe = pe.Workflow(name="pipe")
32+
@pytest.mark.skipif(which('oarsub') is None, reason="OAR not installed")
33+
def test_run_pbsgraph(tmp_path):
34+
pipe = pe.Workflow(name="pipe", base_dir=str(tmp_path))
4135
mod1 = pe.Node(interface=OarTestInterface(), name="mod1")
4236
mod2 = pe.MapNode(interface=OarTestInterface(), iterfield=["input1"], name="mod2")
4337
pipe.connect([(mod1, mod2, [("output1", "input1")])])
@@ -48,5 +42,3 @@ def test_run_oar():
4842
node = list(execgraph.nodes())[names.index("pipe.mod1")]
4943
result = node.get_output("output1")
5044
assert result == [1, 1]
51-
os.chdir(cur_dir)
52-
rmtree(temp_dir)

nipype/pipeline/plugins/tests/test_pbs.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
import os
3-
from shutil import rmtree
4-
from tempfile import mkdtemp
5-
from time import sleep
2+
from shutil import which
63

74
import nipype.interfaces.base as nib
85
import pytest
@@ -32,22 +29,15 @@ def _list_outputs(self):
3229
return outputs
3330

3431

35-
@pytest.mark.xfail(reason="not known")
36-
def test_run_pbsgraph():
37-
cur_dir = os.getcwd()
38-
temp_dir = mkdtemp(prefix="test_engine_")
39-
os.chdir(temp_dir)
40-
41-
pipe = pe.Workflow(name="pipe")
32+
@pytest.mark.skipif(which('qsub') is None, reason="PBS not installed")
33+
def test_run_pbsgraph(tmp_path):
34+
pipe = pe.Workflow(name="pipe", base_dir=str(tmp_path))
4235
mod1 = pe.Node(interface=PbsTestInterface(), name="mod1")
4336
mod2 = pe.MapNode(interface=PbsTestInterface(), iterfield=["input1"], name="mod2")
4437
pipe.connect([(mod1, mod2, [("output1", "input1")])])
45-
pipe.base_dir = os.getcwd()
4638
mod1.inputs.input1 = 1
4739
execgraph = pipe.run(plugin="PBSGraph")
4840
names = [".".join((node._hierarchy, node.name)) for node in execgraph.nodes()]
4941
node = list(execgraph.nodes())[names.index("pipe.mod1")]
5042
result = node.get_output("output1")
5143
assert result == [1, 1]
52-
os.chdir(cur_dir)
53-
rmtree(temp_dir)

nipype/pipeline/plugins/tests/test_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import scipy.sparse as ssp
88
import re
99

10-
import mock
10+
from unittest import mock
1111

1212
from nipype.pipeline.plugins.tools import report_crash
1313

nipype/testing/tests/test_utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
import os
88
import warnings
99
import subprocess
10-
from mock import patch, MagicMock
10+
from unittest.mock import patch, MagicMock
11+
from unittest import SkipTest
1112
from nipype.testing.utils import TempFATFS
1213

1314

1415
def test_tempfatfs():
1516
try:
1617
fatfs = TempFATFS()
1718
except (IOError, OSError):
18-
warnings.warn("Cannot mount FAT filesystems with FUSE")
19-
else:
20-
with fatfs as tmp_dir:
21-
assert os.path.exists(tmp_dir)
19+
raise SkipTest("Cannot mount FAT filesystems with FUSE")
20+
with fatfs as tmp_dir:
21+
assert os.path.exists(tmp_dir)
2222

2323

2424
@patch(

nipype/tests/test_nipype.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from .. import get_info
23
from ..info import get_nipype_gitversion
34
import pytest
@@ -46,26 +47,28 @@ def test_no_et(tmp_path):
4647
from nipype.interfaces import utility as niu
4748
from nipype.interfaces.base import BaseInterface
4849

50+
et = os.getenv("NIPYPE_NO_ET") is None
51+
4952
# Pytest doesn't trigger this, so let's pretend it's there
5053
with patch.object(BaseInterface, "_etelemetry_version_data", {}):
5154

5255
# Direct function call - environment not set
5356
f = niu.Function(function=_check_no_et)
5457
res = f.run()
55-
assert res.outputs.out is True
58+
assert res.outputs.out == et
5659

5760
# Basic node - environment not set
5861
n = pe.Node(
5962
niu.Function(function=_check_no_et), name="n", base_dir=str(tmp_path)
6063
)
6164
res = n.run()
62-
assert res.outputs.out is True
65+
assert res.outputs.out == et
6366

6467
# Linear run - environment not set
6568
wf1 = pe.Workflow(name="wf1", base_dir=str(tmp_path))
6669
wf1.add_nodes([pe.Node(niu.Function(function=_check_no_et), name="n")])
6770
res = wf1.run()
68-
assert next(iter(res.nodes)).result.outputs.out is True
71+
assert next(iter(res.nodes)).result.outputs.out == et
6972

7073
# MultiProc run - environment initialized with NIPYPE_NO_ET
7174
wf2 = pe.Workflow(name="wf2", base_dir=str(tmp_path))
@@ -91,9 +94,9 @@ def test_no_et(tmp_path):
9194
]
9295
)
9396
res = wf4.run(plugin="MultiProc", plugin_args={"n_procs": 1})
94-
assert next(iter(res.nodes)).result.outputs.out is True
97+
assert next(iter(res.nodes)).result.outputs.out == et
9598

96-
# LegacyMultiProc run - environment initialized with NIPYPE_NO_ET
99+
# run_without_submitting - environment not set
97100
wf5 = pe.Workflow(name="wf5", base_dir=str(tmp_path))
98101
wf5.add_nodes(
99102
[
@@ -105,4 +108,4 @@ def test_no_et(tmp_path):
105108
]
106109
)
107110
res = wf5.run(plugin="LegacyMultiProc", plugin_args={"n_procs": 1})
108-
assert next(iter(res.nodes)).result.outputs.out is True
111+
assert next(iter(res.nodes)).result.outputs.out == et

nipype/utils/tests/test_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66
import pytest
77
from nipype import config
8-
from mock import MagicMock
8+
from unittest.mock import MagicMock
99

1010
try:
1111
import xvfbwrapper

nipype/utils/tests/test_filemanip.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
# vi: set ft=python sts=4 ts=4 sw=4 et:
44
import os
55
import time
6-
import warnings
76
from pathlib import Path
87

9-
import mock
8+
from unittest import mock, SkipTest
109
import pytest
1110
from ...testing import TempFATFS
1211
from ...utils.filemanip import (
@@ -238,22 +237,22 @@ def test_copyfallback(_temp_analyze_files):
238237
try:
239238
fatfs = TempFATFS()
240239
except (IOError, OSError):
241-
warnings.warn("Fuse mount failed. copyfile fallback tests skipped.")
242-
else:
243-
with fatfs as fatdir:
244-
tgt_img = os.path.join(fatdir, imgname)
245-
tgt_hdr = os.path.join(fatdir, hdrname)
246-
for copy in (True, False):
247-
for use_hardlink in (True, False):
248-
copyfile(orig_img, tgt_img, copy=copy, use_hardlink=use_hardlink)
249-
assert os.path.exists(tgt_img)
250-
assert os.path.exists(tgt_hdr)
251-
assert not os.path.islink(tgt_img)
252-
assert not os.path.islink(tgt_hdr)
253-
assert not os.path.samefile(orig_img, tgt_img)
254-
assert not os.path.samefile(orig_hdr, tgt_hdr)
255-
os.unlink(tgt_img)
256-
os.unlink(tgt_hdr)
240+
raise SkipTest("Fuse mount failed. copyfile fallback tests skipped.")
241+
242+
with fatfs as fatdir:
243+
tgt_img = os.path.join(fatdir, imgname)
244+
tgt_hdr = os.path.join(fatdir, hdrname)
245+
for copy in (True, False):
246+
for use_hardlink in (True, False):
247+
copyfile(orig_img, tgt_img, copy=copy, use_hardlink=use_hardlink)
248+
assert os.path.exists(tgt_img)
249+
assert os.path.exists(tgt_hdr)
250+
assert not os.path.islink(tgt_img)
251+
assert not os.path.islink(tgt_hdr)
252+
assert not os.path.samefile(orig_img, tgt_img)
253+
assert not os.path.samefile(orig_hdr, tgt_hdr)
254+
os.unlink(tgt_img)
255+
os.unlink(tgt_hdr)
257256

258257

259258
def test_get_related_files(_temp_analyze_files):
@@ -295,7 +294,7 @@ def test_ensure_list(filename, expected):
295294

296295

297296
@pytest.mark.parametrize(
298-
"list, expected", [(["foo.nii"], "foo.nii"), (["foo", "bar"], ["foo", "bar"]),]
297+
"list, expected", [(["foo.nii"], "foo.nii"), (["foo", "bar"], ["foo", "bar"])]
299298
)
300299
def test_simplify_list(list, expected):
301300
x = simplify_list(list)

nipype/utils/tests/test_provenance.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
33
# vi: set ft=python sts=4 ts=4 sw=4 et:
44
import os
5+
from nibabel.optpkg import optional_package
6+
import pytest
7+
8+
_, have_rdflib5, _ = optional_package("rdflib", min_version="5.0.0")
59

610
from nipype.utils.provenance import ProvStore, safe_encode
711

12+
needs_rdflib5 = pytest.mark.skipif(
13+
not have_rdflib5, reason="Test requires rdflib 5.0.0 or higher"
14+
)
15+
816

17+
@needs_rdflib5
918
def test_provenance(tmpdir):
1019
from nipype.interfaces.base import CommandLine
1120

@@ -17,6 +26,7 @@ def test_provenance(tmpdir):
1726
assert "echo hello" in provn
1827

1928

29+
@needs_rdflib5
2030
def test_provenance_exists(tmpdir):
2131
tmpdir.chdir()
2232
from nipype import config

0 commit comments

Comments
 (0)