KamitaniLab / bdpy

Python package for brain decoding analysis (BrainDecoderToolbox2 data format, machine learning analysis, functional MRI)
MIT License
33 stars 22 forks source link

Test codes depend on external files #52

Closed ganow closed 8 months ago

ganow commented 1 year ago

Here is the result of the test codes. Maybe it would be great if we isolate test cases from external files. We can use mock datasets, for example, https://pypi.org/project/pytest-mock/

$ pytest .
============================= test session starts ==============================
platform linux -- Python 3.8.16, pytest-7.2.2, pluggy-1.0.0
rootdir: /workspaces/bdpy
plugins: anyio-3.6.2
collected 98 items

test/test_bdata.py ...........                                           [ 11%]
test/test_bdata_metadata.py ........                                     [ 19%]
test/test_bdata_utils.py ............                                    [ 31%]
test/test_cv.py ..                                                       [ 33%]
test/test_dataform_sparse.py F..                                         [ 36%]
test/test_distcomp.py ..                                                 [ 38%]
test/test_evals.py FF..                                                  [ 42%]
test/test_feature.py ..                                                  [ 44%]
test/test_featureselector.py ........                                    [ 53%]
test/test_ml.py FFFFFF....                                               [ 63%]
test/test_ml_utils.py ......                                             [ 69%]
test/test_mri.py EEE                                                     [ 72%]
test/test_preproc.py ........                                            [ 80%]
test/test_stats.py ...........                                           [ 91%]
test/test_util.py ......                                                 [ 97%]
test/test_util_math.py ..                                                [100%]

==================================== ERRORS ====================================
_____________ ERROR at setup of TestMri.test_add_load_epi_pass0001 _____________

file_like = './data/mri/epi.mat', appendmat = True, mode = 'rb'

    def _open_file(file_like, appendmat, mode='rb'):
        """
        Open `file_like` and return as file-like object. First, check if object is
        already file-like; if so, return it as-is. Otherwise, try to pass it
        to open(). If that fails, and `file_like` is a string, and `appendmat` is true,
        append '.mat' and try again.
        """
        reqs = {'read'} if set(mode) & set('r+') else set()
        if set(mode) & set('wax+'):
            reqs.add('write')
        if reqs.issubset(dir(file_like)):
            return file_like, False

        try:
>           return open(file_like, mode), True
E           FileNotFoundError: [Errno 2] No such file or directory: './data/mri/epi.mat'

.venv/lib/python3.8/site-packages/scipy/io/matlab/_mio.py:39: FileNotFoundError

During handling of the above exception, another exception occurred:

self = <test_mri.TestMri testMethod=test_add_load_epi_pass0001>
args = ('test_add_load_epi_pass0001',), kwargs = {}

    def __init__(self, *args, **kwargs):

        super(TestMri, self).__init__(*args, **kwargs)

        self.data_dir = './data/mri'
        self.test_files = ['epi0001.img', 'epi0002.img', 'epi0003.img',
                           'epi0004.img', 'epi0005.img']
        self.exp_file = 'epi.mat'

        # Get exptected data
>       self.exp_dat = sio.loadmat(os.path.join(self.data_dir, self.exp_file))

test/test_mri.py:26: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.venv/lib/python3.8/site-packages/scipy/io/matlab/_mio.py:225: in loadmat
    with _open_file_context(file_name, appendmat) as f:
/usr/local/lib/python3.8/contextlib.py:113: in __enter__
    return next(self.gen)
.venv/lib/python3.8/site-packages/scipy/io/matlab/_mio.py:17: in _open_file_context
    f, opened = _open_file(file_like, appendmat, mode)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

file_like = './data/mri/epi.mat', appendmat = True, mode = 'rb'

    def _open_file(file_like, appendmat, mode='rb'):
        """
        Open `file_like` and return as file-like object. First, check if object is
        already file-like; if so, return it as-is. Otherwise, try to pass it
        to open(). If that fails, and `file_like` is a string, and `appendmat` is true,
        append '.mat' and try again.
        """
        reqs = {'read'} if set(mode) & set('r+') else set()
        if set(mode) & set('wax+'):
            reqs.add('write')
        if reqs.issubset(dir(file_like)):
            return file_like, False

        try:
            return open(file_like, mode), True
        except OSError as e:
            # Probably "not found"
            if isinstance(file_like, str):
                if appendmat and not file_like.endswith('.mat'):
                    file_like += '.mat'
>               return open(file_like, mode), True
E               FileNotFoundError: [Errno 2] No such file or directory: './data/mri/epi.mat'

.venv/lib/python3.8/site-packages/scipy/io/matlab/_mio.py:45: FileNotFoundError
_____________ ERROR at setup of TestMri.test_get_roiflag_pass0001 ______________

file_like = './data/mri/epi.mat', appendmat = True, mode = 'rb'

    def _open_file(file_like, appendmat, mode='rb'):
        """
        Open `file_like` and return as file-like object. First, check if object is
        already file-like; if so, return it as-is. Otherwise, try to pass it
        to open(). If that fails, and `file_like` is a string, and `appendmat` is true,
        append '.mat' and try again.
        """
        reqs = {'read'} if set(mode) & set('r+') else set()
        if set(mode) & set('wax+'):
            reqs.add('write')
        if reqs.issubset(dir(file_like)):
            return file_like, False

        try:
>           return open(file_like, mode), True
E           FileNotFoundError: [Errno 2] No such file or directory: './data/mri/epi.mat'

.venv/lib/python3.8/site-packages/scipy/io/matlab/_mio.py:39: FileNotFoundError

During handling of the above exception, another exception occurred:

self = <test_mri.TestMri testMethod=test_get_roiflag_pass0001>
args = ('test_get_roiflag_pass0001',), kwargs = {}

    def __init__(self, *args, **kwargs):

        super(TestMri, self).__init__(*args, **kwargs)

        self.data_dir = './data/mri'
        self.test_files = ['epi0001.img', 'epi0002.img', 'epi0003.img',
                           'epi0004.img', 'epi0005.img']
        self.exp_file = 'epi.mat'

        # Get exptected data
>       self.exp_dat = sio.loadmat(os.path.join(self.data_dir, self.exp_file))

test/test_mri.py:26: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.venv/lib/python3.8/site-packages/scipy/io/matlab/_mio.py:225: in loadmat
    with _open_file_context(file_name, appendmat) as f:
/usr/local/lib/python3.8/contextlib.py:113: in __enter__
    return next(self.gen)
.venv/lib/python3.8/site-packages/scipy/io/matlab/_mio.py:17: in _open_file_context
    f, opened = _open_file(file_like, appendmat, mode)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

file_like = './data/mri/epi.mat', appendmat = True, mode = 'rb'

    def _open_file(file_like, appendmat, mode='rb'):
        """
        Open `file_like` and return as file-like object. First, check if object is
        already file-like; if so, return it as-is. Otherwise, try to pass it
        to open(). If that fails, and `file_like` is a string, and `appendmat` is true,
        append '.mat' and try again.
        """
        reqs = {'read'} if set(mode) & set('r+') else set()
        if set(mode) & set('wax+'):
            reqs.add('write')
        if reqs.issubset(dir(file_like)):
            return file_like, False

        try:
            return open(file_like, mode), True
        except OSError as e:
            # Probably "not found"
            if isinstance(file_like, str):
                if appendmat and not file_like.endswith('.mat'):
                    file_like += '.mat'
>               return open(file_like, mode), True
E               FileNotFoundError: [Errno 2] No such file or directory: './data/mri/epi.mat'

.venv/lib/python3.8/site-packages/scipy/io/matlab/_mio.py:45: FileNotFoundError
_____________ ERROR at setup of TestMri.test_get_roiflag_pass0002 ______________

file_like = './data/mri/epi.mat', appendmat = True, mode = 'rb'

    def _open_file(file_like, appendmat, mode='rb'):
        """
        Open `file_like` and return as file-like object. First, check if object is
        already file-like; if so, return it as-is. Otherwise, try to pass it
        to open(). If that fails, and `file_like` is a string, and `appendmat` is true,
        append '.mat' and try again.
        """
        reqs = {'read'} if set(mode) & set('r+') else set()
        if set(mode) & set('wax+'):
            reqs.add('write')
        if reqs.issubset(dir(file_like)):
            return file_like, False

        try:
>           return open(file_like, mode), True
E           FileNotFoundError: [Errno 2] No such file or directory: './data/mri/epi.mat'

.venv/lib/python3.8/site-packages/scipy/io/matlab/_mio.py:39: FileNotFoundError

During handling of the above exception, another exception occurred:

self = <test_mri.TestMri testMethod=test_get_roiflag_pass0002>
args = ('test_get_roiflag_pass0002',), kwargs = {}

    def __init__(self, *args, **kwargs):

        super(TestMri, self).__init__(*args, **kwargs)

        self.data_dir = './data/mri'
        self.test_files = ['epi0001.img', 'epi0002.img', 'epi0003.img',
                           'epi0004.img', 'epi0005.img']
        self.exp_file = 'epi.mat'

        # Get exptected data
>       self.exp_dat = sio.loadmat(os.path.join(self.data_dir, self.exp_file))

test/test_mri.py:26: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.venv/lib/python3.8/site-packages/scipy/io/matlab/_mio.py:225: in loadmat
    with _open_file_context(file_name, appendmat) as f:
/usr/local/lib/python3.8/contextlib.py:113: in __enter__
    return next(self.gen)
.venv/lib/python3.8/site-packages/scipy/io/matlab/_mio.py:17: in _open_file_context
    f, opened = _open_file(file_like, appendmat, mode)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

file_like = './data/mri/epi.mat', appendmat = True, mode = 'rb'

    def _open_file(file_like, appendmat, mode='rb'):
        """
        Open `file_like` and return as file-like object. First, check if object is
        already file-like; if so, return it as-is. Otherwise, try to pass it
        to open(). If that fails, and `file_like` is a string, and `appendmat` is true,
        append '.mat' and try again.
        """
        reqs = {'read'} if set(mode) & set('r+') else set()
        if set(mode) & set('wax+'):
            reqs.add('write')
        if reqs.issubset(dir(file_like)):
            return file_like, False

        try:
            return open(file_like, mode), True
        except OSError as e:
            # Probably "not found"
            if isinstance(file_like, str):
                if appendmat and not file_like.endswith('.mat'):
                    file_like += '.mat'
>               return open(file_like, mode), True
E               FileNotFoundError: [Errno 2] No such file or directory: './data/mri/epi.mat'

.venv/lib/python3.8/site-packages/scipy/io/matlab/_mio.py:45: FileNotFoundError
=================================== FAILURES ===================================
_________________________ TestUtil.test_load_array_jl __________________________

self = <test_dataform_sparse.TestUtil testMethod=test_load_array_jl>

    def test_load_array_jl(self):
        data = np.array([[1, 0, 0, 0],
                         [2, 2, 0, 0],
                         [3, 3, 3, 0]])

>       testdata = load_array('data/array_jl_dense_v1.mat', key='a')

test/test_dataform_sparse.py:70: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
bdpy/dataform/sparse.py:19: in load_array
    with h5py.File(fname, 'r') as f:
.venv/lib/python3.8/site-packages/h5py/_hl/files.py:567: in __init__
    fid = make_fid(name, mode, userblock_size, fapl, fcpl, swmr=swmr)
.venv/lib/python3.8/site-packages/h5py/_hl/files.py:231: in make_fid
    fid = h5f.open(name, flags, fapl=fapl)
h5py/_objects.pyx:54: in h5py._objects.with_phil.wrapper
    ???
h5py/_objects.pyx:55: in h5py._objects.with_phil.wrapper
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   FileNotFoundError: [Errno 2] Unable to open file (unable to open file: name = 'data/array_jl_dense_v1.mat', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

h5py/h5f.pyx:106: FileNotFoundError
_______________________________ TestEval.test_2d _______________________________

self = <test_evals.TestEval testMethod=test_2d>

    def test_2d(self):
>       with open('data/testdata-2d.pkl.gz', 'rb') as f:
E       FileNotFoundError: [Errno 2] No such file or directory: 'data/testdata-2d.pkl.gz'

test/test_evals.py:72: FileNotFoundError
_____________________________ TestEval.test_2d_nan _____________________________

self = <test_evals.TestEval testMethod=test_2d_nan>

    def test_2d_nan(self):
>       with open('data/testdata-2d-nan.pkl.gz', 'rb') as f:
E       FileNotFoundError: [Errno 2] No such file or directory: 'data/testdata-2d-nan.pkl.gz'

test/test_evals.py:88: FileNotFoundError
_____________ TestUtil.test_ModelTest_fastl2lir_chunk_bd_modelpath _____________

self = <test_ml.TestUtil testMethod=test_ModelTest_fastl2lir_chunk_bd_modelpath>

    def test_ModelTest_fastl2lir_chunk_bd_modelpath(self):
        X = np.random.rand(30, 500)

        model = FastL2LiR()
        model_path = './test_models/fastl2lir-chunk-bd/model'

        test = ModelTest(model, X)
        test.model_path = model_path
        test.model_format = 'bdmodel'
        test.chunk_axis = 1
>       y_pred = test.run()

test/test_ml.py:205: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <bdpy.ml.learning.ModelTest object at 0xffff6a1ad3a0>

    def run(self):
        '''Run test.'''

        if self.dtype is not None:
            self.X = self.X.astype(self.dtype)

        if self.model_path is None:
            y_pred = self.model.predict(self.X, **self.model_parameters)
            return y_pred

        if self.model_format == 'pickle':
            if os.path.isfile(self.model_path):
                model_files = [self.model_path]
            elif os.path.isdir(self.model_path):
                model_files = sorted(glob.glob(os.path.join(self.model_path, '*.pkl')))
            else:
                raise ValueError('Invalid model path: %s' % self.model_path)
        elif self.model_format == 'bdmodel':
            if os.path.isfile(self.model_path):
                raise ValueError('BDmodel should be specified as a directory, not a file')

            # W: shape = (n_voxels, shape_features)
            if os.path.isdir(os.path.join(self.model_path, 'W')):
                W_files = sorted(glob.glob(os.path.join(self.model_path, 'W', '*.mat')))
            elif os.path.isfile(os.path.join(self.model_path, 'W.mat')):
                W_files = [os.path.join(self.model_path, 'W.mat')]
            else:
>               raise RuntimeError('W not found.')
E               RuntimeError: W not found.

bdpy/ml/learning.py:507: RuntimeError
____________ TestUtil.test_ModelTest_fastl2lir_chunk_pkl_modelpath _____________

self = <test_ml.TestUtil testMethod=test_ModelTest_fastl2lir_chunk_pkl_modelpath>

    def test_ModelTest_fastl2lir_chunk_pkl_modelpath(self):
        X = np.random.rand(30, 500)

        model = FastL2LiR()
        model_path = './test_models/fastl2lir-chunk-pkl/model'

        test = ModelTest(model, X)
        test.model_path = model_path
        test.chunk_axis = 1
>       y_pred = test.run()

test/test_ml.py:180: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <bdpy.ml.learning.ModelTest object at 0xffff6a19a400>

    def run(self):
        '''Run test.'''

        if self.dtype is not None:
            self.X = self.X.astype(self.dtype)

        if self.model_path is None:
            y_pred = self.model.predict(self.X, **self.model_parameters)
            return y_pred

        if self.model_format == 'pickle':
            if os.path.isfile(self.model_path):
                model_files = [self.model_path]
            elif os.path.isdir(self.model_path):
                model_files = sorted(glob.glob(os.path.join(self.model_path, '*.pkl')))
            else:
>               raise ValueError('Invalid model path: %s' % self.model_path)
E               ValueError: Invalid model path: ./test_models/fastl2lir-chunk-pkl/model

bdpy/ml/learning.py:496: ValueError
____________ TestUtil.test_ModelTest_fastl2lir_nochunk_bd_modelpath ____________

self = <test_ml.TestUtil testMethod=test_ModelTest_fastl2lir_nochunk_bd_modelpath>

    def test_ModelTest_fastl2lir_nochunk_bd_modelpath(self):
        X = np.random.rand(30, 500)

        model = FastL2LiR()
        model_path = './test_models/fastl2lir-nochunk-bd/model'

        test = ModelTest(model, X)
        test.model_path = model_path
        test.model_format = 'bdmodel'
>       y_pred = test.run()

test/test_ml.py:192: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <bdpy.ml.learning.ModelTest object at 0xffff6a257e50>

    def run(self):
        '''Run test.'''

        if self.dtype is not None:
            self.X = self.X.astype(self.dtype)

        if self.model_path is None:
            y_pred = self.model.predict(self.X, **self.model_parameters)
            return y_pred

        if self.model_format == 'pickle':
            if os.path.isfile(self.model_path):
                model_files = [self.model_path]
            elif os.path.isdir(self.model_path):
                model_files = sorted(glob.glob(os.path.join(self.model_path, '*.pkl')))
            else:
                raise ValueError('Invalid model path: %s' % self.model_path)
        elif self.model_format == 'bdmodel':
            if os.path.isfile(self.model_path):
                raise ValueError('BDmodel should be specified as a directory, not a file')

            # W: shape = (n_voxels, shape_features)
            if os.path.isdir(os.path.join(self.model_path, 'W')):
                W_files = sorted(glob.glob(os.path.join(self.model_path, 'W', '*.mat')))
            elif os.path.isfile(os.path.join(self.model_path, 'W.mat')):
                W_files = [os.path.join(self.model_path, 'W.mat')]
            else:
>               raise RuntimeError('W not found.')
E               RuntimeError: W not found.

bdpy/ml/learning.py:507: RuntimeError
___________ TestUtil.test_ModelTest_fastl2lir_nochunk_pkl_modelpath ____________

self = <test_ml.TestUtil testMethod=test_ModelTest_fastl2lir_nochunk_pkl_modelpath>

    def test_ModelTest_fastl2lir_nochunk_pkl_modelpath(self):
        X = np.random.rand(30, 500)

        model = FastL2LiR()
        model_path = './test_models/fastl2lir-nochunk-pkl/model.pkl'

        test = ModelTest(model, X)
        test.model_path = model_path
>       y_pred = test.run()

test/test_ml.py:168: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <bdpy.ml.learning.ModelTest object at 0xffff6a1c35b0>

    def run(self):
        '''Run test.'''

        if self.dtype is not None:
            self.X = self.X.astype(self.dtype)

        if self.model_path is None:
            y_pred = self.model.predict(self.X, **self.model_parameters)
            return y_pred

        if self.model_format == 'pickle':
            if os.path.isfile(self.model_path):
                model_files = [self.model_path]
            elif os.path.isdir(self.model_path):
                model_files = sorted(glob.glob(os.path.join(self.model_path, '*.pkl')))
            else:
>               raise ValueError('Invalid model path: %s' % self.model_path)
E               ValueError: Invalid model path: ./test_models/fastl2lir-nochunk-pkl/model.pkl

bdpy/ml/learning.py:496: ValueError
_________________ TestUtil.test_ModelTest_sklearn_nochunk_pkl __________________

self = <test_ml.TestUtil testMethod=test_ModelTest_sklearn_nochunk_pkl>

    def test_ModelTest_sklearn_nochunk_pkl(self):
        X = np.random.rand(30, 500)

        model_path = './test_models/lir-nochunk-pkl/model.pkl'
>       with open(model_path, 'rb') as f:
E       FileNotFoundError: [Errno 2] No such file or directory: './test_models/lir-nochunk-pkl/model.pkl'

test/test_ml.py:142: FileNotFoundError
____________ TestUtil.test_ModelTest_sklearn_nochunk_pkl_modelpath _____________

self = <test_ml.TestUtil testMethod=test_ModelTest_sklearn_nochunk_pkl_modelpath>

    def test_ModelTest_sklearn_nochunk_pkl_modelpath(self):
        X = np.random.rand(30, 500)

        model = LinearRegression()
        model_path = './test_models/lir-nochunk-pkl/model.pkl'

        test = ModelTest(model, X)
        test.model_path = model_path
>       y_pred = test.run()

test/test_ml.py:157: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <bdpy.ml.learning.ModelTest object at 0xffff8518f7c0>

    def run(self):
        '''Run test.'''

        if self.dtype is not None:
            self.X = self.X.astype(self.dtype)

        if self.model_path is None:
            y_pred = self.model.predict(self.X, **self.model_parameters)
            return y_pred

        if self.model_format == 'pickle':
            if os.path.isfile(self.model_path):
                model_files = [self.model_path]
            elif os.path.isdir(self.model_path):
                model_files = sorted(glob.glob(os.path.join(self.model_path, '*.pkl')))
            else:
>               raise ValueError('Invalid model path: %s' % self.model_path)
E               ValueError: Invalid model path: ./test_models/lir-nochunk-pkl/model.pkl

bdpy/ml/learning.py:496: ValueError
=============================== warnings summary ===============================
../../usr/local/lib/python3.8/unittest/loader.py:66
  /usr/local/lib/python3.8/unittest/loader.py:66: PytestCollectionWarning: cannot collect test class 'TestLoader' because it has a __init__ constructor (from: test/test_bdata.py)
    class TestLoader(object):

../../usr/local/lib/python3.8/unittest/loader.py:66
  /usr/local/lib/python3.8/unittest/loader.py:66: PytestCollectionWarning: cannot collect test class 'TestLoader' because it has a __init__ constructor (from: test/test_bdata_metadata.py)
    class TestLoader(object):

../../usr/local/lib/python3.8/unittest/loader.py:66
  /usr/local/lib/python3.8/unittest/loader.py:66: PytestCollectionWarning: cannot collect test class 'TestLoader' because it has a __init__ constructor (from: test/test_bdata_utils.py)
    class TestLoader(object):

.venv/lib/python3.8/site-packages/fastl2lir/fastl2lir.py:10
  /workspaces/bdpy/.venv/lib/python3.8/site-packages/fastl2lir/fastl2lir.py:10: PendingDeprecationWarning: Importing from numpy.matlib is deprecated since 1.19.0. The matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray. 
    from numpy.matlib import repmat

../../usr/local/lib/python3.8/unittest/loader.py:66
  /usr/local/lib/python3.8/unittest/loader.py:66: PytestCollectionWarning: cannot collect test class 'TestLoader' because it has a __init__ constructor (from: test/test_dataform_sparse.py)
    class TestLoader(object):

../../usr/local/lib/python3.8/unittest/loader.py:66
  /usr/local/lib/python3.8/unittest/loader.py:66: PytestCollectionWarning: cannot collect test class 'TestLoader' because it has a __init__ constructor (from: test/test_distcomp.py)
    class TestLoader(object):

../../usr/local/lib/python3.8/unittest/loader.py:66
  /usr/local/lib/python3.8/unittest/loader.py:66: PytestCollectionWarning: cannot collect test class 'TestLoader' because it has a __init__ constructor (from: test/test_feature.py)
    class TestLoader(object):

../../usr/local/lib/python3.8/unittest/loader.py:66
  /usr/local/lib/python3.8/unittest/loader.py:66: PytestCollectionWarning: cannot collect test class 'TestLoader' because it has a __init__ constructor (from: test/test_featureselector.py)
    class TestLoader(object):

../../usr/local/lib/python3.8/unittest/loader.py:66
  /usr/local/lib/python3.8/unittest/loader.py:66: PytestCollectionWarning: cannot collect test class 'TestLoader' because it has a __init__ constructor (from: test/test_ml_utils.py)
    class TestLoader(object):

.venv/lib/python3.8/site-packages/nibabel/quaternions.py:31
  /workspaces/bdpy/.venv/lib/python3.8/site-packages/nibabel/quaternions.py:31: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    MAX_FLOAT = np.maximum_sctype(np.float)

.venv/lib/python3.8/site-packages/nibabel/quaternions.py:32
  /workspaces/bdpy/.venv/lib/python3.8/site-packages/nibabel/quaternions.py:32: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    FLOAT_EPS = np.finfo(np.float).eps

.venv/lib/python3.8/site-packages/nipy/core/reference/coordinate_system.py:75
  /workspaces/bdpy/.venv/lib/python3.8/site-packages/nipy/core/reference/coordinate_system.py:75: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    dtype = np.dtype([('x', np.float),

.venv/lib/python3.8/site-packages/nipy/core/reference/coordinate_system.py:76
  /workspaces/bdpy/.venv/lib/python3.8/site-packages/nipy/core/reference/coordinate_system.py:76: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    ('y', np.float),

.venv/lib/python3.8/site-packages/nipy/core/reference/coordinate_system.py:77
  /workspaces/bdpy/.venv/lib/python3.8/site-packages/nipy/core/reference/coordinate_system.py:77: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    ('z', np.float)])

.venv/lib/python3.8/site-packages/nipy/core/reference/coordinate_system.py:82
  /workspaces/bdpy/.venv/lib/python3.8/site-packages/nipy/core/reference/coordinate_system.py:82: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    def __init__(self, coord_names, name='', coord_dtype=np.float):

.venv/lib/python3.8/site-packages/nipy/core/reference/coordinate_system.py:423
  /workspaces/bdpy/.venv/lib/python3.8/site-packages/nipy/core/reference/coordinate_system.py:423: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    def __init__(self, coord_names, name='', coord_dtype=np.float):

../../usr/local/lib/python3.8/unittest/loader.py:66
  /usr/local/lib/python3.8/unittest/loader.py:66: PytestCollectionWarning: cannot collect test class 'TestLoader' because it has a __init__ constructor (from: test/test_mri.py)
    class TestLoader(object):

../../usr/local/lib/python3.8/unittest/loader.py:66
  /usr/local/lib/python3.8/unittest/loader.py:66: PytestCollectionWarning: cannot collect test class 'TestLoader' because it has a __init__ constructor (from: test/test_preproc.py)
    class TestLoader(object):

../../usr/local/lib/python3.8/unittest/loader.py:66
  /usr/local/lib/python3.8/unittest/loader.py:66: PytestCollectionWarning: cannot collect test class 'TestLoader' because it has a __init__ constructor (from: test/test_stats.py)
    class TestLoader(object):

../../usr/local/lib/python3.8/unittest/loader.py:66
  /usr/local/lib/python3.8/unittest/loader.py:66: PytestCollectionWarning: cannot collect test class 'TestLoader' because it has a __init__ constructor (from: test/test_util.py)
    class TestLoader(object):

../../usr/local/lib/python3.8/unittest/loader.py:66
  /usr/local/lib/python3.8/unittest/loader.py:66: PytestCollectionWarning: cannot collect test class 'TestLoader' because it has a __init__ constructor (from: test/test_util_math.py)
    class TestLoader(object):

test/test_ml.py: 20 warnings
  /workspaces/bdpy/.venv/lib/python3.8/site-packages/fastl2lir/fastl2lir.py:243: PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.
    def submean(a): return a - np.matrix(np.mean(a, axis=1)).T

test/test_ml.py: 10 warnings
  /workspaces/bdpy/.venv/lib/python3.8/site-packages/fastl2lir/fastl2lir.py:246: PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.
    np.dot(np.matrix(np.std(x, axis=1, ddof=1)).T,

test/test_ml.py: 10 warnings
  /workspaces/bdpy/.venv/lib/python3.8/site-packages/fastl2lir/fastl2lir.py:247: PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.
    np.matrix(np.std(y, axis=1, ddof=1)))

test/test_preproc.py::TestPreprocessor::test_select_top_axisone
test/test_preproc.py::TestPreprocessor::test_select_top_default
  /workspaces/bdpy/bdpy/preproc/select_top.py:44: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    rank = np.zeros(num_elem, dtype=np.int)

test/test_preproc.py::TestPreprocessor::test_select_top_axisone
  /workspaces/bdpy/bdpy/preproc/select_top.py:54: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    selected_index = np.array(range(0, num_elem), dtype=np.int)[selected_index_bool]

test/test_preproc.py::TestPreprocessor::test_select_top_default
  /workspaces/bdpy/bdpy/preproc/select_top.py:51: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    selected_index = np.array(range(0, num_elem), dtype=np.int)[selected_index_bool]

test/test_stats.py::TestStats::test_corrmat_default
test/test_stats.py::TestStats::test_corrmat_default
test/test_stats.py::TestStats::test_corrmat_varcol
test/test_stats.py::TestStats::test_corrmat_varcol
  /workspaces/bdpy/bdpy/stats/corr.py:112: PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.
    submean = lambda a: a - np.matrix(np.mean(a, axis=1)).T

test/test_stats.py::TestStats::test_corrmat_default
test/test_stats.py::TestStats::test_corrmat_default
test/test_stats.py::TestStats::test_corrmat_varcol
test/test_stats.py::TestStats::test_corrmat_varcol
  /workspaces/bdpy/bdpy/stats/corr.py:114: PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.
    cmat = (np.dot(submean(x), submean(y).T) / (nobs - 1)) / np.dot(np.matrix(np.std(x, axis=1, ddof=1)).T, np.matrix(np.std(y, axis=1, ddof=1)))

test/test_util.py::TestUtil::test_divide_chunks
test/test_util.py::TestUtil::test_divide_chunks
  /workspaces/bdpy/bdpy/util/utils.py:93: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    n_chunk = np.int(np.ceil(len(input_list) / chunk_size))

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED test/test_dataform_sparse.py::TestUtil::test_load_array_jl - FileNotFo...
FAILED test/test_evals.py::TestEval::test_2d - FileNotFoundError: [Errno 2] N...
FAILED test/test_evals.py::TestEval::test_2d_nan - FileNotFoundError: [Errno ...
FAILED test/test_ml.py::TestUtil::test_ModelTest_fastl2lir_chunk_bd_modelpath
FAILED test/test_ml.py::TestUtil::test_ModelTest_fastl2lir_chunk_pkl_modelpath
FAILED test/test_ml.py::TestUtil::test_ModelTest_fastl2lir_nochunk_bd_modelpath
FAILED test/test_ml.py::TestUtil::test_ModelTest_fastl2lir_nochunk_pkl_modelpath
FAILED test/test_ml.py::TestUtil::test_ModelTest_sklearn_nochunk_pkl - FileNo...
FAILED test/test_ml.py::TestUtil::test_ModelTest_sklearn_nochunk_pkl_modelpath
ERROR test/test_mri.py::TestMri::test_add_load_epi_pass0001 - FileNotFoundErr...
ERROR test/test_mri.py::TestMri::test_get_roiflag_pass0001 - FileNotFoundErro...
ERROR test/test_mri.py::TestMri::test_get_roiflag_pass0002 - FileNotFoundErro...
============= 9 failed, 86 passed, 75 warnings, 3 errors in 2.95s ==============
ganow commented 1 year ago

I'm trying to resolve this issue in #66

ganow commented 8 months ago

Partly solved in #66. We have decided that we tentatively skip some part of the problem (test_metrics.py and test_mri.py)