Commit 04528289 authored by liadomide's avatar liadomide

TVB-2598 Review unit-tests after introduction of fixtures. Avoid unnecessary load from H5

parent d38bccc5
......@@ -33,8 +33,8 @@
import os
import tvb_data
from uuid import UUID
from tvb.adapters.datatypes.db.connectivity import ConnectivityIndex
from tvb.core.neocom import h5
from tvb.tests.framework.core.base_testcase import TransactionalTestCase
from tvb.core.entities.file.files_helper import FilesHelper
from tvb.adapters.visualizers.connectivity import ConnectivityViewer
......@@ -73,8 +73,7 @@ class TestConnectivityViewer(TransactionalTestCase):
"""
viewer = ConnectivityViewer()
view_model = viewer.get_view_model_class()()
connectivity = h5.load_from_index(self.connectivity_index)
view_model.connectivity = connectivity.gid
view_model.connectivity = UUID(self.connectivity_index.gid)
result = viewer.launch(view_model)
expected_keys = ['weightsMin', 'weightsMax', 'urlWeights', 'urlVertices',
'urlTriangles', 'urlTracts', 'urlPositions', 'urlNormals',
......
......@@ -31,12 +31,9 @@
"""
.. moduleauthor:: Bogdan Neacsa <bogdan.neacsa@codemart.ro>
"""
from tvb.core.neocom import h5
from uuid import UUID
from tvb.tests.framework.core.base_testcase import TransactionalTestCase
from tvb.core.entities.file.files_helper import FilesHelper
from tvb.adapters.visualizers.covariance import CovarianceVisualizer
from tvb.tests.framework.core.factory import TestFactory
class TestCovarianceViewer(TransactionalTestCase):
......@@ -44,32 +41,14 @@ class TestCovarianceViewer(TransactionalTestCase):
Unit-tests for Covariance Viewer.
"""
def transactional_setup_method(self):
"""
Sets up the environment for running the tests;
creates a test user, a test project, a connectivity and a surface;
imports a CFF data-set
"""
self.test_user = TestFactory.create_user("Covariance_Viewer_User")
self.test_project = TestFactory.create_project(self.test_user, "Covariance_Viewer_Project")
def transactional_teardown_method(self):
"""
Clean-up tests data
"""
FilesHelper().remove_project_structure(self.test_project.name)
def test_launch(self, covariance_factory):
"""
Check that all required keys are present in output from BrainViewer launch.
Check that all required keys are present in output from CovarianceVisualizer launch.
"""
covariance_index = covariance_factory()
covariance = h5.load_from_index(covariance_index)
viewer = CovarianceVisualizer()
view_model = viewer.get_view_model_class()()
view_model.datatype = covariance.gid
view_model.datatype = UUID(covariance_index.gid)
result = viewer.launch(view_model)
expected_keys = ['matrix_shape', 'matrix_data', 'mainContent', 'isAdapter']
for key in expected_keys:
......
......@@ -32,11 +32,9 @@
.. moduleauthor:: Bogdan Neacsa <bogdan.neacsa@codemart.ro>
"""
from tvb.core.neocom import h5
from uuid import UUID
from tvb.tests.framework.core.base_testcase import TransactionalTestCase
from tvb.core.entities.file.files_helper import FilesHelper
from tvb.adapters.visualizers.cross_coherence import CrossCoherenceVisualizer
from tvb.tests.framework.core.factory import TestFactory
class TestCrossCoherenceViewer(TransactionalTestCase):
......@@ -44,30 +42,14 @@ class TestCrossCoherenceViewer(TransactionalTestCase):
Unit-tests for Cross Coherence Viewer.
"""
def transactional_setup_method(self):
"""
Sets up the environment for running the tests;
creates a test user, a test project, a connectivity and a surface;
imports a CFF data-set
"""
self.test_user = TestFactory.create_user('Cross_Coherence_Viewer_User')
self.test_project = TestFactory.create_project(self.test_user, "Cross_Coherence_Viewer__Project")
def transactional_teardown_method(self):
"""
Clean-up tests data
"""
FilesHelper().remove_project_structure(self.test_project.name)
def test_launch(self, cross_coherence_factory):
"""
Check that all required keys are present in output from BrainViewer launch.
"""
cross_coherence_index = cross_coherence_factory()
cross_coherence = h5.load_from_index(cross_coherence_index)
viewer = CrossCoherenceVisualizer()
view_model = viewer.get_view_model_class()()
view_model.datatype = cross_coherence.gid
view_model.datatype = UUID(cross_coherence_index.gid)
result = viewer.launch(view_model)
expected_keys = ['matrix_data', 'matrix_shape', 'frequency']
for key in expected_keys:
......
......@@ -32,11 +32,9 @@
.. moduleauthor:: Bogdan Neacsa <bogdan.neacsa@codemart.ro>
"""
from tvb.core.neocom import h5
from uuid import UUID
from tvb.tests.framework.core.base_testcase import TransactionalTestCase
from tvb.core.entities.file.files_helper import FilesHelper
from tvb.adapters.visualizers.cross_correlation import CrossCorrelationVisualizer
from tvb.tests.framework.core.factory import TestFactory
class TestCrossCorrelationViewer(TransactionalTestCase):
......@@ -44,33 +42,15 @@ class TestCrossCorrelationViewer(TransactionalTestCase):
Unit-tests for Cross Correlation Viewer.
"""
def transactional_setup_method(self):
"""
Sets up the environment for running the tests;
creates a test user, a test project, a connectivity and a surface;
imports a CFF data-set
"""
self.test_user = TestFactory.create_user("Cross_Corelation_Viewer_User")
self.test_project = TestFactory.create_project(self.test_user, "Cross_Corelation_Viewer_Project")
def transactional_teardown_method(self):
"""
Clean-up tests data
"""
FilesHelper().remove_project_structure(self.test_project.name)
def test_launch(self, cross_correlation_factory):
"""
Check that all required keys are present in output from BrainViewer launch.
Check that all required keys are present in output from CrossCorrelationVisualizer launch.
"""
cross_correlation_index = cross_correlation_factory()
cross_correlation = h5.load_from_index(cross_correlation_index)
viewer = CrossCorrelationVisualizer()
view_model = viewer.get_view_model_class()()
view_model.datatype = cross_correlation.gid
view_model.datatype = UUID(cross_correlation_index.gid)
result = viewer.launch(view_model)
expected_keys = ['matrix_shape', 'matrix_data', 'mainContent', 'isAdapter']
for key in expected_keys:
assert key in result
......@@ -32,42 +32,24 @@
"""
import json
from tvb.core.neocom import h5
from uuid import UUID
from tvb.tests.framework.core.base_testcase import TransactionalTestCase
from tvb.core.entities.file.files_helper import FilesHelper
from tvb.adapters.visualizers.eeg_monitor import EegMonitor
from tvb.tests.framework.core.factory import TestFactory
class TestEEGMonitor(TransactionalTestCase):
"""
Unit-tests for EEG Viewer.
"""
def transactional_setup_method(self):
"""
Sets up the environment for running the tests;
creates a test user, a test project, a connectivity and a surface;
imports a CFF data-set
"""
self.test_user = TestFactory.create_user("EEG_Monitor_User")
self.test_project = TestFactory.create_project(self.test_user, "EEG_Monitor_Project")
def transactional_teardown_method(self):
"""
Clean-up tests data
"""
FilesHelper().remove_project_structure(self.test_project.name)
def test_launch(self, time_series_index_factory):
"""
Check that all required keys are present in output from BrainViewer launch.
Check that all required keys are present in output from EegMonitor launch.
"""
time_series_index = time_series_index_factory()
time_series = h5.load_from_index(time_series_index)
viewer = EegMonitor()
view_model = viewer.get_view_model_class()()
view_model.input_data = time_series.gid
view_model.input_data = UUID(time_series_index.gid)
result = viewer.launch(view_model)
expected_keys = ['tsNames', 'groupedLabels', 'tsModes', 'tsStateVars', 'longestChannelLength',
'label_x', 'entities', 'page_size', 'number_of_visible_points',
......
......@@ -32,11 +32,9 @@
.. moduleauthor:: Bogdan Neacsa <bogdan.neacsa@codemart.ro>
"""
from tvb.core.entities.file.files_helper import FilesHelper
from tvb.core.neocom import h5
from uuid import UUID
from tvb.tests.framework.core.base_testcase import TransactionalTestCase
from tvb.adapters.visualizers.ica import ICA
from tvb.tests.framework.core.factory import TestFactory
class TestICA(TransactionalTestCase):
......@@ -44,32 +42,14 @@ class TestICA(TransactionalTestCase):
Unit-tests for ICA Viewer.
"""
def transactional_setup_method(self):
"""
Sets up the environment for running the tests;
creates a test user, a test project, a connectivity and a surface;
imports a CFF data-set
"""
self.test_user = TestFactory.create_user("Cross_Corelation_Viewer_User")
self.test_project = TestFactory.create_project(self.test_user, "Cross_Corelation_Viewer_Project")
def transactional_teardown_method(self):
"""
Clean-up tests data
"""
FilesHelper().remove_project_structure(self.test_project.name)
def test_launch(self, ica_factory):
"""
Check that all required keys are present in output from BrainViewer launch.
Check that all required keys are present in output from ICA launch.
"""
ica_index = ica_factory()
ica = h5.load_from_index(ica_index)
viewer = ICA()
view_model = viewer.get_view_model_class()()
view_model.datatype = ica.gid
view_model.datatype = UUID(ica_index.gid)
result = viewer.launch(view_model)
expected_keys = ['matrix_shape', 'matrix_data', 'mainContent', 'isAdapter']
for key in expected_keys:
......
......@@ -33,19 +33,18 @@
"""
import os
from tvb.adapters.datatypes.db.sensors import SensorsIndex
from tvb.adapters.datatypes.db.surface import SurfaceIndex
from tvb.core.entities.filters.chain import FilterChain
from tvb.core.neocom import h5
from tvb.tests.framework.core.base_testcase import TransactionalTestCase
import tvb_data.obj
import tvb_data.sensors
from uuid import UUID
from tvb.adapters.datatypes.db.sensors import SensorsIndex
from tvb.adapters.datatypes.db.surface import SurfaceIndex
from tvb.adapters.uploaders.sensors_importer import SensorsImporterModel
from tvb.adapters.visualizers.sensors import SensorsViewer
from tvb.core.entities.filters.chain import FilterChain
from tvb.core.entities.file.files_helper import FilesHelper
from tvb.datatypes.sensors import EEG_POLYMORPHIC_IDENTITY, \
MEG_POLYMORPHIC_IDENTITY
from tvb.datatypes.sensors import EEG_POLYMORPHIC_IDENTITY, MEG_POLYMORPHIC_IDENTITY
from tvb.datatypes.surfaces import EEG_CAP
from tvb.tests.framework.core.base_testcase import TransactionalTestCase
from tvb.tests.framework.core.factory import TestFactory
......@@ -90,7 +89,6 @@ class TestSensorViewers(TransactionalTestCase):
field = FilterChain.datatype + '.sensors_type'
filters = FilterChain('', [field], [EEG_POLYMORPHIC_IDENTITY], ['=='])
sensors_index = TestFactory.get_entity(self.test_project, SensorsIndex, filters)
sensors = h5.load_from_index(sensors_index)
# Import EEGCap
cap_path = os.path.join(os.path.dirname(tvb_data.obj.__file__), 'eeg_cap.obj')
......@@ -98,11 +96,10 @@ class TestSensorViewers(TransactionalTestCase):
field = FilterChain.datatype + '.surface_type'
filters = FilterChain('', [field], [EEG_CAP], ['=='])
eeg_cap_surface_index = TestFactory.get_entity(self.test_project, SurfaceIndex, filters)
eeg_cap_surface = h5.load_from_index(eeg_cap_surface_index)
viewer = SensorsViewer()
view_model = viewer.get_view_model_class()()
view_model.sensors = sensors.gid
view_model.sensors = UUID(sensors_index.gid)
viewer.current_project_id = self.test_project.id
# Launch without EEG Cap
......@@ -110,7 +107,7 @@ class TestSensorViewers(TransactionalTestCase):
self.assert_compliant_dictionary(self.EXPECTED_KEYS_EEG, result)
# Launch with EEG Cap selected
view_model.shell_surface = eeg_cap_surface.gid
view_model.shell_surface = UUID(eeg_cap_surface_index.gid)
result = viewer.launch(view_model)
self.assert_compliant_dictionary(self.EXPECTED_KEYS_EEG, result)
for key in ['urlVertices', 'urlTriangles', 'urlLines', 'urlNormals']:
......@@ -128,12 +125,11 @@ class TestSensorViewers(TransactionalTestCase):
field = FilterChain.datatype + '.sensors_type'
filters = FilterChain('', [field], [MEG_POLYMORPHIC_IDENTITY], ['=='])
sensors_index = TestFactory.get_entity(self.test_project, SensorsIndex, filters)
sensors = h5.load_from_index(sensors_index)
viewer = SensorsViewer()
viewer.current_project_id = self.test_project.id
view_model = viewer.get_view_model_class()()
view_model.sensors = sensors.gid
view_model.sensors = UUID(sensors_index.gid)
result = viewer.launch(view_model)
self.assert_compliant_dictionary(self.EXPECTED_KEYS_MEG, result)
......@@ -145,12 +141,10 @@ class TestSensorViewers(TransactionalTestCase):
zip_path = os.path.join(os.path.dirname(tvb_data.sensors.__file__), 'seeg_39.txt.bz2')
sensors_index = TestFactory.import_sensors(self.test_user, self.test_project, zip_path,
SensorsImporterModel.OPTIONS['Internal Sensors'])
sensors = h5.load_from_index(sensors_index)
viewer = SensorsViewer()
viewer.current_project_id = self.test_project.id
view_model = viewer.get_view_model_class()()
view_model.sensors = sensors.gid
view_model.sensors = UUID(sensors_index.gid)
result = viewer.launch(view_model)
self.assert_compliant_dictionary(self.EXPECTED_KEYS_INTERNAL, result)
......@@ -34,13 +34,13 @@
import os
import tvb_data.surfaceData
import tvb_data.regionMapping as demo_data
from uuid import UUID
from tvb.adapters.datatypes.db.connectivity import ConnectivityIndex
from tvb.core.neocom import h5
from tvb.tests.framework.core.base_testcase import TransactionalTestCase
from tvb.adapters.visualizers.surface_view import SurfaceViewer, RegionMappingViewer
from tvb.core.entities.file.files_helper import FilesHelper
from tvb.datatypes.surfaces import CORTICAL
import tvb_data.regionMapping as demo_data
from tvb.tests.framework.core.base_testcase import TransactionalTestCase
from tvb.tests.framework.core.factory import TestFactory
......@@ -60,24 +60,22 @@ class TestSurfaceViewers(TransactionalTestCase):
creates a test user, a test project, a connectivity and a surface;
imports a CFF data-set
"""
self.test_user = TestFactory.create_user('Surface_Viewer_User')
self.test_project = TestFactory.create_project(self.test_user, 'Surface_Viewer_Project')
test_user = TestFactory.create_user('Surface_Viewer_User')
self.test_project = TestFactory.create_project(test_user, 'Surface_Viewer_Project')
surf_skull = os.path.join(os.path.dirname(tvb_data.surfaceData.__file__), 'cortex_16384.zip')
surface_index = TestFactory.import_surface_zip(self.test_user, self.test_project, surf_skull, CORTICAL)
assert surface_index is not None
self.surface = h5.load_from_index(surface_index)
self.surface = TestFactory.import_surface_zip(test_user, self.test_project, surf_skull, CORTICAL)
assert self.surface is not None
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")
self.connectivity_index = TestFactory.get_entity(self.test_project, ConnectivityIndex)
assert self.connectivity_index is not None
TestFactory.import_zip_connectivity(test_user, self.test_project, zip_path, "John")
connectivity_index = TestFactory.get_entity(self.test_project, ConnectivityIndex)
assert connectivity_index is not None
TXT_FILE = os.path.join(os.path.dirname(demo_data.__file__), 'regionMapping_16k_76.txt')
region_mapping_index = TestFactory.import_region_mapping(self.test_user, self.test_project, TXT_FILE,
surface_index.gid, self.connectivity_index.gid)
assert region_mapping_index is not None
self.region_mapping = h5.load_from_index(region_mapping_index)
self.region_mapping = TestFactory.import_region_mapping(test_user, self.test_project, TXT_FILE,
self.surface.gid, connectivity_index.gid)
assert self.region_mapping is not None
def transactional_teardown_method(self):
"""
......@@ -92,8 +90,8 @@ class TestSurfaceViewers(TransactionalTestCase):
viewer = SurfaceViewer()
viewer.current_project_id = self.test_project.id
view_model = viewer.get_view_model_class()()
view_model.surface = self.surface.gid
view_model.region_map = self.region_mapping.gid
view_model.surface = UUID(self.surface.gid)
view_model.region_map = UUID(self.region_mapping.gid)
result = viewer.launch(view_model)
self.assert_compliant_dictionary(self.EXPECTED_KEYS, result)
......@@ -105,7 +103,7 @@ class TestSurfaceViewers(TransactionalTestCase):
viewer = RegionMappingViewer()
viewer.current_project_id = self.test_project.id
view_model = viewer.get_view_model_class()()
view_model.region_map = self.region_mapping.gid
view_model.region_map = UUID(self.region_mapping.gid)
result = viewer.launch(view_model)
self.assert_compliant_dictionary(self.EXPECTED_KEYS, result)
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