Skip to content
Snippets Groups Projects
Commit 04fd59e2 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

Specific tests can be excluded using markers - see setup.cfg for list

parent 022c49b0
No related branches found
No related tags found
No related merge requests found
...@@ -5,8 +5,17 @@ test=pytest ...@@ -5,8 +5,17 @@ test=pytest
universal=1 universal=1
[tool:pytest] [tool:pytest]
# Available test markers:
# - fsltest: Requires FSL
# - wxtest: Requires wxPython
# - dicomtest: Requires dcm2niix
# - meshtest: Requires trimesh and rtree
# - igziptest: Requires indexed_gzip
# - longtest: Takes a long time
#
testpaths = tests testpaths = tests
addopts = -v --niters=50 --cov=fsl addopts = -v --niters=50 --cov=fsl -m "not longtest"
[flake8] [flake8]
ignore = E127,E201,E203,E221,E222,E241,E271,E272,E301,E302,E303,E701 ignore = E127,E201,E203,E221,E222,E241,E271,E272,E301,E302,E303,E701
\ No newline at end of file
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
import os import os
import os.path as op import os.path as op
import itertools as it
import numpy as np import numpy as np
import mock import mock
...@@ -26,6 +25,9 @@ import fsl.data.image as fslimage ...@@ -26,6 +25,9 @@ import fsl.data.image as fslimage
datadir = op.join(op.dirname(__file__), 'testdata') datadir = op.join(op.dirname(__file__), 'testdata')
pytestmark = pytest.mark.fsltest
def setup_module(): def setup_module():
if os.environ.get('FSLDIR', None) is None: if os.environ.get('FSLDIR', None) is None:
raise Exception('FSLDIR is not set - atlas tests cannot be run') raise Exception('FSLDIR is not set - atlas tests cannot be run')
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
import os import os
import itertools as it import itertools as it
from collections import defaultdict
import numpy as np import numpy as np
import pytest import pytest
...@@ -20,6 +19,9 @@ import fsl.utils.cache as cache ...@@ -20,6 +19,9 @@ import fsl.utils.cache as cache
from . import (testdir, make_random_mask) from . import (testdir, make_random_mask)
pytestmark = pytest.mark.fsltest
def setup_module(): def setup_module():
if os.environ.get('FSLDIR', None) is None: if os.environ.get('FSLDIR', None) is None:
raise Exception('FSLDIR is not set - atlas tests cannot be run') raise Exception('FSLDIR is not set - atlas tests cannot be run')
......
...@@ -8,12 +8,17 @@ ...@@ -8,12 +8,17 @@
import os import os
import itertools as it import itertools as it
import pytest
import fsl.data.atlases as fslatlases import fsl.data.atlases as fslatlases
import fsl.scripts.atlasq as fslatlasq import fsl.scripts.atlasq as fslatlasq
from . import CaptureStdout from . import CaptureStdout
pytestmark = pytest.mark.fsltest
def setup_module(): def setup_module():
if os.environ.get('FSLDIR', None) is None: if os.environ.get('FSLDIR', None) is None:
raise Exception('FSLDIR is not set - atlas tests cannot be run') raise Exception('FSLDIR is not set - atlas tests cannot be run')
......
...@@ -11,6 +11,8 @@ import os.path as op ...@@ -11,6 +11,8 @@ import os.path as op
import os import os
import shlex import shlex
import pytest
import numpy as np import numpy as np
import fsl.scripts.atlasq as fslatlasq import fsl.scripts.atlasq as fslatlasq
...@@ -21,6 +23,9 @@ from . import (tempdir, ...@@ -21,6 +23,9 @@ from . import (tempdir,
CaptureStdout) CaptureStdout)
pytestmark = pytest.mark.fsltest
def setup_module(): def setup_module():
if os.environ.get('FSLDIR', None) is None: if os.environ.get('FSLDIR', None) is None:
raise Exception('FSLDIR is not set - atlas tests cannot be run') raise Exception('FSLDIR is not set - atlas tests cannot be run')
......
...@@ -10,10 +10,11 @@ import os ...@@ -10,10 +10,11 @@ import os
import os.path as op import os.path as op
import re import re
import itertools as it import itertools as it
import six
import numpy as np import numpy as np
import scipy.ndimage as ndi import scipy.ndimage as ndi
import pytest
import fsl.utils.transform as transform import fsl.utils.transform as transform
import fsl.data.atlases as fslatlases import fsl.data.atlases as fslatlases
import fsl.data.image as fslimage import fsl.data.image as fslimage
...@@ -24,6 +25,9 @@ from . import (tempdir, ...@@ -24,6 +25,9 @@ from . import (tempdir,
CaptureStdout) CaptureStdout)
pytestmark = pytest.mark.fsltest
def setup_module(): def setup_module():
if os.environ.get('FSLDIR', None) is None: if os.environ.get('FSLDIR', None) is None:
raise Exception('FSLDIR is not set - atlas tests cannot be run') raise Exception('FSLDIR is not set - atlas tests cannot be run')
......
...@@ -20,6 +20,10 @@ from fsl.utils.platform import platform as fslplatform ...@@ -20,6 +20,10 @@ from fsl.utils.platform import platform as fslplatform
import tests import tests
pytestmark = pytest.mark.fsltest
def setup_module(): def setup_module():
fsldir = os.environ.get('FSLDIR', None) fsldir = os.environ.get('FSLDIR', None)
if fsldir is None or not op.exists(fsldir): if fsldir is None or not op.exists(fsldir):
......
...@@ -18,6 +18,9 @@ import fsl.utils.tempdir as tempdir ...@@ -18,6 +18,9 @@ import fsl.utils.tempdir as tempdir
datadir = op.join(op.dirname(__file__), 'testdata') datadir = op.join(op.dirname(__file__), 'testdata')
pytestmark = pytest.mark.dicomtest
def setup_module(): def setup_module():
if not fsldcm.enabled(): if not fsldcm.enabled():
......
...@@ -18,6 +18,7 @@ import mock ...@@ -18,6 +18,7 @@ import mock
import fsl.utils.idle as idle import fsl.utils.idle as idle
from fsl.utils.platform import platform as fslplatform from fsl.utils.platform import platform as fslplatform
def _run_with_wx(func, *args, **kwargs): def _run_with_wx(func, *args, **kwargs):
gc.collect() gc.collect()
...@@ -91,6 +92,7 @@ def _wait_for_idle_loop_to_clear(): ...@@ -91,6 +92,7 @@ def _wait_for_idle_loop_to_clear():
wx.Yield() wx.Yield()
@pytest.mark.wxtest
def test_run_with_gui(): _run_with_wx( _test_run) def test_run_with_gui(): _run_with_wx( _test_run)
def test_run_without_gui(): _run_without_wx(_test_run) def test_run_without_gui(): _run_without_wx(_test_run)
def _test_run(): def _test_run():
...@@ -143,7 +145,7 @@ def _test_run(): ...@@ -143,7 +145,7 @@ def _test_run():
assert onErrorCalled[ 0] assert onErrorCalled[ 0]
@pytest.mark.wxtest
def test_idleTimeout_with_gui(): _run_with_wx( _test_idleTimeout) def test_idleTimeout_with_gui(): _run_with_wx( _test_idleTimeout)
def test_idleTimeout_without_gui(): _run_without_wx(_test_idleTimeout) def test_idleTimeout_without_gui(): _run_without_wx(_test_idleTimeout)
def _test_idleTimeout(): def _test_idleTimeout():
...@@ -155,6 +157,7 @@ def _test_idleTimeout(): ...@@ -155,6 +157,7 @@ def _test_idleTimeout():
assert idle.getIdleTimeout() == default assert idle.getIdleTimeout() == default
@pytest.mark.wxtest
def test_idle(): def test_idle():
called = [False] called = [False]
...@@ -185,6 +188,7 @@ def test_idle(): ...@@ -185,6 +188,7 @@ def test_idle():
_run_with_wx(idle.idle, errtask, 1, kwarg1=2) _run_with_wx(idle.idle, errtask, 1, kwarg1=2)
@pytest.mark.wxtest
def test_inidle(): def test_inidle():
called = [False] called = [False]
...@@ -203,6 +207,7 @@ def test_inidle(): ...@@ -203,6 +207,7 @@ def test_inidle():
assert called[0] assert called[0]
@pytest.mark.wxtest
def test_cancelidle(): def test_cancelidle():
called = [False] called = [False]
...@@ -221,6 +226,7 @@ def test_cancelidle(): ...@@ -221,6 +226,7 @@ def test_cancelidle():
assert not called[0] assert not called[0]
@pytest.mark.wxtest
def test_idle_skipIfQueued(): def test_idle_skipIfQueued():
task1called = [False] task1called = [False]
...@@ -244,6 +250,7 @@ def test_idle_skipIfQueued(): ...@@ -244,6 +250,7 @@ def test_idle_skipIfQueued():
assert not task2called[0] assert not task2called[0]
@pytest.mark.wxtest
def test_idle_dropIfQueued(): def test_idle_dropIfQueued():
task1called = [False] task1called = [False]
...@@ -278,6 +285,7 @@ def test_idle_dropIfQueued(): ...@@ -278,6 +285,7 @@ def test_idle_dropIfQueued():
assert task2called[0] assert task2called[0]
@pytest.mark.wxtest
def test_idle_alwaysQueue1(): def test_idle_alwaysQueue1():
# Test scheduling the task before # Test scheduling the task before
...@@ -304,6 +312,7 @@ def test_idle_alwaysQueue1(): ...@@ -304,6 +312,7 @@ def test_idle_alwaysQueue1():
assert called[0] assert called[0]
@pytest.mark.wxtest
def test_idle_alwaysQueue2(): def test_idle_alwaysQueue2():
# Test scheduling the task # Test scheduling the task
...@@ -323,6 +332,7 @@ def test_idle_alwaysQueue2(): ...@@ -323,6 +332,7 @@ def test_idle_alwaysQueue2():
assert called[0] assert called[0]
@pytest.mark.wxtest
def test_idle_alwaysQueue3(): def test_idle_alwaysQueue3():
# Test scheduling the task # Test scheduling the task
...@@ -343,6 +353,7 @@ def test_idle_alwaysQueue3(): ...@@ -343,6 +353,7 @@ def test_idle_alwaysQueue3():
assert called[0] assert called[0]
@pytest.mark.wxtest
def test_idle_alwaysQueue4(): def test_idle_alwaysQueue4():
# Test scheduling the task when # Test scheduling the task when
...@@ -370,6 +381,7 @@ def test_idle_alwaysQueue4(): ...@@ -370,6 +381,7 @@ def test_idle_alwaysQueue4():
assert called[0] assert called[0]
@pytest.mark.wxtest
def test_idle_timeout(): def test_idle_timeout():
called = [False] called = [False]
...@@ -382,7 +394,7 @@ def test_idle_timeout(): ...@@ -382,7 +394,7 @@ def test_idle_timeout():
assert not called[0] assert not called[0]
@pytest.mark.wxtest
def test_idleWhen(): def test_idleWhen():
called = [False] called = [False]
...@@ -403,6 +415,7 @@ def test_idleWhen(): ...@@ -403,6 +415,7 @@ def test_idleWhen():
assert timesPolled[0] == 50 assert timesPolled[0] == 50
@pytest.mark.wxtest
def test_wait_with_gui(): _run_with_wx(_test_wait, finishingDelay=1100) def test_wait_with_gui(): _run_with_wx(_test_wait, finishingDelay=1100)
def test_wait_without_gui(): _test_wait() def test_wait_without_gui(): _test_wait()
def _test_wait(): def _test_wait():
......
...@@ -9,6 +9,7 @@ import os.path as op ...@@ -9,6 +9,7 @@ import os.path as op
import time import time
import mock import mock
import pytest
import numpy as np import numpy as np
import nibabel as nib import nibabel as nib
...@@ -22,15 +23,22 @@ from . import make_random_image ...@@ -22,15 +23,22 @@ from . import make_random_image
# make sure Image(indexed=True) works # make sure Image(indexed=True) works
# even if indexed_gzip is not present # even if indexed_gzip is not present
@pytest.mark.longtest
def test_image_indexed_no_igzip_threaded(): def test_image_indexed_no_igzip_threaded():
with mock.patch.dict('sys.modules', indexed_gzip=None): with mock.patch.dict('sys.modules', indexed_gzip=None):
_test_image_indexed(True) _test_image_indexed(True)
@pytest.mark.longtest
def test_image_indexed_no_igzip_unthreaded(): def test_image_indexed_no_igzip_unthreaded():
with mock.patch.dict('sys.modules', indexed_gzip=None): with mock.patch.dict('sys.modules', indexed_gzip=None):
_test_image_indexed(False) _test_image_indexed(False)
@pytest.mark.longtest
@pytest.mark.igziptest
def test_image_indexed_threaded( ): _test_image_indexed(True) def test_image_indexed_threaded( ): _test_image_indexed(True)
@pytest.mark.longtest
@pytest.mark.igziptest
def test_image_indexed_unthreaded(): _test_image_indexed(False) def test_image_indexed_unthreaded(): _test_image_indexed(False)
def _test_image_indexed(threaded): def _test_image_indexed(threaded):
...@@ -74,8 +82,12 @@ def _test_image_indexed(threaded): ...@@ -74,8 +82,12 @@ def _test_image_indexed(threaded):
assert (end1 - start1) > (end2 - start2) assert (end1 - start1) > (end2 - start2)
@pytest.mark.longtest
@pytest.mark.igziptest
def test_image_indexed_read4D_threaded(seed): def test_image_indexed_read4D_threaded(seed):
_test_image_indexed_read4D(True) _test_image_indexed_read4D(True)
@pytest.mark.longtest
@pytest.mark.igziptest
def test_image_indexed_read4D_unthreaded(seed): def test_image_indexed_read4D_unthreaded(seed):
_test_image_indexed_read4D(False) _test_image_indexed_read4D(False)
def _test_image_indexed_read4D(threaded): def _test_image_indexed_read4D(threaded):
...@@ -115,7 +127,11 @@ def _test_image_indexed_read4D(threaded): ...@@ -115,7 +127,11 @@ def _test_image_indexed_read4D(threaded):
assert np.all(data == np.arange(nvols)) assert np.all(data == np.arange(nvols))
@pytest.mark.igziptest
@pytest.mark.longtest
def test_image_indexed_save_threaded( ): _test_image_indexed_save(True) def test_image_indexed_save_threaded( ): _test_image_indexed_save(True)
@pytest.mark.longtest
@pytest.mark.igziptest
def test_image_indexed_save_unthreaded(): _test_image_indexed_save(False) def test_image_indexed_save_unthreaded(): _test_image_indexed_save(False)
def _test_image_indexed_save(threaded): def _test_image_indexed_save(threaded):
...@@ -186,7 +202,11 @@ def _test_image_indexed_save(threaded): ...@@ -186,7 +202,11 @@ def _test_image_indexed_save(threaded):
assert np.all(img[..., 40] == 45) assert np.all(img[..., 40] == 45)
@pytest.mark.longtest
@pytest.mark.igziptest
def test_image_no_calcRange_threaded(): _test_image_no_calcRange(True) def test_image_no_calcRange_threaded(): _test_image_no_calcRange(True)
@pytest.mark.longtest
@pytest.mark.igziptest
def test_image_no_calcRange_unthreaded(): _test_image_no_calcRange(False) def test_image_no_calcRange_unthreaded(): _test_image_no_calcRange(False)
def _test_image_no_calcRange(threaded): def _test_image_no_calcRange(threaded):
...@@ -217,7 +237,11 @@ def _test_image_no_calcRange(threaded): ...@@ -217,7 +237,11 @@ def _test_image_no_calcRange(threaded):
assert img.dataRange == (0, i) assert img.dataRange == (0, i)
@pytest.mark.longtest
@pytest.mark.igziptest
def test_image_calcRange_threaded(): _test_image_calcRange(True) def test_image_calcRange_threaded(): _test_image_calcRange(True)
@pytest.mark.longtest
@pytest.mark.igziptest
def test_image_calcRange_unthreaded(): _test_image_calcRange(False) def test_image_calcRange_unthreaded(): _test_image_calcRange(False)
def _test_image_calcRange(threaded): def _test_image_calcRange(threaded):
......
...@@ -13,6 +13,7 @@ import time ...@@ -13,6 +13,7 @@ import time
import itertools as it import itertools as it
import numpy as np import numpy as np
import nibabel as nib import nibabel as nib
import pytest
import fsl.data.image as image import fsl.data.image as image
...@@ -566,12 +567,16 @@ def _ImageWraper_busy_wait(wrapper, v=0): ...@@ -566,12 +567,16 @@ def _ImageWraper_busy_wait(wrapper, v=0):
if tt is not None: if tt is not None:
tt.waitUntilIdle() tt.waitUntilIdle()
@pytest.mark.longtest
def test_ImageWrapper_read_threaded(niters, seed): def test_ImageWrapper_read_threaded(niters, seed):
_test_ImageWrapper_read(niters, seed, True) _test_ImageWrapper_read(niters, seed, True)
@pytest.mark.longtest
def test_ImageWrapper_read_unthreaded(niters, seed): def test_ImageWrapper_read_unthreaded(niters, seed):
_test_ImageWrapper_read(niters, seed, False) _test_ImageWrapper_read(niters, seed, False)
@pytest.mark.longtest
def test_ImageWrapper_read_nans_threaded(niters, seed): def test_ImageWrapper_read_nans_threaded(niters, seed):
_test_ImageWrapper_read(niters, seed, True, True) _test_ImageWrapper_read(niters, seed, True, True)
@pytest.mark.longtest
def test_ImageWrapper_read_nans_unthreaded(niters, seed): def test_ImageWrapper_read_nans_unthreaded(niters, seed):
_test_ImageWrapper_read(niters, seed, False, True) _test_ImageWrapper_read(niters, seed, False, True)
...@@ -658,9 +663,10 @@ def _test_ImageWrapper_read(niters, seed, threaded, addnans=False): ...@@ -658,9 +663,10 @@ def _test_ImageWrapper_read(niters, seed, threaded, addnans=False):
else: assert wrapper.covered else: assert wrapper.covered
@pytest.mark.longtest
def test_ImageWrapper_write_out_threaded(niters, seed): def test_ImageWrapper_write_out_threaded(niters, seed):
_test_ImageWrapper_write_out(niters, seed, True) _test_ImageWrapper_write_out(niters, seed, True)
@pytest.mark.longtest
def test_ImageWrapper_write_out_unthreaded(niters, seed): def test_ImageWrapper_write_out_unthreaded(niters, seed):
_test_ImageWrapper_write_out(niters, seed, False) _test_ImageWrapper_write_out(niters, seed, False)
def _test_ImageWrapper_write_out(niters, seed, threaded): def _test_ImageWrapper_write_out(niters, seed, threaded):
...@@ -799,8 +805,10 @@ def _test_ImageWrapper_write_out(niters, seed, threaded): ...@@ -799,8 +805,10 @@ def _test_ImageWrapper_write_out(niters, seed, threaded):
# print('--------------') # print('--------------')
@pytest.mark.longtest
def test_ImageWrapper_write_in_overlap_threaded(niters, seed): def test_ImageWrapper_write_in_overlap_threaded(niters, seed):
_test_ImageWrapper_write_in_overlap(niters, seed, True) _test_ImageWrapper_write_in_overlap(niters, seed, True)
@pytest.mark.longtest
def test_ImageWrapper_write_in_overlap_unthreaded(niters, seed): def test_ImageWrapper_write_in_overlap_unthreaded(niters, seed):
_test_ImageWrapper_write_in_overlap(niters, seed, False) _test_ImageWrapper_write_in_overlap(niters, seed, False)
def _test_ImageWrapper_write_in_overlap(niters, seed, threaded): def _test_ImageWrapper_write_in_overlap(niters, seed, threaded):
...@@ -910,8 +918,10 @@ def _test_ImageWrapper_write_in_overlap(niters, seed, threaded): ...@@ -910,8 +918,10 @@ def _test_ImageWrapper_write_in_overlap(niters, seed, threaded):
assert np.isclose(newHi, expHi) assert np.isclose(newHi, expHi)
@pytest.mark.longtest
def test_ImageWrapper_write_different_volume_threaded(niters, seed): def test_ImageWrapper_write_different_volume_threaded(niters, seed):
_test_ImageWrapper_write_different_volume(niters, seed, True) _test_ImageWrapper_write_different_volume(niters, seed, True)
@pytest.mark.longtest
def test_ImageWrapper_write_different_volume_unthreaded(niters, seed): def test_ImageWrapper_write_different_volume_unthreaded(niters, seed):
_test_ImageWrapper_write_different_volume(niters, seed, False) _test_ImageWrapper_write_different_volume(niters, seed, False)
def _test_ImageWrapper_write_different_volume(niters, seed, threaded): def _test_ImageWrapper_write_different_volume(niters, seed, threaded):
......
...@@ -279,6 +279,7 @@ def test_trimesh_no_trimesh(): ...@@ -279,6 +279,7 @@ def test_trimesh_no_trimesh():
assert faces.size == 0 assert faces.size == 0
@pytest.mark.meshtest
def test_trimesh(): def test_trimesh():
import trimesh import trimesh
...@@ -290,6 +291,7 @@ def test_trimesh(): ...@@ -290,6 +291,7 @@ def test_trimesh():
assert isinstance(mesh.trimesh, trimesh.Trimesh) assert isinstance(mesh.trimesh, trimesh.Trimesh)
@pytest.mark.meshtest
def test_rayIntersection(): def test_rayIntersection():
verts = np.array(CUBE_VERTICES) verts = np.array(CUBE_VERTICES)
...@@ -318,6 +320,7 @@ def test_rayIntersection(): ...@@ -318,6 +320,7 @@ def test_rayIntersection():
assert tri.size == 0 assert tri.size == 0
@pytest.mark.meshtest
def test_nearestVertex(): def test_nearestVertex():
verts = np.array(CUBE_VERTICES) verts = np.array(CUBE_VERTICES)
...@@ -331,6 +334,7 @@ def test_nearestVertex(): ...@@ -331,6 +334,7 @@ def test_nearestVertex():
assert np.all(np.isclose(ndists, np.sqrt(3))) assert np.all(np.isclose(ndists, np.sqrt(3)))
@pytest.mark.meshtest
def test_planeIntersection(): def test_planeIntersection():
verts = np.array(CUBE_VERTICES) verts = np.array(CUBE_VERTICES)
......
...@@ -11,6 +11,7 @@ import os.path as op ...@@ -11,6 +11,7 @@ import os.path as op
import sys import sys
import shutil import shutil
import tempfile import tempfile
import pytest
import mock import mock
...@@ -35,6 +36,7 @@ def test_atts(): ...@@ -35,6 +36,7 @@ def test_atts():
p.glIsSoftwareRenderer p.glIsSoftwareRenderer
@pytest.mark.wxtest
def test_haveGui(): def test_haveGui():
import wx import wx
...@@ -207,6 +209,7 @@ def test_detect_ssh(): ...@@ -207,6 +209,7 @@ def test_detect_ssh():
assert not p.inVNCSession assert not p.inVNCSession
@pytest.mark.wxtest
def test_IsWidgetAlive(): def test_IsWidgetAlive():
import wx import wx
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment