Skip to content

Commit

Permalink
[TESTS] Add example tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcieslak committed Nov 11, 2020
1 parent c421823 commit 23612fe
Showing 1 changed file with 82 additions and 4 deletions.
86 changes: 82 additions & 4 deletions tests/test_bond.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,98 @@
import pytest
from pkg_resources import resource_filename as pkgrf
import shutil
import bond
import tempfile
from bond import BOnD
import os.path as op
from copy import deepcopy
import base64
from glob import glob

TEST_DATA = pkgrf("bond", "testdata")

COMPLETE_KEY_GROUPS = [
'acquisition-HASC55AP_datatype-dwi_suffix-dwi',
'acquisition-v4_datatype-fmap_fmap-magnitude1_suffix-magnitude1',
'acquisition-v4_datatype-fmap_fmap-magnitude2_suffix-magnitude2',
'acquisition-v4_datatype-fmap_fmap-phasediff_suffix-phasediff',
'datatype-anat_suffix-T1w',
'datatype-fmap_direction-PA_fmap-epi_suffix-epi',
'datatype-func_suffix-bold_task-rest']

def test_data(tmp_path):

def get_data(tmp_path):
"""Copy testing data to a local directory"""
data_root = tmp_path / "testdata"
shutil.copytree(TEST_DATA, str(data_root))
assert len(list(data_root.rglob("*"))) > 5
return data_root


def test_keygroups(tmp_path):
data_root = get_data(tmp_path)

# Test the complete data
complete_bod = BOnD(data_root / "complete")
complete_misfit_fmaps = complete_bod._cache_fieldmaps()
# There should be no unpaired fieldmaps
assert len(complete_misfit_fmaps) == 0

# Test that the correct key groups are found
key_groups = complete_bod.get_key_groups()
assert key_groups == COMPLETE_KEY_GROUPS

# Test the incomplete
ibod = BOnD(data_root / "inconsistent")
inc_misfit_fmaps = ibod._cache_fieldmaps()
assert len(inc_misfit_fmaps) == 1

# There will still be the same number of key groups
ikey_groups = ibod.get_key_groups()
assert ikey_groups == COMPLETE_KEY_GROUPS


def test_csv_creation(tmp_path):
"""Test the Key Group and Parameter Group creation on sample data.
"""
data_root = get_data(tmp_path)

# Test the complete data
complete_bod = BOnD(data_root / "complete")
complete_misfit_fmaps = complete_bod._cache_fieldmaps()
# There should be no unpaired fieldmaps
assert len(complete_misfit_fmaps) == 0

# Test that the correct key groups are found
key_groups = complete_bod.get_key_groups()
assert key_groups == COMPLETE_KEY_GROUPS

# Get the CSVs from the complete data
cfiles_df, csummary_df = \
complete_bod.get_param_groups_dataframes()

# Make sure we got all 21 of the files
assert cfiles_df.shape[0] == 21

# This data should have the same number of param
# groups as key groups
assert csummary_df.shape[0] == len(COMPLETE_KEY_GROUPS)

# Test the incomplete
ibod = BOnD(data_root / "inconsistent")
inc_misfit_fmaps = ibod._cache_fieldmaps()
assert len(inc_misfit_fmaps) == 1

# There will still be the same number of key groups
ikey_groups = ibod.get_key_groups()
assert ikey_groups == COMPLETE_KEY_GROUPS

# Get the CSVs from the inconsistent data
ifiles_df, isummary_df = \
ibod.get_param_groups_dataframes()

# There are still 21 files
assert ifiles_df.shape[0] == 21

# But now there are more parameter groups
assert isummary_df.shape[0] == 11


"""
Expand Down

0 comments on commit 23612fe

Please sign in to comment.