Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor test modules #66

Merged
merged 32 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e67f288
refactor ml/test_crossvalidation.py
ganow Jun 20, 2023
ea8461a
test/bdata/test_metadata.py
ganow Jun 20, 2023
3372881
test/bdata/test_utils.py
ganow Jun 20, 2023
e94082f
test/bdata/test_bdata.py
ganow Jun 20, 2023
03c7aa7
add note for deprecation warning
ganow Jun 20, 2023
fc7b796
test/dataform
ganow Jun 20, 2023
0fcabdd
test/distcomp
ganow Jun 20, 2023
1dbbd47
notes on optional dependencies
ganow Jun 20, 2023
925b9fa
fix comment
ganow Jun 20, 2023
2505d61
remove the dependency on the pre-computed data
ganow Jun 20, 2023
034f9bc
test/dl/torch
ganow Jun 20, 2023
104bad2
explicitly raise errors for non-tested codebases
ganow Jun 20, 2023
85f2a0e
rename test modules
ganow Jun 20, 2023
4ce8a2f
test/ml/test_learning.py
ganow Jun 20, 2023
1876284
update test/ml
ganow Jun 20, 2023
ada85bd
test/evals
ganow Jun 20, 2023
0847a24
test/feature
ganow Jun 20, 2023
b3baa15
test/util
ganow Jun 21, 2023
a9c18bc
__init__ in test/ to accept multiple test files with same names
ganow Jun 21, 2023
92f390c
test/bdata/test_featureselector.py
ganow Jun 21, 2023
2971e9f
test/test_stats.py
ganow Jun 21, 2023
780db44
test/preproc
ganow Jun 21, 2023
18c8f60
Merge branch 'dev' into refactor-test-modules
ganow Jun 27, 2023
ac517f7
remove unimplemented test
ganow Jun 27, 2023
a859e93
rename test directory from 'test' to 'tests'
ganow Jun 27, 2023
5e97175
assets for testing ModelTest
ganow Jun 27, 2023
994d3c1
Merge branch 'dev' into refactor-test-modules
ganow Jul 21, 2023
b23098f
use relative path to specify data/mri/epi*.{img/mat}
ganow Jul 21, 2023
5938706
use relative path to specify array_jl_*.mat
ganow Jul 21, 2023
ddee365
array datasets for testing
ganow Jul 21, 2023
c07246c
add note on the failed test
ganow Dec 14, 2023
75c6c76
Merge branch 'dev' into refactor-test-modules
ganow Dec 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Python package for brain decoding analysis
- `fig` module
- matplotlib
- Pillow
- `bdpy.ml` module
- tqdm
- `mri` module
- nipy
- nibabel
Expand All @@ -38,6 +40,9 @@ Python package for brain decoding analysis
- PyTorch
- Pillow

### Optional requirements for testing
- fastl2lir

## Installation

Latest stable release:
Expand Down
3 changes: 3 additions & 0 deletions bdpy/preproc/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

import numpy as np
from numpy.matlib import repmat
# NOTE: PendingDeprecationWarning: Importing from numpy.matlib is deprecated since 1.19.0.
# repmat(a, m, n) is equivalent to tile(a, (m, n)). Use tile instead.
# c.f. https://numpy.org/doc/stable/user/numpy-for-matlab-users.html


## Abstract preprocessor #######################################################
Expand Down
35 changes: 16 additions & 19 deletions test/test_bdata.py → test/bdata/test_bdata.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
'''Tests for bdpy.bdata'''
'''Tests for bdpy.bdata.bdata.'''


from unittest import TestCase, TestLoader, TextTestRunner

import copy
import unittest

import numpy as np
from numpy.testing import assert_array_equal

import bdpy
from bdpy.bdata.bdata import BData


class TestBdata(TestCase):
class TestBdata(unittest.TestCase):
'''Tests of 'bdata' module'''

def __init__(self, *args, **kwargs):
Expand All @@ -23,7 +21,7 @@ def test_add_get(self):
data_y = np.random.rand(5, 8)
data_z = np.random.rand(5, 20)

b = bdpy.BData()
b = BData()

b.add(data_x, 'Data_X')
b.add(data_y, 'Data_Y')
Expand Down Expand Up @@ -55,7 +53,7 @@ def test_metadata_add_get(self):
metadata_a = np.random.rand(n_col)
metadata_b = np.random.rand(n_col)

b = bdpy.BData()
b = BData()

b.add(data_x, 'Data_X')
b.add(data_y, 'Data_Y')
Expand All @@ -77,7 +75,7 @@ def test_metadata_add_get_where(self):
metadata_a = np.random.rand(10)
metadata_b = np.random.rand(8)

b = bdpy.BData()
b = BData()

b.add(data_x, 'Data_X')
b.add(data_y, 'Data_Y')
Expand All @@ -99,7 +97,7 @@ def test_set_metadatadescription_1(self):
metadata_a = np.random.rand(10)
metadata_b = np.random.rand(8)

b = bdpy.BData()
b = BData()
b.add(data_x, 'Data_X')
b.add(data_y, 'Data_Y')
b.add_metadata('Metadata_A', metadata_a, where='Data_X')
Expand All @@ -117,7 +115,7 @@ def test_select(self):
data_x = np.random.rand(5, 10)
data_y = np.random.rand(5, 5)

b = bdpy.BData()
b = BData()
b.add(data_x, 'Data_X')
b.add(data_y, 'Data_Y')

Expand All @@ -142,7 +140,7 @@ def test_select(self):

# Tests for vmap
def test_vmap_add_get(self):
bdata = bdpy.BData()
bdata = BData()
bdata.add(np.random.rand(4, 3), 'MainData')
bdata.add(np.arange(4) + 1, 'Label')

Expand All @@ -159,7 +157,7 @@ def test_vmap_add_get(self):
np.testing.assert_array_equal(bdata.get_label('Label'), label)

def test_vmap_add_same_map(self):
bdata = bdpy.BData()
bdata = BData()
bdata.add(np.random.rand(4, 3), 'MainData')
bdata.add(np.arange(4) + 1, 'Label')

Expand All @@ -179,7 +177,7 @@ def test_vmap_add_same_map(self):
def test_vmap_errorcases(self):
n_sample = 4

bdata = bdpy.BData()
bdata = BData()
bdata.add(np.random.rand(n_sample, 3), 'MainData')
bdata.add(np.arange(n_sample) + 1, 'Label')

Expand Down Expand Up @@ -208,7 +206,7 @@ def test_vmap_errorcases(self):
bdata.add_vmap('Label', label_map_inconsist)

def test_vmap_add_unnecessary_vmap(self):
bdata = bdpy.BData()
bdata = BData()
bdata.add(np.random.rand(4, 3), 'MainData')
bdata.add(np.arange(4) + 1, 'Label')

Expand All @@ -226,7 +224,7 @@ def test_vmap_add_unnecessary_vmap(self):
assert bdata.get_vmap('Label') == label_map_ture

def test_vmap_add_insufficient_vmap(self):
bdata = bdpy.BData()
bdata = BData()
bdata.add(np.random.rand(4, 3), 'MainData')
bdata.add(np.arange(4) + 1, 'Label')

Expand All @@ -238,7 +236,7 @@ def test_vmap_add_insufficient_vmap(self):
bdata.add_vmap('Label', label_map)

def test_vmap_add_invalid_name_vmap(self):
bdata = bdpy.BData()
bdata = BData()
bdata.add(np.random.rand(4, 3), 'MainData')
bdata.add(np.arange(4) + 1, 'Label')

Expand All @@ -252,5 +250,4 @@ def test_vmap_add_invalid_name_vmap(self):


if __name__ == "__main__":
test_suite = TestLoader().loadTestsFromTestCase(TestBdata)
TextTestRunner(verbosity=2).run(test_suite)
unittest.main()
27 changes: 13 additions & 14 deletions test/test_bdata_metadata.py → test/bdata/test_metadata.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
'''Tests for bdpy.bdata.metadata.'''


from unittest import TestCase, TestLoader, TextTestRunner
import unittest

import numpy as np
from numpy.testing import assert_array_equal

import bdpy
from bdpy.bdata import metadata


class TestBdataMetadata(TestCase):
class TestMetadata(unittest.TestCase):
'''Tests for bdpy.bdata.metadata.'''

def __init__(self, *args, **kwargs):
super(TestBdataMetadata, self).__init__(*args, **kwargs)
super(TestMetadata, self).__init__(*args, **kwargs)

def test_set_get(self):
'''Test for MetaData.set() and MetaData.get().'''
md = bdpy.bdata.metadata.MetaData()
md = metadata.MetaData()
md.set('MetaData_A', [1] * 10 + [0] * 5, 'Test metadata A')
md.set('MetaData_B', [0] * 10 + [1] * 5, 'Test metadata B')

Expand All @@ -28,7 +28,7 @@ def test_set_get(self):

def test_set_get_resize(self):
'''Test for MetaData.set() and MetaData.get(); resizing values.'''
md = bdpy.bdata.metadata.MetaData()
md = metadata.MetaData()
md.set('MetaData_A', [1] * 10 + [0] * 5, 'Test metadata A')
md.set('MetaData_B', [0] * 10 + [1] * 5, 'Test metadata B')
md.set('MetaData_C', [0] * 15 + [1] * 3, 'Test metadata C')
Expand All @@ -42,7 +42,7 @@ def test_set_get_resize(self):

def test_set_get_overwrite(self):
'''Test for MetaData.set() and MetaData.get(); overwriting values.'''
md = bdpy.bdata.metadata.MetaData()
md = metadata.MetaData()
md.set('MetaData_A', [1] * 10 + [0] * 5, 'Test metadata A')
md.set('MetaData_B', [0] * 10 + [1] * 5, 'Test metadata B')

Expand All @@ -55,7 +55,7 @@ def test_set_get_overwrite(self):

def test_set_get_overwrite_resize(self):
'''Test for MetaData.set() and MetaData.get(); overwriting and resizing values.'''
md = bdpy.bdata.metadata.MetaData()
md = metadata.MetaData()
md.set('MetaData_A', [1, 1, 1, 0, 0], 'Test metadata A')
md.set('MetaData_B', [0, 0, 0, 1, 1], 'Test metadata B')

Expand All @@ -68,7 +68,7 @@ def test_set_get_overwrite_resize(self):

def test_set_get_update(self):
'''Test for MetaData.set() and MetaData.get(); updating values.'''
md = bdpy.bdata.metadata.MetaData()
md = metadata.MetaData()
md.set('MetaData_A', [1] * 10 + [0] * 5, 'Test metadata A')
md.set('MetaData_B', [0] * 10 + [1] * 5, 'Test metadata B')

Expand All @@ -81,7 +81,7 @@ def test_set_get_update(self):

def test_get_notfound(self):
'''Test for MetaData.get(); key not found case.'''
md = bdpy.bdata.metadata.MetaData()
md = metadata.MetaData()
md.set('MetaData_A', [1] * 10 + [0] * 5, 'Test metadata A')
md.set('MetaData_B', [0] * 10 + [1] * 5, 'Test metadata B')

Expand All @@ -90,21 +90,20 @@ def test_get_notfound(self):

def test_get_value_len(self):
'''Test for get_value_len().'''
md = bdpy.bdata.metadata.MetaData()
md = metadata.MetaData()
md.set('MetaData_A', [1] * 10 + [0] * 5, 'Test metadata A')
md.set('MetaData_B', [0] * 10 + [1] * 5, 'Test metadata B')

assert_array_equal(md.get_value_len(), 15)

def test_keylist(self):
'''Test for keylist().'''
md = bdpy.bdata.metadata.MetaData()
md = metadata.MetaData()
md.set('MetaData_A', [1] * 10 + [0] * 5, 'Test metadata A')
md.set('MetaData_B', [0] * 10 + [1] * 5, 'Test metadata B')

assert_array_equal(md.keylist(), ['MetaData_A', 'MetaData_B'])


if __name__ == '__main__':
test_suite = TestLoader().loadTestsFromTestCase(TestBdataMetadata)
TextTestRunner(verbosity=2).run(test_suite)
unittest.main()
Loading