Example #1
0
def test_import_module_from_source():
    module_path = os.path.dirname(__file__)
    # import the local_module.py which consist of a single function.
    mod = import_module_from_source(
        os.path.join(module_path, 'local_module.py'), 'mod'
    )
    assert hasattr(mod, 'func_local_module')
Example #2
0
def test_check_workflow(session_scope_function):
    # load the workflow from the iris kit which is in the test data
    for kit in ['iris', 'boston_housing']:
        kit_path = os.path.join(HERE, 'data', '{}_kit'.format(kit))
        problem_module = import_module_from_source(
            os.path.join(kit_path, 'problem.py'), 'problem')
        add_workflow(session_scope_function, problem_module.workflow)
    workflow = get_workflow(session_scope_function, None)
    assert len(workflow) == 2
    assert isinstance(workflow, list)
    workflow = get_workflow(session_scope_function, 'Classifier')
    assert workflow.name == 'Classifier'
    assert isinstance(workflow, Workflow)
Example #3
0
def add_problem(session, problem_name, kit_dir, data_dir, force=False):
    """Add a RAMP problem to the database.

    Parameters
    ----------
    session : :class:`sqlalchemy.orm.Session`
        The session to directly perform the operation on the database.
    problem_name : str
        The name of the problem to register in the database.
    kit_dir : str
        The directory where the RAMP kit are located. It will corresponds to
        the key `ramp_kit_dir` of the dictionary created with
        :func:`ramp_utils.generate_ramp_config`.
    data_dir : str
        The directory where the RAMP data are located. It will corresponds to
        the key `ramp_data_dir` of the dictionary created with
        :func:`ramp_utils.generate_ramp_config`.
    force : bool, default is False
        Whether to force add the problem. If ``force=False``, an error is
        raised if the problem was already in the database.
    """
    problem = select_problem_by_name(session, problem_name)
    problem_kit_path = kit_dir
    if problem is not None:
        if not force:
            raise ValueError('Attempting to overwrite a problem and '
                             'delete all linked events. Use"force=True" '
                             'if you want to overwrite the problem and '
                             'delete the events.')
        delete_problem(session, problem_name)

    # load the module to get the type of workflow used for the problem
    problem_module = import_module_from_source(
        os.path.join(problem_kit_path, 'problem.py'), 'problem')
    add_workflow(session, problem_module.workflow)
    problem = Problem(name=problem_name,
                      path_ramp_kit=kit_dir,
                      path_ramp_data=data_dir,
                      session=session)
    logger.info('Adding {}'.format(problem))
    session.add(problem)
    session.commit()
Example #4
0
 def module(self):
     """module: Get the problem module."""
     return import_module_from_source(
         os.path.join(self.path_ramp_kits, self.name, 'problem.py'),
         'problem')