pyNIBS pytest suite
Problem
pyNIBS uses global relative file paths in a couple of its pytests. Because pytest always resolves to the working directory from which it was started, it is recommended to use file paths relative to the test file instead. This will also make pyNIBS usable as a git submodule in the TMSflux project.
(All simNIBS pytest are passing, even in a git submodule configuration.)
Summary Log
-
test_simnibs_heavy.py -
[line 12] subj_mesh_dir = Path(file).parent / 'data'
-
[line 13/14] File inputs need to be swapped?
-
test_layer_generation.py -
[line 12] subj_mesh_dir = Path(file).parent / 'data'
-
test_merge_exp_data_brainsight.py -
[line 20] File 'testsub.sn4' not found. Could not find the file on git.
-
test_simnibs_heavy.py -
[line 43] calc_e_in_midlayer_roi() called with unexpected keywords.
Detailed pyNIBS pytest report
(tmsflux) ➜ pynibs git:(dev) ✗ pytest ============================================================================= test session starts ============================================================================= platform darwin -- Python 3.11.13, pytest-8.3.3, pluggy-1.6.0 rootdir: /Users/jonaswitt/Documents/Volunteering/MPI/tmsflux/external/pynibs configfile: pyproject.toml plugins: anyio-4.9.0 collected 115 itemstests/test_coil.py ............... [ 13%] tests/test_elements2nodes.py ..... [ 17%] tests/test_hdf5_io/test_xdmf.py .... [ 20%] tests/test_mesh_transformations.py ........ [ 27%] tests/test_mesh_utils.py ............ [ 38%] tests/test_neuron_regression/test_neuron.py FF. [ 40%] tests/test_neuron_regression/test_simnibs.py .. [ 42%] tests/test_nnav_imports.py ..... [ 46%] tests/test_optimization_multichannel.py ......... [ 54%] tests/test_quality_measures.py ...... [ 60%] tests/test_regressdata.py ....................... [ 80%] tests/test_roi.py .. [ 81%] tests/test_rotations.py ....... [ 87%] tests/test_subject.py ..... [ 92%] tests/test_util.py . [ 93%] tests_heavy/test_exp/test_merge_exp_data_brainsight.py F [ 93%] tests_heavy/test_layer_generation.py .... [ 97%] tests_heavy/test_simnibs_heavy.py F.. [100%]
================================================================================== FAILURES =================================================================================== ______________________________________________________________________ TestNeuron.test_calc_e_effective _______________________________________________________________________
self = <test_neuron.TestNeuron testMethod=test_calc_e_effective>
def test_calc_e_effective(self):
e_eff = pynibs.calc_e_effective(
self.test_data["mag_e"],
"L23",
self.test_data["theta"],
self.test_data["gradient"],
neuronmodel="sensitivity_weighting",
waveform="biphasic"
)
assert np.allclose(
e_eff,
self.ref_solutions['E_eff_theta_grad_biph']
), "Computed result does not match reference result when using 'theta' and 'gradient' (biphasic)!"
E AssertionError: Computed result does not match reference result when using 'theta' and 'gradient' (biphasic)! E assert False E + where False = <function allclose at 0x1039f3770>(array([[108.99286613, 85.96408903, 124.17195412, 98.8275486 ,\n 73.3491116 ],\n [144.52914589, 106.75814922, 111.12730748, 72.60687059,\n 86.49080839]]), array([[108.99286613, 85.96408903, 124.17195412, 98.8275486 ,\n 73.3491116 ],\n [144.53038703, 106.75814922, 111.11770803, 72.57034409,\n 86.49080839]])) E + where <function allclose at 0x1039f3770> = np.allclose
tests/test_neuron_regression/test_neuron.py:115: AssertionError _____________________________________________________________________ TestNeuron.test_calc_e_sensitivity ______________________________________________________________________
self = <test_neuron.TestNeuron testMethod=test_calc_e_sensitivity>
def test_calc_e_sensitivity(self):
e_sens = pynibs.calc_e_threshold(
"L23",
self.test_data["theta"],
self.test_data["gradient"],
neuronmodel="sensitivity_weighting",
waveform="biphasic"
)
assert np.allclose(
e_sens,
self.ref_solutions['E_sens_theta_grad_biph']
), "Computed result does not match reference result when using 'theta' and 'gradient' (biphasic)!"
E AssertionError: Computed result does not match reference result when using 'theta' and 'gradient' (biphasic)! E assert False E + where False = <function allclose at 0x1039f3770>(array([[0.91749124, 1.16327645, 0.80533483, 1.01186361, 1.36334303],\n [0.69190196, 0.93669664, 0.89986883, 1.37728013, 1.15619222]]), array([[0.91749124, 1.16327645, 0.80533483, 1.01186361, 1.36334303],\n [0.69189602, 0.93669664, 0.89994657, 1.37797335, 1.15619222]])) E + where <function allclose at 0x1039f3770> = np.allclose
tests/test_neuron_regression/test_neuron.py:66: AssertionError _____________________________________________________ TestMergeExpDataBrainsight.test_merge_exp_data_brainsight_simnibs4 ______________________________________________________
self = <test_merge_exp_data_brainsight.TestMergeExpDataBrainsight testMethod=test_merge_exp_data_brainsight_simnibs4>
def test_merge_exp_data_brainsight_simnibs4(self):
with tempfile.TemporaryDirectory() as tempdir:
###### preparation
testcase_sn4_name = os.path.basename(self.testcase_sn4)
# copy sample directories to temporary diretory
shutil.copytree(self.testcase_sn4, os.path.join(tempdir, testcase_sn4_name))
tests_heavy/test_exp/test_merge_exp_data_brainsight.py:28:
src = '/Users/jonaswitt/Documents/Volunteering/MPI/tmsflux/external/pynibs/tests_heavy/data/testsub.sn4' dst = '/var/folders/jd/9nq6c67n5bvdwdk8hpl02th40000gn/T/tmpi4ypoamz/testsub.sn4', symlinks = False, ignore = None, copy_function = <function copy2 at 0x101a79080> ignore_dangling_symlinks = False, dirs_exist_ok = False
def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2,
ignore_dangling_symlinks=False, dirs_exist_ok=False):
"""Recursively copy a directory tree and return the destination directory.
If exception(s) occur, an Error is raised with a list of reasons.
If the optional symlinks flag is true, symbolic links in the
source tree result in symbolic links in the destination tree; if
it is false, the contents of the files pointed to by symbolic
links are copied. If the file pointed by the symlink doesn't
exist, an exception will be added in the list of errors raised in
an Error exception at the end of the copy process.
You can set the optional ignore_dangling_symlinks flag to true if you
want to silence this exception. Notice that this has no effect on
platforms that don't support os.symlink.
The optional ignore argument is a callable. If given, it
is called with the `src` parameter, which is the directory
being visited by copytree(), and `names` which is the list of
`src` contents, as returned by os.listdir():
callable(src, names) -> ignored_names
Since copytree() is called recursively, the callable will be
called once for each directory that is copied. It returns a
list of names relative to the `src` directory that should
not be copied.
The optional copy_function argument is a callable that will be used
to copy each file. It will be called with the source path and the
destination path as arguments. By default, copy2() is used, but any
function that supports the same signature (like copy()) can be used.
If dirs_exist_ok is false (the default) and `dst` already exists, a
`FileExistsError` is raised. If `dirs_exist_ok` is true, the copying
operation will continue if it encounters existing directories, and files
within the `dst` tree will be overwritten by corresponding files from the
`src` tree.
"""
sys.audit("shutil.copytree", src, dst)
with os.scandir(src) as itr:
E FileNotFoundError: [Errno 2] No such file or directory: '/Users/jonaswitt/Documents/Volunteering/MPI/tmsflux/external/pynibs/tests_heavy/data/testsub.sn4'
/opt/anaconda3/envs/tmsflux/lib/python3.11/shutil.py:571: FileNotFoundError ________________________________________________________________ TestSimnibsHeavy.test_calc_e_in_midlayer_roi _________________________________________________________________
self = <test_simnibs_heavy.TestSimnibsHeavy testMethod=test_calc_e_in_midlayer_roi>
def test_calc_e_in_midlayer_roi(self):
qois = ['E', 'mag', 'norm', 'tan']
qois_in_midlayer = pynibs.calc_e_in_midlayer_roi(
subject=None,
phi_dadt=(self.volmesh.elmdata[0].value, self.volmesh.nodedata[0].value),
roi=self.roi,
phi_scaling = 1.,
mesh = self.volmesh,
qoi = qois,
)
E TypeError: calc_e_in_midlayer_roi() got an unexpected keyword argument 'subject'
tests_heavy/test_simnibs_heavy.py:43: TypeError ============================================================================== warnings summary =============================================================================== tests/test_elements2nodes.py::TestDataElements2Nodes::test_e2n_single_data_tri_zero /Users/jonaswitt/Documents/Volunteering/MPI/tmsflux/external/pynibs/pynibs/mesh/transformations.py:136: RuntimeWarning: Mean of empty slice. data_in_nodes.append(np.array([data_flat[con_flat == i].mean() for i in range(n_nodes)]))
tests/test_elements2nodes.py::TestDataElements2Nodes::test_e2n_single_data_tri_zero /opt/anaconda3/envs/tmsflux/lib/python3.11/site-packages/numpy/core/_methods.py:129: RuntimeWarning: invalid value encountered in scalar divide ret = ret.dtype.type(ret / rcount)
tests/test_nnav_imports.py::TestPyNIBSLocalite::test_read_triggermarker_localite_valid
/Users/jonaswitt/Documents/Volunteering/MPI/tmsflux/external/pynibs/pynibs/expio/localite.py:505: DeprecationWarning: This function is deprecated. Use read_triggermarker
instead.
warnings.warn("This function is deprecated. Use read_triggermarker
instead.", DeprecationWarning)
tests/test_nnav_imports.py::TestReadTargetsBrainsight::test_read_targets_brainsight /Users/jonaswitt/Documents/Volunteering/MPI/tmsflux/external/pynibs/pynibs/expio/brainsight.py:163: DeprecationWarning: This function is deprecated. Please use pynibs.brainsight.get_marker(markertype='Targets') instead. warnings.warn("This function is deprecated. Please use pynibs.brainsight.get_marker(markertype='Targets') instead.",
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html =========================================================================== short test summary info =========================================================================== FAILED tests/test_neuron_regression/test_neuron.py::TestNeuron::test_calc_e_effective - AssertionError: Computed result does not match reference result when using 'theta' and 'gradient' (biphasic)! FAILED tests/test_neuron_regression/test_neuron.py::TestNeuron::test_calc_e_sensitivity - AssertionError: Computed result does not match reference result when using 'theta' and 'gradient' (biphasic)! FAILED tests_heavy/test_exp/test_merge_exp_data_brainsight.py::TestMergeExpDataBrainsight::test_merge_exp_data_brainsight_simnibs4 - FileNotFoundError: [Errno 2] No such file or directory: '/Users/jonaswitt/Documents/Volunteering/MPI/tmsflux/external/pynibs/tests_heavy/data/testsub.sn4' FAILED tests_heavy/test_simnibs_heavy.py::TestSimnibsHeavy::test_calc_e_in_midlayer_roi - TypeError: calc_e_in_midlayer_roi() got an unexpected keyword argument 'subject' ================================================================= 4 failed, 111 passed, 4 warnings in 32.53s ==================================================================
Detailed simNIBS pytest report
`(tmsflux) ➜ simnibs git:(v4.5.0) pytest ============================================================================= test session starts ============================================================================= platform darwin -- Python 3.11.13, pytest-8.3.3, pluggy-1.6.0 rootdir: /Users/jonaswitt/Documents/Volunteering/MPI/tmsflux/external/simnibs configfile: pyproject.toml plugins: anyio-4.9.0 collected 2210 itemssimnibs/eeg/tests/test_forward.py . [ 0%] simnibs/eeg/tests/test_utils_fieldtrip.py .. [ 0%] simnibs/mesh_tools/tests/test_mesh_io.py .............................................................................................................................. [ 5%] .............................................s......................................... [ 9%] simnibs/mesh_tools/tests/test_meshing.py ............................ [ 11%] simnibs/mesh_tools/tests/test_msurface.py ........ [ 11%] simnibs/optimization/tes_flex_optimization/tests/test_array_layout.py ........ [ 11%] simnibs/optimization/tes_flex_optimization/tests/test_ellipsoid.py ... [ 11%] simnibs/optimization/tes_flex_optimization/tests/test_tes_flex_optimization.py .ssss...... [ 12%] simnibs/optimization/tests/test_ADMlib.py ........ [ 12%] simnibs/optimization/tests/test_opt_struct.py ......................................................................................................................... [ 18%] ....................... [ 19%] simnibs/optimization/tests/test_optimization_methods.py .............................................................. [ 22%] simnibs/optimization/tests/test_optimize_tms.py ...... [ 22%] simnibs/optimization/tests/test_tms_flex_optimization.py ........s..s... [ 23%] simnibs/segmentation/tests/test_brain_surface.py ............................ [ 24%] simnibs/segmentation/tests/test_cat_c_utils.py ........ [ 24%] simnibs/segmentation/tests/test_charm_utils.py ............... [ 25%] simnibs/segmentation/tests/test_marching_cube.py . [ 25%] simnibs/segmentation/tests/test_thickness.py .. [ 25%] simnibs/simulation/pygpc/tests/test_adaptive.py ........... [ 25%] simnibs/simulation/tests/test_analytical_solutions.py ............................. [ 27%] simnibs/simulation/tests/test_biot_savart.py ................. [ 28%] simnibs/simulation/tests/test_direct_solvers.py .ss..ss..ss.....sss [ 28%] simnibs/simulation/tests/test_electrode_placement.py ................ [ 29%] simnibs/simulation/tests/test_fem.py ................................................................. [ 32%] simnibs/simulation/tests/test_fem_target_point_cloud.py .. [ 32%] simnibs/simulation/tests/test_gpc.py .............. [ 33%] simnibs/simulation/tests/test_onlinefem.py ss..ss..ss..ss..ss..ss..ss..ss..ss..ss..ss..ss..ss..ss.. [ 35%] simnibs/simulation/tests/test_sim_struct.py .................... [ 36%] simnibs/simulation/tms_coil/tests/test_coil.py ......................................... [ 38%] simnibs/simulation/tms_coil/tests/test_coil_deformation.py ..................... [ 39%] simnibs/simulation/tms_coil/tests/test_coil_element.py ................................................................................................................ [ 44%] ....................................................................................................................................................................... [ 52%] ....................................................................................................................................................................... [ 59%] ....................................................................................................................................................................... [ 67%] ....................................................................................................................................................................... [ 74%] ....................................................................................................................................................................... [ 82%] ..................................................................................... [ 86%] simnibs/simulation/tms_coil/tests/test_coil_model.py ..... [ 86%] simnibs/simulation/tms_coil/tests/test_stimulator.py ........ [ 86%] simnibs/simulation/tms_coil/tests/test_tcd_json_schema.py .................................................... [ 89%] simnibs/utils/tests/test_TI_utils.py .... [ 89%] simnibs/utils/tests/test_cond_utils.py ............... [ 90%] simnibs/utils/tests/test_csv_reader.py ....... [ 90%] simnibs/utils/tests/test_file_finder.py ............................................................................. [ 93%] simnibs/utils/tests/test_itk_mesh_io.py .. [ 93%] simnibs/utils/tests/test_matlab_read.py ........ [ 94%] simnibs/utils/tests/test_nnav.py ........................ [ 95%] simnibs/utils/tests/test_region_of_interest.py ..s.s..........s............sssss...........s.......... [ 97%] simnibs/utils/tests/test_roi_result_visualization.py ....... [ 98%] simnibs/utils/tests/test_settings_reader.py . [ 98%] simnibs/utils/tests/test_spatial_transform.py ... [ 98%] simnibs/utils/tests/test_spawn_process.py .. [ 98%] simnibs/utils/tests/test_transformations.py ...................s.............. [100%]
============================================================================== warnings summary ===============================================================================
simnibs/simulation/tests/test_onlinefem.py: 12 warnings
UserWarning: solver pardiso
was specified but MKL PARDISO is not available for Darwin systems; falling back to MUMPS.
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html ========================================================== 2156 passed, 54 skipped, 12 warnings in 432.63s (0:07:12) ==========================================================`