Ejemplo n.º 1
0
def update():
    """
    Update TVB code to SVN revision version 4455.
    This update was done for release 1.0.2.
    """
    projects_count = dao.get_all_projects(is_count=True)

    for page_start in range(0, projects_count, PAGE_SIZE):
        projects_page = dao.get_all_projects(page_start=page_start,
                                             page_size=PAGE_SIZE)

        for project in projects_page:
            try:
                user = dao.get_system_user()
                adapter = ObjSurfaceImporter()
                OperationService().fire_operation(adapter,
                                                  user,
                                                  project.id,
                                                  visible=False,
                                                  surface_type=EEG_CAP,
                                                  data_file=DATA_FILE_EEG_CAP)
                adapter = ObjSurfaceImporter()
                OperationService().fire_operation(adapter,
                                                  user,
                                                  project.id,
                                                  visible=False,
                                                  surface_type=FACE,
                                                  data_file=DATA_FILE_FACE)
            except Exception as excep:
                LOGGER.exception(excep)

    TvbProfile.current.manager.add_entries_to_config_file(
        {stored.KEY_MATLAB_EXECUTABLE: get_matlab_executable()})
Ejemplo n.º 2
0
 def dec(*args, **kwargs):
     session_maker = SessionMaker()
     cfg.ALLOW_NESTED_TRANSACTIONS = True
     default_dir = cfg.CURRENT_DIR
     default_mlab_exe = cfg.MATLAB_EXECUTABLE
     cfg.MATLAB_EXECUTABLE = get_matlab_executable()
     session_maker.start_transaction()
     try:
         try:
             if hasattr(args[0], 'setUpTVB'):
                 args[0].setUpTVB()
             result = func(*args, **kwargs)
         finally:
             if hasattr(args[0], 'tearDownTVB'):
                 args[0].tearDownTVB()
                 args[0].delete_project_folders()
     finally:
         session_maker.rollback_transaction()
         session_maker.close_transaction()
         cfg.ALLOW_NESTED_TRANSACTIONS = False
         cfg.MATLAB_EXECUTABLE = default_mlab_exe
         cfg.CURRENT_DIR = default_dir
     if callback is not None:
         callback(*args, **kwargs)
     return result
Ejemplo n.º 3
0
    def initialize_profile(self, change_logger_in_dev=False):
        super(
            TestSQLiteProfile,
            self).initialize_profile(change_logger_in_dev=change_logger_in_dev)

        from tvb.core.utils import get_matlab_executable
        self.MATLAB_EXECUTABLE = get_matlab_executable()
Ejemplo n.º 4
0
def init_test_env():
    """
        This method prepares all necessary data for tests execution
    """
    default_mlab_exe = cfg.MATLAB_EXECUTABLE
    cfg.MATLAB_EXECUTABLE = get_matlab_executable()
    reset_database()
    initialize(["tvb.config", "tvb_test"], load_xml_events=False)
    cfg.MATLAB_EXECUTABLE = default_mlab_exe
    def test_check_matlab_path(self):
        """
        Test that for a various Matlab paths, the correct check response is returned.
        """
        submit_data = {stored.KEY_MATLAB_EXECUTABLE: get_matlab_executable()}
        result = json.loads(self.settings_c.validate_matlab_path(**submit_data))
        self.assertEqual(result['status'], 'ok')

        submit_data[stored.KEY_MATLAB_EXECUTABLE] = "/this/path/should/be/invalid"
        result = json.loads(self.settings_c.validate_matlab_path(**submit_data))
        self.assertEqual(result['status'], 'not ok')
Ejemplo n.º 6
0
from tvb.core.utils import get_matlab_executable
from tvb.core.services.event_handlers import handle_event
from tvb.core.entities.storage import dao


LOGGER = get_logger(__name__)
PAGE_SIZE = 20
EVENT_FILE_IDENTIFIER = "CodeVersionsManager.update.4455"


def update():
    """
    Update TVB code to SVN revision version 4455.
    This update was done for release 1.0.2.
    """
    projects_count = dao.get_all_projects(is_count=True)
    
    for page_start in range(0, projects_count, PAGE_SIZE):
        projects_page = dao.get_all_projects(page_start=page_start,
                                             page_end=min(page_start + PAGE_SIZE, projects_count))
        
        for project in projects_page:
            try:
                handle_event(EVENT_FILE_IDENTIFIER, dao.get_system_user(), project)
            except Exception, excep:
                LOGGER.exception(excep)
                
    TvbProfile.current.manager.add_entries_to_config_file({stored.KEY_MATLAB_EXECUTABLE: get_matlab_executable()})
    
    
    
Ejemplo n.º 7
0
class BCTTest(TransactionalTestCase):
    """
    Test that all BCT analyzers are executed without error.
    We do not verify that the algorithms are correct, because that is outside the purpose of TVB framework.
    """
    EXPECTED_TO_FAIL_VALIDATION = [
        "CentralityKCoreness", "CentralityEigenVector",
        "ClusteringCoefficientBU", "ClusteringCoefficientWU",
        "TransitivityBinaryUnDirected", "TransitivityWeightedUnDirected"
    ]

    @unittest.skipIf(get_matlab_executable() is None,
                     "Matlab or Octave not installed!")
    def setUp(self):
        """
        Sets up the environment for running the tests;
        creates a test user, a test project, a connectivity and a list of BCT adapters;
        imports a CFF data-set
        """
        self.test_user = TestFactory.create_user("BCT_User")
        self.test_project = TestFactory.create_project(self.test_user,
                                                       "BCT-Project")
        ### Make sure Connectivity is in DB
        TestFactory.import_cff(test_user=self.test_user,
                               test_project=self.test_project)
        self.connectivity = dao.get_generic_entity(Connectivity, 'John Doe',
                                                   'subject')[0]

        # make weights matrix symmetric, or else some BCT algorithms will run infinitely:
        w = self.connectivity.weights
        self.connectivity.weights = w + w.T - numpy.diag(w.diagonal())

        algorithms = dao.get_generic_entity(model.Algorithm,
                                            'Brain Connectivity Toolbox',
                                            'group_description')
        self.assertTrue(algorithms is not None)
        self.assertTrue(len(algorithms) > 5)

        self.bct_adapters = []
        for algo in algorithms:
            self.bct_adapters.append(ABCAdapter.build_adapter(algo))

    def tearDown(self):
        """
        Cleans the database after the tests
        """
        self.clean_database(True)

    @unittest.skipIf(get_matlab_executable() is None,
                     "Matlab or Octave not installed!")
    def test_bct_all(self):
        """
        Iterate all BCT algorithms and execute them.
        """
        for adapter_instance in self.bct_adapters:
            algorithm = adapter_instance.stored_adapter
            operation = TestFactory.create_operation(
                algorithm=algorithm,
                test_user=self.test_user,
                test_project=self.test_project,
                operation_status=model.STATUS_STARTED)
            self.assertEqual(model.STATUS_STARTED, operation.status)
            ### Launch BCT algorithm
            submit_data = {algorithm.parameter_name: self.connectivity.gid}
            try:
                OperationService().initiate_prelaunch(operation,
                                                      adapter_instance, {},
                                                      **submit_data)
                if algorithm.classname in BCTTest.EXPECTED_TO_FAIL_VALIDATION:
                    raise Exception(
                        "Algorithm %s was expected to throw input validation "
                        "exception, but did not!" % (algorithm.classname, ))

                operation = dao.get_operation_by_id(operation.id)
                ### Check that operation status after execution is success.
                self.assertEqual(STATUS_FINISHED, operation.status)
                ### Make sure at least one result exists for each BCT algorithm
                results = dao.get_generic_entity(model.DataType, operation.id,
                                                 'fk_from_operation')
                self.assertTrue(len(results) > 0)

            except InvalidParameterException, excep:
                ## Some algorithms are expected to throw validation exception.
                if algorithm.classname not in BCTTest.EXPECTED_TO_FAIL_VALIDATION:
                    raise excep
from tvb.core.utils import get_matlab_executable
from tvb.core.services.event_handlers import handle_event
from tvb.core.entities.storage import dao


LOGGER = get_logger(__name__)
PAGE_SIZE = 20
EVENT_FILE_IDENTIFIER = "CodeVersionsManager.update.4455"


def update():
    """
    Update TVB code to SVN revision version 4455.
    This update was done for release 1.0.2.
    """
    projects_count = dao.get_all_projects(is_count=True)
    
    for page_start in range(0, projects_count, PAGE_SIZE):
        projects_page = dao.get_all_projects(page_start=page_start,
                                             page_end=min(page_start + PAGE_SIZE, projects_count))
        
        for project in projects_page:
            try:
                handle_event(EVENT_FILE_IDENTIFIER, dao.get_system_user(), project)
            except Exception, excep:
                LOGGER.exception(excep)
                
    cfg.add_entries_to_config_file({cfg.KEY_MATLAB_EXECUTABLE: get_matlab_executable()})
    
    
    
Ejemplo n.º 9
0
    def initialize_profile(self, change_logger_in_dev=False):
        super(TestSQLiteProfile, self).initialize_profile(change_logger_in_dev=change_logger_in_dev)

        from tvb.core.utils import get_matlab_executable
        self.MATLAB_EXECUTABLE = get_matlab_executable()
Ejemplo n.º 10
0
import cherrypy
import shutil
from types import FunctionType
from tvb.basic.config.utils import EnhancedDictionary
from tvb.basic.config.settings import TVBSettings as cfg
from tvb.basic.logger.builder import get_logger
from tvb.core.utils import get_matlab_executable
from tvb.core.entities.storage import dao
from tvb.core.entities.storage.sessionmaker import SessionMaker
from tvb.core.entities import model
from tvb.core.entities.modelmanager import reset_database
from tvb.core.services.initializer import initialize
from tvb.core.services.operationservice import OperationService

LOGGER = get_logger(__name__)
MATLAB_EXECUTABLE = get_matlab_executable()


def init_test_env():
    """
        This method prepares all necessary data for tests execution
    """
    default_mlab_exe = cfg.MATLAB_EXECUTABLE
    cfg.MATLAB_EXECUTABLE = get_matlab_executable()
    reset_database()
    initialize(["tvb.config", "tvb_test"], load_xml_events=False)
    cfg.MATLAB_EXECUTABLE = default_mlab_exe


def transactional_test(func, callback=None):
    """
class SettingsControllerTest(BaseTransactionalControllerTest):
    """
    Unit tests for SettingsController class
    """

    was_reset = False
    accepted_db_url = ('sqlite:///TestFolder' + os.path.sep + 'tvb-database.db'
                       if TvbProfile.current.db.SELECTED_DB == 'sqlite'
                       else TvbProfile.current.db.DB_URL)

    VALID_SETTINGS = {'TVB_STORAGE': "TestFolder",
                      'USR_DISK_SPACE': 1,
                      'MAXIMUM_NR_OF_THREADS': 6,
                      'MAXIMUM_NR_OF_VERTICES_ON_SURFACE': 142,
                      'MAXIMUM_NR_OF_OPS_IN_RANGE': 16,
                      'MATLAB_EXECUTABLE': '',

                      'DEPLOY_CLUSTER': 'True',
                      'SELECTED_DB': TvbProfile.current.db.SELECTED_DB,  # Not changeable,due to test profile overwrites
                      'URL_VALUE': accepted_db_url,

                      'URL_WEB': "http://*****:*****@test.test'}


    def setUp(self):

        self.init(with_data=False)
        self.settings_c = SettingsController()
        self.assertTrue(TvbProfile.is_first_run())


    def tearDown(self):
        """ Cleans the testing environment """
        self.cleanup()

        if os.path.exists(self.VALID_SETTINGS['TVB_STORAGE']):
            shutil.rmtree(self.VALID_SETTINGS['TVB_STORAGE'])


    def test_with_invalid_admin_settings(self):

        self._assert_invalid_parameters({'ADMINISTRATOR_NAME': '',
                                         'ADMINISTRATOR_PASSWORD': '',
                                         'ADMINISTRATOR_EMAIL': ''})

        self._assert_invalid_parameters({'ADMINISTRATOR_EMAIL': "bla.com"})


    def test_with_invalid_web_settings(self):

        self._assert_invalid_parameters({'URL_WEB': '',
                                         'WEB_SERVER_PORT': 'a'})

        self._assert_invalid_parameters({'URL_WEB': 'off://bla',
                                         'WEB_SERVER_PORT': '70000'})


    def test_with_invalid_settings(self):

        self._assert_invalid_parameters({'TVB_STORAGE': '',
                                         'SELECTED_DB': '',
                                         'URL_VALUE': ''})

        self._assert_invalid_parameters({'USR_DISK_SPACE': '',
                                         'MAXIMUM_NR_OF_THREADS': '0',
                                         'MAXIMUM_NR_OF_VERTICES_ON_SURFACE': '-1',
                                         'MAXIMUM_NR_OF_OPS_IN_RANGE': '2'})

        self._assert_invalid_parameters({'USR_DISK_SPACE': 'a',
                                         'MAXIMUM_NR_OF_THREADS': '20',
                                         'MAXIMUM_NR_OF_VERTICES_ON_SURFACE': str(256 * 256 * 256 + 1),
                                         'MAXIMUM_NR_OF_OPS_IN_RANGE': '10000'})

        self._assert_invalid_parameters({'MAXIMUM_NR_OF_THREADS': 'c',
                                         'MAXIMUM_NR_OF_VERTICES_ON_SURFACE': 'b',
                                         'MAXIMUM_NR_OF_OPS_IN_RANGE': 'a'})


    def _assert_invalid_parameters(self, params_dictionary):
        """
        Simulate submit of a given params (key:value) and check that they are found in the error response
        """
        submit_data = copy.copy(self.VALID_SETTINGS)
        for key, value in params_dictionary.iteritems():
            submit_data[key] = value

        response = self.settings_c.settings(save_settings=True, **submit_data)

        self.assertTrue(common.KEY_ERRORS in response)
        for key in params_dictionary:
            self.assertTrue(key in response[common.KEY_ERRORS], "Not found in errors %s" % key)


    def test_with_valid_settings(self):

        submit_data = self.VALID_SETTINGS
        self.settings_c._restart_services = self._fake_restart_services

        self.assertRaises(cherrypy.HTTPRedirect, self.settings_c.settings, save_settings=True, **self.VALID_SETTINGS)

        # wait until 'restart' is done
        sleep(1)
        self.assertTrue(self.was_reset)
        self.assertEqual(16, len(TvbProfile.current.manager.stored_settings))

        self.assertEqual(submit_data['TVB_STORAGE'], TvbProfile.current.TVB_STORAGE)
        self.assertEqual(submit_data['USR_DISK_SPACE'] * 2 ** 10, TvbProfile.current.MAX_DISK_SPACE)
        self.assertEqual(submit_data['MAXIMUM_NR_OF_THREADS'], TvbProfile.current.MAX_THREADS_NUMBER)
        self.assertEqual(submit_data['MAXIMUM_NR_OF_OPS_IN_RANGE'], TvbProfile.current.MAX_RANGE_NUMBER)
        self.assertEqual(submit_data['MAXIMUM_NR_OF_VERTICES_ON_SURFACE'],
                         TvbProfile.current.MAX_SURFACE_VERTICES_NUMBER)

        self.assertEqual(submit_data['DEPLOY_CLUSTER'], str(TvbProfile.current.cluster.IS_DEPLOY))
        self.assertEqual(submit_data['SELECTED_DB'], TvbProfile.current.db.SELECTED_DB)
        self.assertEqual(submit_data['URL_VALUE'], TvbProfile.current.db.DB_URL)

        self.assertEqual(submit_data['URL_WEB'], TvbProfile.current.web.BASE_URL)
        self.assertEqual(submit_data['WEB_SERVER_PORT'], TvbProfile.current.web.SERVER_PORT)

        self.assertEqual(submit_data['ADMINISTRATOR_NAME'], TvbProfile.current.web.admin.ADMINISTRATOR_NAME)
        self.assertEqual(submit_data['ADMINISTRATOR_EMAIL'], TvbProfile.current.web.admin.ADMINISTRATOR_EMAIL)
        self.assertEqual(md5(submit_data['ADMINISTRATOR_PASSWORD']).hexdigest(),
                         TvbProfile.current.web.admin.ADMINISTRATOR_PASSWORD)


    def _fake_restart_services(self, should_reset):
        """
        This function will replace the SettingsController._restart_service method,
        to avoid problems in tests due to restart.
        """
        self.was_reset = should_reset
        TvbProfile._build_profile_class(TvbProfile.CURRENT_PROFILE_NAME)


    def test_check_db_url(self):
        """
        Test that for a various DB URLs, the correct check response is returned.
        """
        submit_data = {stored.KEY_STORAGE: TvbProfile.current.TVB_STORAGE,
                       stored.KEY_DB_URL: TvbProfile.current.db.DB_URL}
        result = json.loads(self.settings_c.check_db_url(**submit_data))
        self.assertEqual(result['status'], 'ok')

        submit_data[stored.KEY_DB_URL] = "this URL should be invalid"
        result = json.loads(self.settings_c.check_db_url(**submit_data))
        self.assertEqual(result['status'], 'not ok')


    @unittest.skipIf(get_matlab_executable() is None, "Matlab or Octave not installed!")
    def test_check_matlab_path(self):
        """
        Test that for a various Matlab paths, the correct check response is returned.
        """
        submit_data = {stored.KEY_MATLAB_EXECUTABLE: get_matlab_executable()}
        result = json.loads(self.settings_c.validate_matlab_path(**submit_data))
        self.assertEqual(result['status'], 'ok')

        submit_data[stored.KEY_MATLAB_EXECUTABLE] = "/this/path/should/be/invalid"
        result = json.loads(self.settings_c.validate_matlab_path(**submit_data))
        self.assertEqual(result['status'], 'not ok')
def update():
    """
    Update TVB code to SVN revision version 4455.
    This update was done for release 1.0.2.
    """
    projects_count = dao.get_all_projects(is_count=True)
    
    for page_start in range(0, projects_count, PAGE_SIZE):
        projects_page = dao.get_all_projects(page_start=page_start, page_size=PAGE_SIZE)
        
        for project in projects_page:
            try:
                user = dao.get_system_user()
                adapter = ObjSurfaceImporter()
                FlowService().fire_operation(adapter, user, project.id, visible=False,
                                             surface_type=EEG_CAP, data_file=DATA_FILE_EEG_CAP)
                adapter = ObjSurfaceImporter()
                FlowService().fire_operation(adapter, user, project.id, visible=False,
                                             surface_type=FACE, data_file=DATA_FILE_FACE)
            except Exception as excep:
                LOGGER.exception(excep)
                
    TvbProfile.current.manager.add_entries_to_config_file({stored.KEY_MATLAB_EXECUTABLE: get_matlab_executable()})
    
    
    
Ejemplo n.º 13
0
 def __init__(self):
     self.logger = get_logger(__name__)
     first_run = TvbProfile.is_first_run()
     storage = TvbProfile.current.TVB_STORAGE if not first_run else TvbProfile.current.DEFAULT_STORAGE
     self.configurable_keys = {
         self.KEY_STORAGE: {
             'label': 'Root folder for all projects',
             'value': storage,
             'readonly': not first_run,
             'type': 'text'
         },
         self.KEY_MAX_DISK_SPACE_USR: {
             'label': 'Max hard disk space per user (MBytes)',
             'value': TvbProfile.current.MAX_DISK_SPACE / 2**10,
             'type': 'text'
         },
         self.KEY_MATLAB_EXECUTABLE: {
             'label':
             'Optional Matlab or Octave path',
             'type':
             'text',
             'value':
             TvbProfile.current.MATLAB_EXECUTABLE
             or get_matlab_executable() or '',
             'description':
             'Some analyzers will not be available when '
             'matlab/octave are not found'
         },
         self.KEY_SELECTED_DB: {
             'label': 'Select one DB engine',
             'value': TvbProfile.current.db.SELECTED_DB,
             'type': 'select',
             'readonly': not first_run,
             'options': TvbProfile.current.db.ACEEPTED_DBS
         },
         self.KEY_DB_URL: {
             'label':
             "DB connection URL",
             'value':
             TvbProfile.current.db.ACEEPTED_DBS[
                 TvbProfile.current.db.SELECTED_DB],
             'type':
             'text',
             'readonly':
             TvbProfile.current.db.SELECTED_DB == 'sqlite'
         },
         self.KEY_PORT: {
             'label': 'Port to run Cherrypy on',
             'value': TvbProfile.current.web.SERVER_PORT,
             'dtype': 'primitive',
             'type': 'text'
         },
         self.KEY_PORT_MPLH5: {
             'label': 'Port to run Matplotlib on',
             'type': 'text',
             'dtype': 'primitive',
             'value': TvbProfile.current.web.MPLH5_SERVER_PORT
         },
         self.KEY_URL_WEB: {
             'label': 'URL for accessing web',
             'value': TvbProfile.current.web.BASE_URL,
             'type': 'text',
             'dtype': 'primitive'
         },
         self.KEY_URL_MPLH5: {
             'label': 'URL for accessing MPLH5 visualizers',
             'type': 'text',
             'value': TvbProfile.current.web.MPLH5_SERVER_URL,
             'dtype': 'primitive'
         },
         self.KEY_MAX_NR_THREADS: {
             'label': 'Maximum no. of threads for local installations',
             'type': 'text',
             'value': TvbProfile.current.MAX_THREADS_NUMBER,
             'dtype': 'primitive'
         },
         self.KEY_MAX_RANGE: {
             'label': 'Maximum no. of operations in one PSE',
             'description':
             "Parameters Space Exploration (PSE) maximum number of operations",
             'value': TvbProfile.current.MAX_RANGE_NUMBER,
             'type': 'text',
             'dtype': 'primitive'
         },
         self.KEY_MAX_NR_SURFACE_VERTEX: {
             'label': 'Maximum no. of vertices in a surface',
             'type': 'text',
             'dtype': 'primitive',
             'value': TvbProfile.current.MAX_SURFACE_VERTICES_NUMBER
         },
         self.KEY_CLUSTER: {
             'label': 'Deploy on cluster',
             'value': TvbProfile.current.cluster.IS_DEPLOY,
             'description':
             'Check this only if on the web-server machine OARSUB command is enabled.',
             'dtype': 'primitive',
             'type': 'boolean'
         },
         self.KEY_ADMIN_NAME: {
             'label':
             'Administrator User Name',
             'value':
             TvbProfile.current.web.admin.ADMINISTRATOR_NAME,
             'type':
             'text',
             'readonly':
             not first_run,
             'description':
             ('Password and Email can be edited after first run, '
              'from the profile page directly.')
         },
         self.KEY_ADMIN_PWD: {
             'label':
             'Password',
             'value':
             TvbProfile.current.web.admin.ADMINISTRATOR_BLANK_PWD
             if first_run else
             TvbProfile.current.web.admin.ADMINISTRATOR_PASSWORD,
             'type':
             'password',
             'readonly':
             not first_run
         },
         self.KEY_ADMIN_EMAIL: {
             'label': 'Administrator Email',
             'value': TvbProfile.current.web.admin.ADMINISTRATOR_EMAIL,
             'readonly': not first_run,
             'type': 'text'
         }
     }
Ejemplo n.º 14
0
                    operation = dao.get_operation_by_id(operation.id)
                    ### Check that operation status after execution is success.
                    self.assertEqual(STATUS_FINISHED, operation.status)
                    ### Make sure at least one result exists for each BCT algorithm
                    results = dao.get_generic_entity(model.DataType,
                                                     operation.id,
                                                     'fk_from_operation')
                    self.assertTrue(len(results) > 0)

                except InvalidParameterException, excep:
                    ## Some algorithms are expected to throw validation exception.
                    if bct_identifier not in BCTTest.EXPECTED_TO_FAIL_VALIDATION:
                        raise excep

    @unittest.skipIf(get_matlab_executable() is None,
                     "Matlab or Octave not installed!")
    def test_bct_descriptions(self):
        """
        Iterate all BCT algorithms and check description not empty.
        """
        for i in xrange(len(self.bct_adapters)):
            for bct_identifier in self.bct_adapters[
                    i].get_algorithms_dictionary():
                ### Prepare Operation and parameters
                algorithm = dao.get_algorithm_by_group(self.algo_groups[i].id,
                                                       bct_identifier)
                self.assertTrue(
                    len(algorithm.description) > 0,
                    "Description was not loaded properly for algorithm %s" %
                    (str(algorithm, )))
Ejemplo n.º 15
0
                                    "exception, but did not!" % (algorithm.classname,))

                operation = dao.get_operation_by_id(operation.id)
                ### Check that operation status after execution is success.
                self.assertEqual(STATUS_FINISHED, operation.status)
                ### Make sure at least one result exists for each BCT algorithm
                results = dao.get_generic_entity(model.DataType, operation.id, 'fk_from_operation')
                self.assertTrue(len(results) > 0)

            except InvalidParameterException, excep:
                ## Some algorithms are expected to throw validation exception.
                if algorithm.classname not in BCTTest.EXPECTED_TO_FAIL_VALIDATION:
                    raise excep


    @unittest.skipIf(get_matlab_executable() is None, "Matlab or Octave not installed!")
    def test_bct_descriptions(self):
        """
        Iterate all BCT algorithms and check that description has been extracted from *.m files.
        """
        for adapter_instance in self.bct_adapters:
            self.assertTrue(len(adapter_instance.stored_adapter.description) > 10,
                            "Description was not loaded properly for algorithm %s" % (str(adapter_instance)))


def suite():
    """
    Gather all the tests in a test suite.
    """
    test_suite = unittest.TestSuite()
    test_suite.addTest(unittest.makeSuite(BCTTest))
Ejemplo n.º 16
0
from tvb.basic.logger.builder import get_logger
from tvb.basic.config.settings import TVBSettings as cfg
from tvb.core.utils import get_matlab_executable
from tvb.core.entities.storage import dao


LOGGER = get_logger(__name__)
PAGE_SIZE = 20
EVENT_FILE_IDENTIFIER = "CodeVersionsManager.update.4455"


def update():
    """
    Update TVB code to SVN revision version 4455.
    This update was done for release 1.0.2.
    """
    projects_count = dao.get_all_projects(is_count=True)
    
    for page_start in range(0, projects_count, PAGE_SIZE):
        projects_page = dao.get_all_projects(page_start=page_start, page_end=min(page_start +PAGE_SIZE, projects_count))
        
        for project in projects_page:
            try:
                eventhandler.handle_event(EVENT_FILE_IDENTIFIER, dao.get_system_user(), project)
            except Exception, excep:
                LOGGER.exception(excep)
                
    cfg.add_entries_to_config_file({cfg.KEY_MATLAB_EXECUTABLE : get_matlab_executable()})
    
    
    
Ejemplo n.º 17
0
class TestBCT(TransactionalTestCase):
    """
    Test that all BCT analyzers are executed without error.
    We do not verify that the algorithms are correct, because that is outside the purpose of TVB framework.
    """

    @pytest.mark.skipif(get_matlab_executable() is None, reason="Matlab or Octave not installed!")
    def transactional_setup_method(self):
        """
        Sets up the environment for running the tests;
        creates a test user, a test project, a connectivity and a list of BCT adapters;
        imports a CFF data-set
        """
        self.test_user = TestFactory.create_user("BCT_User")
        self.test_project = TestFactory.create_project(self.test_user, "BCT-Project")
        # Make sure Connectivity is in DB
        zip_path = os.path.join(os.path.dirname(tvb_data.__file__), 'connectivity', 'connectivity_76.zip')
        self.connectivity = TestFactory.import_zip_connectivity(self.test_user, self.test_project, zip_path)

        algorithms = dao.get_generic_entity(Algorithm, 'Brain Connectivity Toolbox', 'group_description')
        assert algorithms is not None
        assert len(algorithms) > 5

        self.bct_adapters = []
        for algo in algorithms:
            self.bct_adapters.append(ABCAdapter.build_adapter(algo))

    def transactional_teardown_method(self):
        """
        Cleans the database after the tests
        """
        self.clean_database(True)

    @pytest.mark.skipif(get_matlab_executable() is None, reason="Matlab or Octave not installed!")
    def test_bct_all(self):
        """
        Iterate all BCT algorithms and execute them.
        """
        service = OperationService()
        algo_category = dao.get_category_by_id(self.bct_adapters[0].stored_adapter.fk_category)
        for adapter_instance in self.bct_adapters:
            algorithm = adapter_instance.stored_adapter
            view_model = BaseBCTModel()
            view_model.connectivity = self.connectivity.gid

            # Avoid the scheduled execution, as this is asynch, thus launch it immediately
            operation = service.prepare_operations(self.test_user.id, self.test_project, algorithm, algo_category,
                                                   {}, True, view_model=view_model)[0][0]
            service.initiate_prelaunch(operation, adapter_instance)

            operation = dao.get_operation_by_id(operation.id)
            # Check that operation status after execution is success.
            assert STATUS_FINISHED == operation.status
            # Make sure at least one result exists for each BCT algorithm
            results = dao.get_generic_entity(DataType, operation.id, 'fk_from_operation')
            assert len(results) > 0

    @pytest.mark.skipif(get_matlab_executable() is None, reason="Matlab or Octave not installed!")
    def test_bct_descriptions(self):
        """
        Iterate all BCT algorithms and check that description has been extracted from *.m files.
        """
        for adapter_instance in self.bct_adapters:
            assert len(adapter_instance.stored_adapter.description) > 10, "Description was not loaded properly for " \
                                                                          "algorithm %s" % (str(adapter_instance))
Ejemplo n.º 18
0
class BCTTest(TransactionalTestCase):
    """
    Test that all BCT analyzers are executed without error.
    We do not verify that the algorithms are correct, because that is outside the purpose of TVB framework.
    """
    EXPECTED_TO_FAIL_VALIDATION = [
        "CCBU", "CCWU", "EIGUN", "KCCBU", "TBU", "TWU"
    ]

    @unittest.skipIf(get_matlab_executable() is None,
                     "Matlab or Octave not installed!")
    def setUp(self):
        """
        Sets up the environment for running the tests;
        creates a test user, a test project, a connectivity and a list of BCT adapters;
        imports a CFF data-set
        """
        self.test_user = TestFactory.create_user("BCT_User")
        self.test_project = TestFactory.create_project(self.test_user,
                                                       "BCT-Project")
        ### Make sure Connectivity is in DB
        TestFactory.import_cff(test_user=self.test_user,
                               test_project=self.test_project)
        self.connectivity = dao.get_generic_entity(Connectivity, 'John Doe',
                                                   'subject')[0]

        # make weights matrix symmetric, or else some BCT algorithms will run infinitely:
        w = self.connectivity.weights
        self.connectivity.weights = w + w.T - numpy.diag(w.diagonal())

        self.algo_groups = dao.get_generic_entity(model.AlgorithmGroup,
                                                  'MatlabAdapter', 'classname')

        self.assertTrue(self.algo_groups is not None)
        self.assertEquals(6, len(self.algo_groups))
        self.bct_adapters = []
        for group in self.algo_groups:
            self.bct_adapters.append(
                TestFactory.create_adapter(group, self.test_project))

    def tearDown(self):
        """
        Cleans the database after the tests
        """
        self.clean_database(True)

    @unittest.skipIf(get_matlab_executable() is None,
                     "Matlab or Octave not installed!")
    def test_bct_all(self):
        """
        Iterate all BCT algorithms and execute them.
        """
        for i in xrange(len(self.bct_adapters)):
            for bct_identifier in self.bct_adapters[
                    i].get_algorithms_dictionary():
                ### Prepare Operation and parameters
                algorithm = dao.get_algorithm_by_group(self.algo_groups[i].id,
                                                       bct_identifier)
                operation = TestFactory.create_operation(
                    algorithm=algorithm,
                    test_user=self.test_user,
                    test_project=self.test_project,
                    operation_status=model.STATUS_STARTED)
                self.assertEqual(model.STATUS_STARTED, operation.status)
                ### Launch BCT algorithm
                submit_data = {
                    self.algo_groups[i].algorithm_param_name: bct_identifier,
                    algorithm.parameter_name: self.connectivity.gid
                }
                try:
                    OperationService().initiate_prelaunch(
                        operation, self.bct_adapters[i], {}, **submit_data)
                    if bct_identifier in BCTTest.EXPECTED_TO_FAIL_VALIDATION:
                        raise Exception(
                            "Algorithm %s was expected to throw input validation "
                            "exception, but did not!" % (bct_identifier, ))

                    operation = dao.get_operation_by_id(operation.id)
                    ### Check that operation status after execution is success.
                    self.assertEqual(STATUS_FINISHED, operation.status)
                    ### Make sure at least one result exists for each BCT algorithm
                    results = dao.get_generic_entity(model.DataType,
                                                     operation.id,
                                                     'fk_from_operation')
                    self.assertTrue(len(results) > 0)

                except InvalidParameterException, excep:
                    ## Some algorithms are expected to throw validation exception.
                    if bct_identifier not in BCTTest.EXPECTED_TO_FAIL_VALIDATION:
                        raise excep
    def __init__(self):
        self.logger = get_logger(__name__)
        first_run = TvbProfile.is_first_run()
        storage = TvbProfile.current.TVB_STORAGE if not first_run else TvbProfile.current.DEFAULT_STORAGE
        self.configurable_keys = {
            self.KEY_STORAGE: {'label': 'Root folder for all projects', 'value': storage,
                               'readonly': not first_run, 'type': 'text'},
            self.KEY_MAX_DISK_SPACE_USR: {'label': 'Max hard disk space per user (MBytes)',
                                          'value': TvbProfile.current.MAX_DISK_SPACE / 2 ** 10, 'type': 'text'},
            self.KEY_MATLAB_EXECUTABLE: {'label': 'Optional Matlab or Octave path', 'type': 'text',
                                         'value': TvbProfile.current.MATLAB_EXECUTABLE or get_matlab_executable() or '',
                                         'description': 'Some analyzers will not be available when '
                                                        'matlab/octave are not found'},
            self.KEY_SELECTED_DB: {'label': 'Select one DB engine', 'value': TvbProfile.current.db.SELECTED_DB,
                                   'type': 'select', 'readonly': not first_run,
                                   'options': TvbProfile.current.db.ACEEPTED_DBS},
            self.KEY_DB_URL: {'label': "DB connection URL",
                              'value': TvbProfile.current.db.ACEEPTED_DBS[TvbProfile.current.db.SELECTED_DB],
                              'type': 'text', 'readonly': TvbProfile.current.db.SELECTED_DB == 'sqlite'},

            self.KEY_PORT: {'label': 'Port to run Cherrypy on',
                            'value': TvbProfile.current.web.SERVER_PORT, 'dtype': 'primitive', 'type': 'text'},
            self.KEY_URL_WEB: {'label': 'URL for accessing web',
                               'value': TvbProfile.current.web.BASE_URL, 'type': 'text', 'dtype': 'primitive'},

            self.KEY_MAX_NR_THREADS: {'label': 'Maximum no. of threads for local installations', 'type': 'text',
                                      'value': TvbProfile.current.MAX_THREADS_NUMBER, 'dtype': 'primitive'},
            self.KEY_MAX_RANGE: {'label': 'Maximum no. of operations in one PSE',
                                 'description': "Parameters Space Exploration (PSE) maximum number of operations",
                                 'value': TvbProfile.current.MAX_RANGE_NUMBER, 'type': 'text', 'dtype': 'primitive'},
            self.KEY_MAX_NR_SURFACE_VERTEX: {'label': 'Maximum no. of vertices in a surface',
                                             'type': 'text', 'dtype': 'primitive',
                                             'value': TvbProfile.current.MAX_SURFACE_VERTICES_NUMBER},
            self.KEY_CLUSTER: {'label': 'Deploy on cluster', 'value': TvbProfile.current.cluster.IS_DEPLOY,
                               'description': 'Check this only if on the web-server machine OARSUB command is enabled.',
                               'dtype': 'primitive', 'type': 'boolean'},
            self.KEY_ADMIN_NAME: {'label': 'Administrator User Name',
                                  'value': TvbProfile.current.web.admin.ADMINISTRATOR_NAME,
                                  'type': 'text', 'readonly': not first_run,
                                  'description': ('Password and Email can be edited after first run, '
                                                  'from the profile page directly.')},
            self.KEY_ADMIN_PWD: {'label': 'Password',
                                 'value': TvbProfile.current.web.admin.ADMINISTRATOR_BLANK_PWD if first_run
                                 else TvbProfile.current.web.admin.ADMINISTRATOR_PASSWORD,
                                 'type': 'password', 'readonly': not first_run},
            self.KEY_ADMIN_EMAIL: {'label': 'Administrator Email',
                                   'value': TvbProfile.current.web.admin.ADMINISTRATOR_EMAIL,
                                   'readonly': not first_run, 'type': 'text'}}
Ejemplo n.º 20
0
from tvb.basic.profile import TvbProfile
from tvb.core.utils import get_matlab_executable
from tvb.core.services.event_handlers import handle_event
from tvb.core.entities.storage import dao

LOGGER = get_logger(__name__)
PAGE_SIZE = 20
EVENT_FILE_IDENTIFIER = "CodeVersionsManager.update.4455"


def update():
    """
    Update TVB code to SVN revision version 4455.
    This update was done for release 1.0.2.
    """
    projects_count = dao.get_all_projects(is_count=True)

    for page_start in range(0, projects_count, PAGE_SIZE):
        projects_page = dao.get_all_projects(page_start=page_start,
                                             page_size=PAGE_SIZE)

        for project in projects_page:
            try:
                handle_event(EVENT_FILE_IDENTIFIER, dao.get_system_user(),
                             project)
            except Exception, excep:
                LOGGER.exception(excep)

    TvbProfile.current.manager.add_entries_to_config_file(
        {stored.KEY_MATLAB_EXECUTABLE: get_matlab_executable()})
Ejemplo n.º 21
0
class TestSettingsController(BaseTransactionalControllerTest):
    """
    Unit tests for SettingsController class
    """

    was_reset = False
    storage = str(Path.home()) + os.path.sep + "TestFolder"
    accepted_db_url = ('sqlite:///' + storage + os.path.sep +
                       'tvb-database.db' if TvbProfile.current.db.SELECTED_DB
                       == 'sqlite' else TvbProfile.current.db.DB_URL)

    VALID_SETTINGS = {
        'KEYCLOAK_CONFIGURATION':
        storage + os.path.sep + 'keycloak-config.json',
        'KEYCLOAK_WEB_CONFIGURATION':
        storage + os.path.sep + 'keycloak-web-config.json',
        'TVB_STORAGE': storage,
        'USR_DISK_SPACE': 1,
        'MAXIMUM_NR_OF_THREADS': 6,
        'MAXIMUM_NR_OF_VERTICES_ON_SURFACE': 142,
        'MAXIMUM_NR_OF_OPS_IN_RANGE': 16,
        'MATLAB_EXECUTABLE': '',
        'DEPLOY_CLUSTER': 'True',
        'CLUSTER_SCHEDULER': TvbProfile.current.cluster.SCHEDULER_OAR,
        'SELECTED_DB': TvbProfile.current.db.
        SELECTED_DB,  # Not changeable,due to test profile overwrites
        'URL_VALUE': accepted_db_url,
        'WEB_SERVER_PORT': 9999,
        'ADMINISTRATOR_NAME': 'test_admin',
        'ADMINISTRATOR_DISPLAY_NAME': 'test_Administrator',
        'ADMINISTRATOR_PASSWORD': "******",
        'ADMINISTRATOR_EMAIL': '*****@*****.**'
    }

    def transactional_setup_method(self):

        self.init(with_data=False)
        self.settings_c = SettingsController()
        assert TvbProfile.is_first_run()

    def transactional_teardown_method(self):
        """ Cleans the testing environment """
        self.cleanup()
        self.clean_database()

        if os.path.exists(self.VALID_SETTINGS['TVB_STORAGE']):
            shutil.rmtree(self.VALID_SETTINGS['TVB_STORAGE'])

    def test_with_invalid_admin_settings(self):

        self._assert_invalid_parameters({
            'ADMINISTRATOR_NAME': '',
            'ADMINISTRATOR_PASSWORD': '',
            'ADMINISTRATOR_EMAIL': ''
        })

        self._assert_invalid_parameters({'ADMINISTRATOR_EMAIL': "bla.com"})

    def test_with_invalid_web_settings(self):

        self._assert_invalid_parameters({'WEB_SERVER_PORT': 'a'})

        self._assert_invalid_parameters({'WEB_SERVER_PORT': '70000'})

    def test_with_invalid_settings(self):

        self._assert_invalid_parameters({
            'TVB_STORAGE': '',
            'SELECTED_DB': '',
            'URL_VALUE': ''
        })

        self._assert_invalid_parameters({
            'USR_DISK_SPACE': '',
            'MAXIMUM_NR_OF_THREADS': '0',
            'MAXIMUM_NR_OF_VERTICES_ON_SURFACE': '-1',
            'MAXIMUM_NR_OF_OPS_IN_RANGE': '2'
        })

        self._assert_invalid_parameters({
            'USR_DISK_SPACE':
            'a',
            'MAXIMUM_NR_OF_THREADS':
            '20',
            'MAXIMUM_NR_OF_VERTICES_ON_SURFACE':
            str(256 * 256 * 256 + 1),
            'MAXIMUM_NR_OF_OPS_IN_RANGE':
            '10000'
        })

        self._assert_invalid_parameters({
            'MAXIMUM_NR_OF_THREADS': 'c',
            'MAXIMUM_NR_OF_VERTICES_ON_SURFACE': 'b',
            'MAXIMUM_NR_OF_OPS_IN_RANGE': 'a'
        })

    def _assert_invalid_parameters(self, params_dictionary):
        """
        Simulate submit of a given params (key:value) and check that they are found in the error response
        """
        submit_data = copy.copy(self.VALID_SETTINGS)
        for key, value in params_dictionary.items():
            submit_data[key] = value

        response = self.settings_c.settings(save_settings=True, **submit_data)

        assert common.KEY_ERRORS in response
        for key in params_dictionary:
            assert key in response[
                common.KEY_ERRORS], "Not found in errors %s" % key

    def test_with_valid_settings(self):
        # Ensure we submit acceptable values, depending on the current profile (set-up after fixtures execution)
        submit_data = copy.copy(self.VALID_SETTINGS)
        accepted_db_url = ('sqlite:///' + self.storage + os.path.sep +
                           'tvb-database.db'
                           if TvbProfile.current.db.SELECTED_DB == 'sqlite'
                           else TvbProfile.current.db.DB_URL)
        submit_data['SELECTED_DB'] = TvbProfile.current.db.SELECTED_DB
        submit_data['URL_VALUE'] = accepted_db_url

        self.settings_c._restart_services = self._fake_restart_services

        with pytest.raises(cherrypy.HTTPRedirect):
            self.settings_c.settings(save_settings=True, **self.VALID_SETTINGS)

        # wait until 'restart' is done
        sleep(1)
        assert self.was_reset
        assert len(TvbProfile.current.manager.stored_settings) == 21

        assert submit_data['TVB_STORAGE'] == TvbProfile.current.TVB_STORAGE
        assert submit_data[
            'USR_DISK_SPACE'] * 2**10 == TvbProfile.current.MAX_DISK_SPACE
        assert submit_data[
            'MAXIMUM_NR_OF_THREADS'] == TvbProfile.current.MAX_THREADS_NUMBER
        assert submit_data[
            'MAXIMUM_NR_OF_OPS_IN_RANGE'] == TvbProfile.current.MAX_RANGE_NUMBER
        assert submit_data[
            'MAXIMUM_NR_OF_VERTICES_ON_SURFACE'] == TvbProfile.current.MAX_SURFACE_VERTICES_NUMBER

        assert submit_data['DEPLOY_CLUSTER'] == str(
            TvbProfile.current.cluster.IS_DEPLOY)
        assert submit_data['SELECTED_DB'] == TvbProfile.current.db.SELECTED_DB
        assert submit_data['URL_VALUE'] == TvbProfile.current.db.DB_URL

        assert submit_data[
            'WEB_SERVER_PORT'] == TvbProfile.current.web.SERVER_PORT

        assert submit_data[
            'ADMINISTRATOR_NAME'] == TvbProfile.current.web.admin.ADMINISTRATOR_NAME
        assert submit_data[
            'ADMINISTRATOR_EMAIL'] == TvbProfile.current.web.admin.ADMINISTRATOR_EMAIL
        assert hash_password(
            submit_data['ADMINISTRATOR_PASSWORD']
        ) == TvbProfile.current.web.admin.ADMINISTRATOR_PASSWORD

    def _fake_restart_services(self, should_reset):
        """
        This function will replace the SettingsController._restart_service method,
        to avoid problems in tests due to restart.
        """
        self.was_reset = should_reset
        TvbProfile._build_profile_class(TvbProfile.CURRENT_PROFILE_NAME)

    def test_check_db_url(self):
        """
        Test that for a various DB URLs, the correct check response is returned.
        """
        submit_data = {
            stored.KEY_STORAGE: TvbProfile.current.TVB_STORAGE,
            stored.KEY_DB_URL: TvbProfile.current.db.DB_URL
        }
        result = json.loads(self.settings_c.check_db_url(**submit_data))
        assert result['status'] == 'ok'

        submit_data[stored.KEY_DB_URL] = "this URL should be invalid"
        result = json.loads(self.settings_c.check_db_url(**submit_data))
        assert result['status'] == 'not ok'

    @pytest.mark.skipif(get_matlab_executable() is None,
                        reason="Matlab or Octave not installed!")
    def test_check_matlab_path(self):
        """
        Test that for a various Matlab paths, the correct check response is returned.
        """
        submit_data = {stored.KEY_MATLAB_EXECUTABLE: get_matlab_executable()}
        result = json.loads(
            self.settings_c.validate_matlab_path(**submit_data))
        assert result['status'] == 'ok'

        submit_data[
            stored.KEY_MATLAB_EXECUTABLE] = "/this/path/should/be/invalid"
        result = json.loads(
            self.settings_c.validate_matlab_path(**submit_data))
        assert result['status'] == 'not ok'
Ejemplo n.º 22
0
class TestBCT(TransactionalTestCase):
    """
    Test that all BCT analyzers are executed without error.
    We do not verify that the algorithms are correct, because that is outside the purpose of TVB framework.
    """
    EXPECTED_TO_FAIL_VALIDATION = [
        "CentralityKCoreness", "CentralityEigenVector",
        "ClusteringCoefficientBU", "ClusteringCoefficientWU",
        "TransitivityBinaryUnDirected", "TransitivityWeightedUnDirected"
    ]

    @pytest.mark.skipif(get_matlab_executable() is None,
                        reason="Matlab or Octave not installed!")
    def transactional_setup_method(self):
        """
        Sets up the environment for running the tests;
        creates a test user, a test project, a connectivity and a list of BCT adapters;
        imports a CFF data-set
        """
        self.test_user = TestFactory.create_user("BCT_User")
        self.test_project = TestFactory.create_project(self.test_user,
                                                       "BCT-Project")
        # Make sure Connectivity is in DB
        zip_path = os.path.join(os.path.dirname(tvb_data.__file__),
                                'connectivity', 'connectivity_66.zip')
        conn_index = TestFactory.import_zip_connectivity(
            self.test_user, self.test_project, zip_path)
        self.connectivity = ABCAdapter.load_traited_by_gid(conn_index.gid)

        # make weights matrix symmetric, or else some BCT algorithms will run infinitely:
        w = self.connectivity.weights
        self.connectivity.weights = w + w.T - numpy.diag(w.diagonal())

        algorithms = dao.get_generic_entity(Algorithm,
                                            'Brain Connectivity Toolbox',
                                            'group_description')
        assert algorithms is not None
        assert len(algorithms) > 5

        self.bct_adapters = []
        for algo in algorithms:
            self.bct_adapters.append(ABCAdapter.build_adapter(algo))

    def transactional_teardown_method(self):
        """
        Cleans the database after the tests
        """
        self.clean_database(True)

    @pytest.mark.skipif(get_matlab_executable() is None,
                        reason="Matlab or Octave not installed!")
    def test_bct_all(self):
        """
        Iterate all BCT algorithms and execute them.
        """
        for adapter_instance in self.bct_adapters:
            algorithm = adapter_instance.stored_adapter
            operation = TestFactory.create_operation(
                algorithm=algorithm,
                test_user=self.test_user,
                test_project=self.test_project,
                operation_status=STATUS_STARTED)
            assert STATUS_STARTED == operation.status
            # Launch BCT algorithm
            submit_data = {algorithm.parameter_name: self.connectivity.gid}
            try:
                OperationService().initiate_prelaunch(operation,
                                                      adapter_instance, {},
                                                      **submit_data)
                if algorithm.classname in TestBCT.EXPECTED_TO_FAIL_VALIDATION:
                    raise Exception(
                        "Algorithm %s was expected to throw input validation "
                        "exception, but did not!" % (algorithm.classname, ))

                operation = dao.get_operation_by_id(operation.id)
                # Check that operation status after execution is success.
                assert STATUS_FINISHED == operation.status
                # Make sure at least one result exists for each BCT algorithm
                results = dao.get_generic_entity(DataType, operation.id,
                                                 'fk_from_operation')
                assert len(results) > 0

            except InvalidParameterException as excep:
                # Some algorithms are expected to throw validation exception.
                if algorithm.classname not in TestBCT.EXPECTED_TO_FAIL_VALIDATION:
                    raise excep

    @pytest.mark.skipif(get_matlab_executable() is None,
                        reason="Matlab or Octave not installed!")
    def test_bct_descriptions(self):
        """
        Iterate all BCT algorithms and check that description has been extracted from *.m files.
        """
        for adapter_instance in self.bct_adapters:
            assert len(adapter_instance.stored_adapter.description) > 10, "Description was not loaded properly for " \
                                                                          "algorithm %s" % (str(adapter_instance))
Ejemplo n.º 23
0
                                        "exception, but did not!" % (bct_identifier,))

                    operation = dao.get_operation_by_id(operation.id)
                    ### Check that operation status after execution is success.
                    self.assertEqual(STATUS_FINISHED, operation.status)
                    ### Make sure at least one result exists for each BCT algorithm
                    results = dao.get_generic_entity(model.DataType, operation.id, 'fk_from_operation')
                    self.assertTrue(len(results) > 0)

                except InvalidParameterException, excep:
                    ## Some algorithms are expected to throw validation exception.
                    if bct_identifier not in BCTTest.EXPECTED_TO_FAIL_VALIDATION:
                        raise excep


    @unittest.skipIf(get_matlab_executable() is None, "Matlab or Octave not installed!")
    def test_bct_descriptions(self):
        """
        Iterate all BCT algorithms and check description not empty.
        """
        for i in xrange(len(self.bct_adapters)):
            for bct_identifier in self.bct_adapters[i].get_algorithms_dictionary():
                ### Prepare Operation and parameters
                algorithm = dao.get_algorithm_by_group(self.algo_groups[i].id, bct_identifier)
                self.assertTrue(len(algorithm.description) > 0,
                                "Description was not loaded properly for algorithm %s -- %s" % (str(algorithm),
                                                                                                bct_identifier))


def suite():
    """