Commit d38bccc5 authored by liadomide's avatar liadomide

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

parent 19e977d0
......@@ -33,13 +33,15 @@
"""
import os
from uuid import UUID
import tvb_data.surfaceData
import tvb_data.regionMapping as demo_data
from tests.framework.conftest import time_series_region_index_factory, operation_factory
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.datatypes.surfaces import CORTICAL
from tvb.adapters.visualizers.brain import BrainViewer, DualBrainViewer, ConnectivityIndex, TimeSeries
from tvb.adapters.visualizers.brain import BrainViewer, DualBrainViewer, ConnectivityIndex
from tvb.tests.framework.core.factory import TestFactory
......@@ -55,7 +57,6 @@ class TestBrainViewer(TransactionalTestCase):
'extended_view', 'legendLabels', 'labelsStateVar', 'labelsModes', 'title']
face = os.path.join(os.path.dirname(tvb_data.surfaceData.__file__), 'cortex_16384.zip')
region_mapping_path = os.path.join(os.path.dirname(demo_data.__file__), 'regionMapping_16k_76.txt')
def transactional_setup_method(self):
......@@ -70,13 +71,19 @@ class TestBrainViewer(TransactionalTestCase):
zip_path = os.path.join(os.path.dirname(tvb_data.__file__), 'connectivity', 'connectivity_96.zip')
TestFactory.import_zip_connectivity(self.test_user, self.test_project, zip_path, "John")
self.connectivity = TestFactory.get_entity(self.test_project, ConnectivityIndex)
assert self.connectivity is not None
connectivity_idx = TestFactory.get_entity(self.test_project, ConnectivityIndex)
assert connectivity_idx is not None
self.face_surface = TestFactory.import_surface_zip(self.test_user, self.test_project, self.face, CORTICAL)
self.region_mapping = TestFactory.import_region_mapping(self.test_user, self.test_project,
self.region_mapping_path, self.face_surface.gid, self.connectivity.gid)
region_mapping = TestFactory.import_region_mapping(self.test_user, self.test_project,
self.region_mapping_path, self.face_surface.gid,
connectivity_idx.gid)
conn = h5.load_from_index(connectivity_idx)
rm = h5.load_from_index(region_mapping)
self.time_series_index = time_series_region_index_factory(
operation_factory(None, None)(test_user=self.test_user, test_project=self.test_project))(conn, rm)
def transactional_teardown_method(self):
"""
......@@ -84,66 +91,52 @@ class TestBrainViewer(TransactionalTestCase):
"""
FilesHelper().remove_project_structure(self.test_project.name)
def test_launch(self, time_series_region_index_factory):
def test_launch(self):
"""
Check that all required keys are present in output from BrainViewer launch.
"""
conn = h5.load_from_index(self.connectivity)
rm = h5.load_from_index(self.region_mapping)
time_series_index = time_series_region_index_factory(conn, rm)
time_series = h5.load_from_index(time_series_index)
viewer = BrainViewer()
viewer.current_project_id = self.test_project.id
view_model = viewer.get_view_model_class()()
view_model.time_series = time_series.gid
surface = h5.load_from_index(self.face_surface)
view_model.shell_surface = surface.gid
view_model.time_series = UUID(self.time_series_index.gid)
view_model.shell_surface = UUID(self.face_surface.gid)
result = viewer.launch(view_model)
for key in TestBrainViewer.EXPECTED_KEYS + TestBrainViewer.EXPECTED_EXTRA_KEYS:
assert key in result and result[key] is not None
assert not result['extended_view']
def test_get_required_memory(self, time_series_region_index_factory):
def test_get_required_memory(self):
"""
Brainviewer should know required memory so expect positive number and not -1.
"""
conn = h5.load_from_index(self.connectivity)
rm = h5.load_from_index(self.region_mapping)
time_series_index = time_series_region_index_factory(conn, rm)
time_series = h5.load_from_index(time_series_index)
viewer = BrainViewer()
viewer.current_project_id = self.test_project.id
view_model = viewer.get_view_model_class()()
view_model.time_series = time_series.gid
view_model.time_series = UUID(self.time_series_index.gid)
assert viewer.get_required_memory_size(view_model) > 0
def test_generate_preview(self, time_series_region_index_factory):
def test_generate_preview(self):
"""
Check that all required keys are present in preview generate by BrainViewer.
"""
conn = h5.load_from_index(self.connectivity)
rm = h5.load_from_index(self.region_mapping)
time_series = time_series_region_index_factory(conn, rm)
viewer = BrainViewer()
result = viewer.generate_preview(time_series, figure_size=(500, 200))
viewer.current_project_id = self.test_project.id
view_model = viewer.get_view_model_class()()
view_model.time_series = UUID(self.time_series_index.gid)
result = viewer.generate_preview(view_model, figure_size=(500, 200))
for key in TestBrainViewer.EXPECTED_KEYS:
assert key in result and result[key] is not None, key
def test_launch_eeg(self, time_series_region_index_factory):
def test_launch_eeg(self):
"""
Tests successful launch of a BrainEEG and that all required keys are present in returned template dictionary
"""
conn = h5.load_from_index(self.connectivity)
rm = h5.load_from_index(self.region_mapping)
time_series_index = time_series_region_index_factory(conn, rm)
time_series = h5.load_from_index(time_series_index)
viewer = DualBrainViewer()
viewer.current_project_id = self.test_project.id
view_model = viewer.get_view_model_class()()
view_model.time_series = time_series.gid
surface = h5.load_from_index(self.face_surface)
view_model.shell_surface = surface.gid
view_model.time_series = UUID(self.time_series_index.gid)
view_model.shell_surface = UUID(self.face_surface.gid)
result = viewer.launch(view_model)
for key in TestBrainViewer.EXPECTED_KEYS + TestBrainViewer.EXPECTED_EXTRA_KEYS:
assert key in result and result[key] is not None
......
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