Skip to content

Commit

Permalink
Add a basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
AuguB committed Dec 8, 2023
1 parent 999c495 commit 86ea110
Showing 1 changed file with 20 additions and 33 deletions.
53 changes: 20 additions & 33 deletions pytest_tests/test_normative.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,24 @@
import pytest_tests
from pcntoolkit.normative import load_response_vars
from pcntoolkit.dataio import fileio
# from dataio import fileio
import pytest
import sys
from unittest import mock
from pcntoolkit.normative import get_args

import numpy as np
def test_get_args():
# Define the test arguments
test_args = ['program_name', 'responses', '-f', 'estimate', '-m', 'maskfile', '-c', 'covfile', '-k', '5', '-t', 'testcov', '-r', 'testresp', '-a', 'gpr', '-x', 'configparam']

def create_dummy_data():
# Create a dummy 3D array for the datafile
data = np.random.rand(10, 10, 10)

# Create a dummy 3D array for the maskfile
mask = np.ones((10, 10, 10))

return data, mask

# Use the function to create the dummy data
data, mask = create_dummy_data()

# Store the dummy data on disk
datafile = 'test_data.nii.gz'
maskfile = 'test_mask.nii.gz'
fileio.save_nifti(data, datafile)
fileio.save_nifti(mask, maskfile)


def test_load_response_vars():

# Call the function with the test inputs
Y, volmask,my_str = load_response_vars(datafile, maskfile, vol=True)
# Replace sys.argv with the test arguments
with mock.patch.object(sys, 'argv', test_args):
# Call the function with the test arguments
args = get_args()

# Assert that the function returns the expected results
# This will depend on what you expect the function to return
# For example, you might check that Y and volmask are not None
assert Y is not None
assert volmask is not None
assert my_str == 'test'
assert args.responses == 'responses'
assert args.func == 'estimate'
assert args.maskfile == 'maskfile'
assert args.covfile == 'covfile'
assert args.cvfolds == '5'
assert args.testcov == 'testcov'
assert args.testresp == 'testresp'
assert args.alg == 'gpr'
assert args.configparam == 'configparam'

0 comments on commit 86ea110

Please sign in to comment.