Example #1
0
def task_workbench(monkeypatch, app_dir):
    """Setup the workbench in such a way that the task manager can be tested.

    """
    def exit_err(self):
        if self._delayed:
            raise Exception('Unexpected exceptions occured :\n' +
                            pformat(self._delayed))

    monkeypatch.setattr(ErrorsPlugin, 'exit_error_gathering', exit_err)
    workbench = Workbench()
    workbench.register(CoreManifest())
    workbench.register(AppManifest())
    workbench.register(PreferencesManifest())
    workbench.register(ErrorsManifest())
    workbench.register(DependenciesManifest())
    workbench.register(TasksManagerManifest())

    yield workbench

    for m_id in ('ecpy.tasks', 'ecpy.app.dependencies', 'ecpy.app.errors',
                 'ecpy.app.preferences', 'ecpy.app'):
        try:
            workbench.unregister(m_id)
        except ValueError:
            pass
Example #2
0
def content_workbench(measure_workbench, measure, windows):
    """Create a measure workspace.

    """
    measure_workbench.register(UIManifest())
    measure_workbench.register(LogManifest())
    measure_workbench.register(TasksManagerManifest())
    measure_plugin = measure_workbench.get_plugin('ecpy.measure')
    measure_plugin.selected_engine = 'dummy'
    measure_plugin.default_monitors = ['dummy']

    return measure_workbench
Example #3
0
def processor(windows, measure_workbench, measure):
    """Fixture starting the measure plugin and returning the processor.

    Use app because we need run the event loop

    """
    # measure ensures that contributions are there
    measure_workbench.register(UIManifest())
    measure_workbench.register(TasksManagerManifest())
    plugin = measure_workbench.get_plugin('ecpy.measure')
    plugin.selected_engine = 'dummy'
    return plugin.processor
Example #4
0
def workspace(measure_workbench, measure, windows):
    """Create a measure workspace.

    """
    measure_workbench.register(UIManifest())
    measure_workbench.register(LogManifest())
    measure_workbench.register(TasksManagerManifest())
    measure_plugin = measure_workbench.get_plugin('ecpy.measure')
    measure_plugin.selected_engine = 'dummy'
    measure_plugin.default_monitors = ['dummy']
    core = measure_workbench.get_plugin('enaml.workbench.core')
    cmd = 'enaml.workbench.ui.select_workspace'
    core.invoke_command(cmd, {'workspace': 'ecpy.measure.workspace'})

    return measure_plugin.workspace
Example #5
0
def test_running_checks(measure_workbench, measure):
    """Test running the checks attached to a measure.

    """
    # Add dummy hooks
    measure.add_tool('pre-hook', 'dummy')
    measure.add_tool('post-hook', 'dummy')

    # This is necessary for the internal checks.
    measure_workbench.register(TasksManagerManifest())
    res, msg, errors = measure.dependencies.collect_runtimes()
    assert res

    # Check that the internal hook does run the root_task tests.
    res, errors = measure.run_checks()
    assert not res
    assert 'ecpy.internal_checks' in errors

    # Check an ideal case
    measure.root_task.default_path = os.path.dirname(__file__)
    res, errors = measure.run_checks()
    assert res
    assert not errors

    # Check handling error in pre_hook
    measure.pre_hooks['dummy'].fail_check = True
    res, errors = measure.run_checks()
    assert not res
    assert 'dummy' in errors and errors['dummy'] == 'pre'

    # Check handling error in post_hook
    measure.pre_hooks['dummy'].fail_check = False
    measure.post_hooks['dummy'].fail_check = True
    res, errors = measure.run_checks()
    assert not res
    assert 'dummy' in errors and errors['dummy'] == 'post'

    # Check kwargs passing to pre-hooks
    measure.post_hooks['dummy'].fail_check = False
    res, errors = measure.run_checks(fail=True)
    assert not res
    assert 'dummy' in errors and errors['dummy'] == 'pre'

    # Check kwargs passing to post-hooks
    res, errors = measure.run_checks(fail_post=True)
    assert not res
    assert 'dummy' in errors and errors['dummy'] == 'post'
Example #6
0
def test_measure_persistence(measure_workbench, measure, tmpdir, monkeypatch):
    """Test saving and reloading a measure.

    """
    measure_workbench.register(TasksManagerManifest())
    plugin = measure_workbench.get_plugin('ecpy.measure')

    measure.add_tool('pre-hook', 'dummy')
    measure.root_task.default_path = 'test'
    measure.pre_hooks['dummy'].fail_check = True

    path = str(tmpdir.join('test.meas.ini'))
    measure.save(path)
    assert measure.path == path

    loaded, errors = Measure.load(plugin, path)
    assert loaded.root_task.default_path == 'test'
    assert loaded.pre_hooks['dummy'].fail_check
    assert loaded.path == path
    assert not errors

    # Test handling errors : root_task rebuilding and tool rebuilding.
    class CommandError(Exception):
        pass

    def generate_err(self, cmd, infos, u=None):
        raise CommandError()

    from enaml.workbench.core.core_plugin import CorePlugin
    monkeypatch.setattr(CorePlugin, 'invoke_command', generate_err)

    class CreationError(Exception):
        pass

    class Fail(object):
        def new(self, workbench, default=True):
            raise CreationError()

    plugin._pre_hooks.contributions['dummy'] = Fail()

    loaded, errors = Measure.load(plugin, path)
    assert loaded is None
    assert 'main task' in errors and 'CommandError' in errors['main task']
    assert 'pre-hook' in errors and 'dummy' in errors['pre-hook']
    assert 'CreationError' in errors['pre-hook']['dummy']
Example #7
0
def workspace(measure_workbench, measure, windows):
    """Create a measure workspace.

    """
    measure_workbench.register(UIManifest())
    measure_workbench.register(LogManifest())
    measure_workbench.register(TasksManagerManifest())
    measure_plugin = measure_workbench.get_plugin('ecpy.measure')
    measure_plugin.selected_engine = 'dummy'
    measure_plugin.default_monitors = ['dummy']
    core = measure_workbench.get_plugin('enaml.workbench.core')
    cmd = 'enaml.workbench.ui.select_workspace'
    core.invoke_command(cmd, {'workspace': 'ecpy.measure.workspace'})

    yield measure_plugin.workspace

    cmd = 'enaml.workbench.ui.close_workspace'
    core.invoke_command(cmd, {'workspace': 'ecpy.measure.workspace'})

    for m_id in ('ecpy.tasks', 'ecpy.app.logging'):
        try:
            measure_workbench.unregister(m_id)
        except ValueError:
            pass
Example #8
0
def process_engine(measure_workbench):
    measure_workbench.register(LogManifest())
    measure_workbench.register(TasksManagerManifest())
    plugin = measure_workbench.get_plugin('ecpy.measure')
    return plugin.create('engine', 'ecpy.process_engine')
Example #9
0
def main(cmd_line_args=None):
    """Main entry point of the Ecpy application.

    """
    # Build parser from ArgParser and parse arguemnts
    parser = ArgParser()
    parser.add_choice('workspaces', 'ecpy.measure.workspace', 'measure')
    parser.add_argument("-s",
                        "--nocapture",
                        help="Don't capture stdout/stderr",
                        action='store_true')
    parser.add_argument("-w",
                        "--workspace",
                        help='Select start-up workspace',
                        default='measure',
                        choices='workspaces')
    parser.add_argument("-r",
                        "--reset-app-folder",
                        help='Reset the application startup folder.',
                        action='store_true')

    modifiers = []
    for i, ep in enumerate(iter_entry_points('ecpy_cmdline_args')):

        try:
            modifier, priority = ep.load(require=False)
            modifiers.append((ep, modifier, priority, i))
        except Exception as e:
            text = 'Error loading extension %s' % ep.name
            content = ('The following error occurred when trying to load the '
                       'entry point {} :\n {}'.format(ep.name, e))
            details = format_exc()
            display_startup_error_dialog(text, content, details)

    modifiers.sort(key=itemgetter(1, 2))
    try:
        for m in modifiers:
            m[1](parser)
    except Exception as e:
        text = 'Error modifying cmd line arguments'
        content = ('The following error occurred when the entry point {} '
                   'tried to add cmd line options :\n {}'.format(ep.name, e))
        details = format_exc()
        display_startup_error_dialog(text, content, details)

    try:
        args = parser.parse_args(cmd_line_args)
    except BaseException as e:
        if e.args == (0, ):
            sys.exit(0)
        text = 'Failed to parse cmd line arguments'
        content = ('The following error occurred when trying to parse the '
                   'command line arguments :\n {}'.format(e))
        details = format_exc()
        display_startup_error_dialog(text, content, details)

    workbench = Workbench()
    workbench.register(CoreManifest())
    workbench.register(UIManifest())
    workbench.register(AppManifest())
    workbench.register(StateManifest())
    workbench.register(ErrorsManifest())
    workbench.register(PreferencesManifest())
    workbench.register(LogManifest())
    workbench.register(PackagesManifest())
    workbench.register(DependenciesManifest())
    workbench.register(TasksManagerManifest())
    workbench.register(MeasureManifest())

    ui = workbench.get_plugin(u'enaml.workbench.ui')  # Create the application

    try:
        app = workbench.get_plugin('ecpy.app')
        app.run_app_startup(args)
    except Exception as e:
        text = 'Error starting plugins'
        content = ('The following error occurred when executing plugins '
                   'apllication start code :\n {}'.format(e))
        details = format_exc()
        display_startup_error_dialog(text, content, details)

    core = workbench.get_plugin('enaml.workbench.core')
    core.invoke_command('enaml.workbench.ui.select_workspace',
                        {'workspace': args.workspace}, workbench)

    ui = workbench.get_plugin(u'enaml.workbench.ui')
    ui.show_window()
    ui.window.maximize()
    ui.start_application()

    core.invoke_command('enaml.workbench.ui.close_workspace', {}, workbench)

    # Unregister all contributed packages
    workbench.unregister('ecpy.app.packages')

    workbench.unregister('ecpy.measure')
    workbench.unregister('ecpy.tasks')
    workbench.unregister('ecpy.app.preferences')
    workbench.unregister('ecpy.app.states')
    workbench.unregister('ecpy.app.dependencies')
    workbench.unregister('ecpy.app.errors')
    workbench.unregister('ecpy.app.logging')
    workbench.unregister('ecpy.app')
    workbench.unregister(u'enaml.workbench.ui')
    workbench.unregister(u'enaml.workbench.core')