Skip to content

Commit

Permalink
👔 Only decorate for pytest if we're in a testing environment
Browse files Browse the repository at this point in the history
  • Loading branch information
shnizzedy committed Jun 21, 2023
1 parent 1fe1499 commit 26a1cc1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
13 changes: 6 additions & 7 deletions CPAC/generate_motion_statistics/generate_motion_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
from typing import Optional
import numpy as np
import nibabel as nb
#import pytest
from CPAC.pipeline import nipype_pipeline_engine as pe
from nipype.interfaces.afni.base import (AFNICommand, AFNICommandInputSpec)
from nipype.interfaces.base import (TraitedSpec, traits, File)
import nipype.interfaces.utility as util
from CPAC.pipeline import nipype_pipeline_engine as pe
from CPAC.utils.interfaces.function import Function

from nipype.interfaces.afni.base import (AFNICommand, AFNICommandInputSpec)
from nipype.interfaces.base import (TraitedSpec, traits, isdefined, File)
from CPAC.utils.pytest import skipif


def motion_power_statistics(name='motion_stats',
Expand Down Expand Up @@ -352,8 +351,8 @@ def calculate_FD_P(in_file):
return out_file


#@pytest.mark.skipif(sys.version_info < (3, 10),
# reason="Test requires Python 3.10 or higher")
@skipif(sys.version_info < (3, 10),
reason="Test requires Python 3.10 or higher")
def calculate_FD_J(in_file: str, calc_from: Literal['affine', 'rms'],
center: Optional[np.ndarray] = None) -> str:
"""
Expand Down
32 changes: 32 additions & 0 deletions CPAC/utils/pytest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (C) 2023 C-PAC Developers

# This file is part of C-PAC.

# C-PAC is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.

# C-PAC is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with C-PAC. If not, see <https://www.gnu.org/licenses/>.
"""Utilities for Pytest integration"""
try:
import pytest
HAVE_PYTEST = True
except ImportError:
HAVE_PYTEST = False


def skipif(condition, reason):
"""Skip test if we have Pytest, ignore test entirely if not"""
def decorator(func):
"""Skip test if we have Pytest"""
if HAVE_PYTEST:
return pytest.mark.skipif(condition, reason)(func)
return func # return undecorated function
return decorator # return conditionally decorated function

0 comments on commit 26a1cc1

Please sign in to comment.