Commit 7aaa71f7 authored by liadomide's avatar liadomide

TVB-2598 Avoid read from H5 when only GID is necessary

parent 03718e9e
......@@ -74,7 +74,7 @@ class TestNIFTIImporter(TransactionalTestCase):
zip_path = os.path.join(os.path.dirname(tvb_data.__file__), 'connectivity', 'connectivity_76.zip')
TestFactory.import_zip_connectivity(self.test_user, self.test_project, zip_path, "John")
connectivity_index = TestFactory.get_entity(self.test_project, ConnectivityIndex)
self.connectivity = h5.load_from_index(connectivity_index)
self.connectivity_gid = connectivity_index.gid
def transactional_teardown_method(self):
"""
......@@ -82,22 +82,22 @@ class TestNIFTIImporter(TransactionalTestCase):
"""
FilesHelper().remove_project_structure(self.test_project.name)
def _import(self, import_file_path=None, expected_result_class=StructuralMRIIndex, connectivity=None):
def _import(self, import_file_path=None, expected_result_class=StructuralMRIIndex, connectivity_gid=None):
"""
This method is used for importing data in NIFIT format
:param import_file_path: absolute path of the file to be imported
"""
### Retrieve Adapter instance
# Retrieve Adapter instance
importer = TestFactory.create_adapter('tvb.adapters.uploaders.nifti_importer', 'NIFTIImporter')
form = NIFTIImporterForm()
form.fill_from_post({'_data_file': Part(import_file_path, HeaderMap({}), ''),
'_apply_corrections': 'True',
'_connectivity': connectivity.gid.hex if connectivity else None,
'_connectivity': connectivity_gid,
'_mappings_file': Part(self.TXT_FILE, HeaderMap({}), ''),
'_Data_Subject': 'bla bla'
})
})
form.data_file.data = import_file_path
form.mappings_file.data = self.TXT_FILE
view_model = form.get_view_model()()
......@@ -105,8 +105,7 @@ class TestNIFTIImporter(TransactionalTestCase):
form.fill_trait(view_model)
importer.submit_form(form)
### Launch import Operation
# Launch import Operation
FlowService().fire_operation(importer, self.test_user, self.test_project.id, view_model=view_model)
dts, count = dao.get_values_of_datatype(self.test_project.id, expected_result_class, None)
......@@ -120,7 +119,7 @@ class TestNIFTIImporter(TransactionalTestCase):
"""
This method tests import of a NIFTI file.
"""
time_series_index = self._import(self.TIMESERIES_NII_FILE, TimeSeriesVolumeIndex, self.connectivity)
time_series_index = self._import(self.TIMESERIES_NII_FILE, TimeSeriesVolumeIndex, self.connectivity_gid)
# Since self.assertAlmostEquals is not available on all machine
# We compare floats as following
......@@ -144,7 +143,7 @@ class TestNIFTIImporter(TransactionalTestCase):
"""
This method tests import of a NIFTI file.
"""
structural_mri_index = self._import(self.NII_FILE, connectivity=self.connectivity)
structural_mri_index = self._import(self.NII_FILE, connectivity_gid=self.connectivity_gid)
assert "T1" == structural_mri_index.weighting
structural_mri = h5.load_from_index(structural_mri_index)
......@@ -168,7 +167,7 @@ class TestNIFTIImporter(TransactionalTestCase):
"""
This method tests import of a NIFTI file compressed in GZ format.
"""
structure = self._import(self.GZ_NII_FILE, connectivity=self.connectivity)
structure = self._import(self.GZ_NII_FILE, connectivity_gid=self.connectivity_gid)
assert "T1" == structure.weighting
def test_import_region_mapping(self):
......@@ -176,7 +175,7 @@ class TestNIFTIImporter(TransactionalTestCase):
This method tests import of a NIFTI file compressed in GZ format.
"""
to_link_conn = TestFactory.get_entity(self.test_project, ConnectivityIndex)
mapping_index = self._import(self.GZ_NII_FILE, RegionVolumeMappingIndex, self.connectivity)
mapping_index = self._import(self.GZ_NII_FILE, RegionVolumeMappingIndex, self.connectivity_gid)
mapping = h5.load_from_index(mapping_index)
......@@ -207,4 +206,3 @@ class TestNIFTIImporter(TransactionalTestCase):
except OperationException:
# Expected exception
pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment