Пример #1
0
def test_create_context(workbench, root, exopy_qtbot):
    """Test creating a context for a sequence.

    """
    core = workbench.get_plugin('enaml.workbench.core')

    def select_context(exopy_qtbot, dial):
        """Select the sequence to build.

        """
        obj_combo = dial.central_widget().widgets()[0]
        obj_combo.selected_item = 'Dummy'

    with handle_dialog(exopy_qtbot, 'accept', select_context):
        cmd = 'exopy.pulses.create_context'
        core.invoke_command(cmd, dict(root=root))

    assert root.context is not None

    del root.context

    with handle_dialog(exopy_qtbot, 'reject'):
        cmd = 'exopy.pulses.create_context'
        core.invoke_command(cmd, dict(root=root))

    assert root.context is None
Пример #2
0
def test_browing_dialog_profiles_delete(exopy_qtbot, prof_plugin,
                                        dialog_sleep):
    """Test the browsing dialog page dedicated to explore the profiles.

    """
    d = BrowsingDialog(plugin=prof_plugin)
    nb = d.central_widget().widgets()[0]
    nb.selected_tab = 'profiles'
    d.show()
    wait_for_window_displayed(exopy_qtbot, d)
    exopy_qtbot.wait(dialog_sleep)

    c = nb.pages()[0].page_widget()
    btn = c.widgets()[-1]
    c.p_id = 'fp1'
    print(prof_plugin._profiles)

    with handle_dialog(exopy_qtbot, 'reject', cls=MessageBox):
        btn.clicked = True

    assert 'fp1' in prof_plugin._profiles

    def handle(bot, dial):
        dial.buttons[0].was_clicked = True

    with handle_dialog(exopy_qtbot, 'accept', handle, cls=MessageBox):
        btn.clicked = True

    exopy_qtbot.wait(1000)

    def assert_profiles():
        assert 'fp1' not in prof_plugin._profiles
    exopy_qtbot.wait_until(assert_profiles)
Пример #3
0
def test_create_sequence(root, workbench, exopy_qtbot, monkeypatch):
    """Test creating a sequence.

    """
    core = workbench.get_plugin('enaml.workbench.core')

    def select_sequence(exopy_qtbot, dial):
        """Select the sequence to build.

        """
        dial.selector.selected_sequence = 'exopy_pulses.BaseSequence'

    with handle_dialog(exopy_qtbot, 'accept', select_sequence):
        cmd = 'exopy.pulses.create_sequence'
        seq = core.invoke_command(cmd, dict(root=root))

    assert seq is not None

    with handle_dialog(exopy_qtbot, 'reject'):
        cmd = 'exopy.pulses.create_sequence'
        seq = core.invoke_command(cmd, dict(root=root))

    assert seq is None

    def raise_on_build(*args, **kwargs):
        raise Exception()

    from exopy_pulses.pulses.configs.base_config import SequenceConfig
    monkeypatch.setattr(SequenceConfig, 'build_sequence', raise_on_build)

    with handle_dialog(exopy_qtbot, 'accept', cls=ErrorsDialog, time=500):
        with handle_dialog(exopy_qtbot, 'accept', cls=BuilderView):
            cmd = 'exopy.pulses.create_sequence'
            seq = core.invoke_command(cmd, dict(root=root))
Пример #4
0
def test_browing_dialog_profiles_delete(exopy_qtbot, prof_plugin,
                                        dialog_sleep):
    """Test the browsing dialog page dedicated to explore the profiles.

    """
    d = BrowsingDialog(plugin=prof_plugin)
    nb = d.central_widget().widgets()[0]
    nb.selected_tab = 'profiles'
    d.show()
    wait_for_window_displayed(exopy_qtbot, d)
    exopy_qtbot.wait(dialog_sleep)

    c = nb.pages()[0].page_widget()
    btn = c.widgets()[-1]
    c.p_id = 'fp1'
    print(prof_plugin._profiles)

    with handle_dialog(exopy_qtbot, 'reject', cls=MessageBox):
        btn.clicked = True

    assert 'fp1' in prof_plugin._profiles

    def handle(bot, dial):
        dial.buttons[0].was_clicked = True

    with handle_dialog(exopy_qtbot, 'accept', handle, cls=MessageBox):
        btn.clicked = True

    exopy_qtbot.wait(1000)

    def assert_profiles():
        assert 'fp1' not in prof_plugin._profiles

    exopy_qtbot.wait_until(assert_profiles)
Пример #5
0
def test_report_command(err_workbench, exopy_qtbot):
    """Test generating an application errors report.

    """
    core = err_workbench.get_plugin('enaml.workbench.core')
    with handle_dialog(exopy_qtbot):
        core.invoke_command('exopy.app.errors.report')

    with handle_dialog(exopy_qtbot):
        core.invoke_command('exopy.app.errors.report', dict(kind='error'))

    with handle_dialog(exopy_qtbot):
        core.invoke_command('exopy.app.errors.report', dict(kind='stupid'))
Пример #6
0
def test_report_command(err_workbench, exopy_qtbot):
    """Test generating an application errors report.

    """
    core = err_workbench.get_plugin('enaml.workbench.core')
    with handle_dialog(exopy_qtbot):
        core.invoke_command('exopy.app.errors.report')

    with handle_dialog(exopy_qtbot):
        core.invoke_command('exopy.app.errors.report', dict(kind='error'))

    with handle_dialog(exopy_qtbot):
        core.invoke_command('exopy.app.errors.report', dict(kind='stupid'))
Пример #7
0
def test_handling_error_in_handlers(err_workbench, exopy_qtbot):
    """Test handling an error occuring in a specilaized handler.

    """
    plugin = err_workbench.get_plugin(ERRORS_ID)

    def check_dialog(bot, dial):
        assert 'error' in dial.errors
        assert 'registering' not in dial.errors

    with handle_dialog(exopy_qtbot, handler=check_dialog):
        plugin.signal('registering')

    with handle_dialog(exopy_qtbot, handler=check_dialog):
        plugin.signal('registering', msg=FailedFormat())
Пример #8
0
def test_handling_error_in_handlers(err_workbench, exopy_qtbot):
    """Test handling an error occuring in a specilaized handler.

    """
    plugin = err_workbench.get_plugin(ERRORS_ID)

    def check_dialog(bot, dial):
        assert 'error' in dial.errors
        assert 'registering' not in dial.errors

    with handle_dialog(exopy_qtbot, handler=check_dialog):
        plugin.signal('registering')

    with handle_dialog(exopy_qtbot, handler=check_dialog):
        plugin.signal('registering', msg=FailedFormat())
Пример #9
0
def test_create_task2(exopy_qtbot, task_workbench, dialog_sleep):
    """Test handling user cancellation.

    """
    core = task_workbench.get_plugin('enaml.workbench.core')

    def answer_dialog(exopy_qtbot, dial):
        selector = dial.selector
        qlist = selector.widgets()[-1]
        qlist.selected_item = qlist.items[-1]

        def assert_dial_config():
            assert dial.config

        exopy_qtbot.wait_until(assert_dial_config)
        exopy_qtbot.wait(dialog_sleep)

        dial._choose_config('_dummy_')
        assert not dial.config
        exopy_qtbot.wait(dialog_sleep)

    with handle_dialog(exopy_qtbot, 'reject', answer_dialog):
        res = core.invoke_command('exopy.tasks.create_task')

    assert res is None
Пример #10
0
def test_enqueuing_fail_reload(workspace, monkeypatch, tmpdir, exopy_qtbot):
    """Test failing when reloading the measurement after saving.

    """
    m = workspace.plugin.edited_measurements.measurements[0]
    m.root_task.default_path = str(tmpdir)
    from exopy.measurement.measurement import Measurement

    witness = []

    @classmethod
    def r(cls, measurement_plugin, path, build_dep=None):
        witness.append(None)
        return None, {'r': 't'}
    monkeypatch.setattr(Measurement, 'load', r)

    with handle_dialog(exopy_qtbot):
        workspace.enqueue_measurement(m)

    # Check dependencies are cleaned up
    assert_dependencies_released(workspace, m)

    assert not workspace.plugin.enqueued_measurements.measurements

    assert witness
Пример #11
0
    def handle_error_report(bot, dial):
        def answer_question(bot, dial):
            dial.buttons[1].was_clicked = True

        with handle_dialog(bot, 'reject', answer_question,
                           cls=MessageBox):
            dial.central_widget().widgets()[-1].clicked = True
Пример #12
0
def test_save_action(exopy_qtbot, workspace, measurement):
    """Test that save action calls the proper commands.

    """
    act = SaveAction(workspace=workspace,
                     action_context={'data': (None, None,
                                              measurement.root_task, None)})

    with handle_dialog(exopy_qtbot, 'reject'):
        act.triggered = True

    class CmdException(Exception):

        def __init__(self, cmd, opts):
            self.cmd = cmd

    def invoke(self, cmd, opts, caller=None):
        raise CmdException(cmd, opts)

    from enaml.workbench.core.core_plugin import CorePlugin
    old = CorePlugin.invoke_command
    CorePlugin.invoke_command = invoke

    try:
        with pytest.raises(CmdException) as ex:
            act.triggered = True
            exopy_qtbot.wait(10)
        assert ex.value.cmd == 'exopy.app.errors.signal'
    finally:
        CorePlugin.invoke_command = old
Пример #13
0
def test_create_task2(exopy_qtbot, task_workbench, dialog_sleep, task_config):
    """Test handling user cancellation.

    """
    core = task_workbench.get_plugin('enaml.workbench.core')

    def answer_dialog(exopy_qtbot, dial):
        selector = dial.selector
        qlist = selector.widgets()[-1]
        qlist.selected_item = qlist.items[-1]

        def assert_dial_config():
            assert dial.config
        exopy_qtbot.wait_until(assert_dial_config)
        exopy_qtbot.wait(dialog_sleep)

        dial._choose_config('_dummy_')
        assert not dial.config
        exopy_qtbot.wait(dialog_sleep)

    root = RootTask()
    with handle_dialog(exopy_qtbot, 'reject', answer_dialog):
        res = core.invoke_command('exopy.tasks.create_task',
                                  dict(future_parent=root))

    assert res is None
Пример #14
0
def test_save_action(exopy_qtbot, workspace, measurement):
    """Test that save action calls the proper commands.

    """
    act = SaveAction(
        workspace=workspace,
        action_context={'data': (None, None, measurement.root_task, None)})

    with handle_dialog(exopy_qtbot, 'reject'):
        act.triggered = True

    class CmdException(Exception):
        def __init__(self, cmd, opts):
            self.cmd = cmd

    def invoke(self, cmd, opts, caller=None):
        raise CmdException(cmd, opts)

    from enaml.workbench.core.core_plugin import CorePlugin
    old = CorePlugin.invoke_command
    CorePlugin.invoke_command = invoke

    try:
        with pytest.raises(CmdException) as ex:
            act.triggered = True
            exopy_qtbot.wait(10)
        assert ex.value.cmd == 'exopy.app.errors.signal'
    finally:
        CorePlugin.invoke_command = old
Пример #15
0
def test_running_main_error_in_parser_modifying(exopy_qtbot, monkeypatch):
    """Test starting the main app but encountering an issue while adding
    arguments.

    """
    import exopy.__main__ as em

    def false_iter(arg):

        class FalseEntryPoint(EntryPoint):
            def load(self, *args, **kwargs):

                def false_modifier(parser):
                    raise Exception('Failed to add stupid argument to parser')

                return (false_modifier, 1)

        return [FalseEntryPoint('dummy', 'dummy')]

    monkeypatch.setattr(em, 'iter_entry_points', false_iter)

    def check_dialog(qtbot, dial):
        assert 'modifying' in dial.text

    with pytest.raises(SystemExit):
        with handle_dialog(exopy_qtbot, 'reject', check_dialog):
            main([])
Пример #16
0
def test_app_startup4(pref_workbench, tmpdir, exopy_qtbot):
    """Test app start-up when user request to reset app folder.

    """
    manifest = PreferencesManifest()
    pref_workbench.register(manifest)

    app_dir = str(tmpdir.join('exopy'))

    # Add a app_directory.ini file.
    app_pref = os.path.join(exopy_path(), APP_PREFERENCES, APP_DIR_CONFIG)
    if not os.path.isfile(app_pref):
        conf = ConfigObj(encoding='utf8')
        conf.filename = app_pref
        conf['app_path'] = app_dir
        conf.write()

    # Start the app and fake a user answer.
    app = pref_workbench.get_plugin('exopy.app')

    class DummyArgs(object):

        reset_app_folder = True

    with handle_dialog(exopy_qtbot,
                       handler=lambda bot, x: setattr(x, 'path', app_dir)):
        app.run_app_startup(DummyArgs)

    assert os.path.isfile(app_pref)
    assert ConfigObj(app_pref)['app_path'] == app_dir
    assert os.path.isdir(app_dir)
Пример #17
0
def test_app_startup1(pref_workbench, tmpdir, exopy_qtbot):
    """Test app start-up when no app_directory.ini exists.

    """
    manifest = PreferencesManifest()
    pref_workbench.register(manifest)

    # Remove any trash app_directory.ini file. The global fixture ensure
    # that it cannot be a user file.
    app_pref = os.path.join(exopy_path(), APP_PREFERENCES, APP_DIR_CONFIG)
    if os.path.isfile(app_pref):
        os.remove(app_pref)

    # Start the app and fake a user answer.
    app = pref_workbench.get_plugin('exopy.app')

    app_dir = str(tmpdir.join('exopy'))

    with handle_dialog(exopy_qtbot,
                       handler=lambda bot, d: setattr(d, 'path', app_dir)):
        app.run_app_startup(object())

    assert os.path.isfile(app_pref)
    assert ConfigObj(app_pref)['app_path'] == app_dir
    assert os.path.isdir(app_dir)
Пример #18
0
    def test_unsatifiable_requirement(self, exopy_qtbot):
        """Test the case of a declarator always adding itself to _deflayed.

        """
        self.workbench.register(DContributor5())
        with handle_dialog(exopy_qtbot):
            self.workbench.get_plugin(PLUGIN_ID)
Пример #19
0
def test_enqueuing_fail_reload(workspace, monkeypatch, tmpdir, exopy_qtbot):
    """Test failing when reloading the measurement after saving.

    """
    m = workspace.plugin.edited_measurements.measurements[0]
    m.root_task.default_path = str(tmpdir)
    from exopy.measurement.measurement import Measurement

    witness = []

    @classmethod
    def r(cls, measurement_plugin, path, build_dep=None):
        witness.append(None)
        return None, {'r': 't'}

    monkeypatch.setattr(Measurement, 'load', r)

    with handle_dialog(exopy_qtbot):
        workspace.enqueue_measurement(m)

    # Check dependencies are cleaned up
    assert_dependencies_released(workspace, m)

    assert not workspace.plugin.enqueued_measurements.measurements

    assert witness
Пример #20
0
def test_enqueueing_abort_warning(workspace, monkeypatch, tmpdir, exopy_qtbot):
    """Test aborting enqueueing because some checks raised warnings.

    """
    m = workspace.plugin.edited_measurements.measurements[0]
    m.root_task.default_path = str(tmpdir)
    from exopy.measurement.measurement import Measurement

    witness = []

    def check(*args, **kwargs):
        witness.append(None)
        return True, {'r': {'t': 's'}}

    monkeypatch.setattr(Measurement, 'run_checks', check)

    with handle_dialog(exopy_qtbot, 'reject'):
        workspace.enqueue_measurement(m)

    # Check dependencies are cleaned up
    assert_dependencies_released(workspace, m)

    assert not workspace.plugin.enqueued_measurements.measurements

    assert witness
Пример #21
0
def test_signal_command_with_unknown(err_workbench, exopy_qtbot):
    """Test the signal command with a stupid kind of error.

    """
    core = err_workbench.get_plugin('enaml.workbench.core')

    with handle_dialog(exopy_qtbot):
        core.invoke_command('exopy.app.errors.signal',
                            {'kind': 'stupid', 'msg': None})

    with handle_dialog(exopy_qtbot):
        fail = FailedFormat()
        core.invoke_command('exopy.app.errors.signal',
                            {'kind': 'stupid', 'msg': fail})

    assert getattr(fail, 'called', None)
Пример #22
0
def test_saving_as_template(exopy_qtbot, tmpdir, task_workbench, task,
                            monkeypatch):
    """Test saving a task as a template.

    """
    from exopy.tasks.utils import saving

    monkeypatch.setattr(saving.TemplateViewer, 'exec_',
                        saving.TemplateViewer.show)

    plugin = task_workbench.get_plugin('exopy.tasks')
    plugin.templates = {'test': ''}

    def answer_dialog(bot, dialog):
        model = dialog._model
        model.folder = str(tmpdir)
        model.filename = 'test'
        model.doc = 'This is a test'
        dialog.show_result = True

        assert model.accept_template_info(dialog)

    core = task_workbench.get_plugin('enaml.workbench.core')
    with handle_dialog(exopy_qtbot, 'accept', answer_dialog):
        core.invoke_command(CMD, dict(task=task, mode='template'))

    w = get_window(exopy_qtbot, Dialog)
    w.accept()
    wait_for_destruction(exopy_qtbot, w)

    path = str(tmpdir.join('test.task.ini'))
    assert os.path.isfile(path)
    config = ConfigObj(path)
    assert config.initial_comment == ['# This is a test']
Пример #23
0
def test_driver_validation_error_handler(exopy_qtbot, instr_workbench):
    """Test the error handler dedicated to driver validation issues.

    """
    core = instr_workbench.get_plugin('enaml.workbench.core')
    p = instr_workbench.get_plugin('exopy.instruments')
    d = DriverInfos(starter='starter',
                    connections={
                        'c1': {},
                        'c2': {}
                    },
                    settings={
                        's2': {},
                        's3': {}
                    })
    cmd = 'exopy.app.errors.signal'

    def check_dialog(bot, dial):
        w = dial.errors['exopy.driver-validation']
        assert 'd' in w.errors
        for err in ('starter', 'connections', 'settings'):
            assert err in w.errors['d']

    with handle_dialog(exopy_qtbot, 'accept', check_dialog):
        core.invoke_command(cmd, {
            'kind': 'exopy.driver-validation',
            'details': {
                'd': d.validate(p)[1]
            }
        })
Пример #24
0
def test_saving_as_template(exopy_qtbot, tmpdir, task_workbench, task,
                            monkeypatch):
    """Test saving a task as a template.

    """
    from exopy.tasks.utils import saving

    monkeypatch.setattr(saving.TemplateViewer, 'exec_',
                        saving.TemplateViewer.show)

    plugin = task_workbench.get_plugin('exopy.tasks')
    plugin.templates = {'test': ''}

    def answer_dialog(bot, dialog):
        model = dialog._model
        model.folder = str(tmpdir)
        model.filename = 'test'
        model.doc = 'This is a test'
        dialog.show_result = True

        assert model.accept_template_info(dialog)

    core = task_workbench.get_plugin('enaml.workbench.core')
    with handle_dialog(exopy_qtbot, 'accept', answer_dialog):
        core.invoke_command(CMD, dict(task=task, mode='template'))

    w = get_window(exopy_qtbot, Dialog)
    w.accept()
    wait_for_destruction(exopy_qtbot, w)

    path = str(tmpdir.join('test.task.ini'))
    assert os.path.isfile(path)
    config = ConfigObj(path)
    assert config.initial_comment == ['# This is a test']
Пример #25
0
    def test_declarator_failed_registration(self, exopy_qtbot):
        """Test handling of error when a declarator fail to register.

        """
        self.workbench.register(DContributor4())
        with handle_dialog(exopy_qtbot):
            self.workbench.get_plugin(PLUGIN_ID)
Пример #26
0
def test_select_instrument(instr_task_workbench, instr_view, exopy_qtbot):
    """Test selecting an instrument from the view.

    """
    tool_btn = instr_view.widgets()[-1].widgets()[-1]
    selec = ('fp1', 'tasks.test.FalseDriver',
             'false_connection', 'false_settings')
    instr_view.task.selected_instrument = selec
    with handle_dialog(exopy_qtbot, 'reject'):
        tool_btn.clicked = True

    assert instr_view.task.selected_instrument == selec

    with handle_dialog(exopy_qtbot, 'accept'):
        tool_btn.clicked = True

    assert instr_view.task.selected_instrument == selec
Пример #27
0
    def test_check_errors1(self, exopy_qtbot):
        """Test enforcement of type when using factory.

        """

        self.workbench.register(DContributor3())
        with handle_dialog(exopy_qtbot):
            self.workbench.get_plugin(PLUGIN_ID)
Пример #28
0
    def test_check_errors2(self, exopy_qtbot):
        """Test use of validate_ext.

        """

        self.workbench.register(Contributor3())
        with handle_dialog(exopy_qtbot):
            self.workbench.get_plugin(PLUGIN_ID)
Пример #29
0
def test_select_instrument(instr_task_workbench, instr_view, exopy_qtbot):
    """Test selecting an instrument from the view.

    """
    tool_btn = instr_view.widgets()[-1].widgets()[-1]
    selec = ('fp1', 'tasks.test.FalseDriver', 'false_connection',
             'false_settings')
    instr_view.task.selected_instrument = selec
    with handle_dialog(exopy_qtbot, 'reject'):
        tool_btn.clicked = True

    assert instr_view.task.selected_instrument == selec

    with handle_dialog(exopy_qtbot, 'accept'):
        tool_btn.clicked = True

    assert instr_view.task.selected_instrument == selec
Пример #30
0
def test_saving_as_template_cancelled(exopy_qtbot, task_workbench, task):
    """Test saving a task as a template : fail to save.

    """
    core = task_workbench.get_plugin('enaml.workbench.core')

    with handle_dialog(exopy_qtbot, 'reject'):
        val = core.invoke_command(CMD, dict(task=task, mode='template'))

    assert val is None
Пример #31
0
def test_saving_as_template_cancelled(exopy_qtbot, task_workbench, task):
    """Test saving a task as a template : fail to save.

    """
    core = task_workbench.get_plugin('enaml.workbench.core')

    with handle_dialog(exopy_qtbot, 'reject'):
        val = core.invoke_command(CMD, dict(task=task, mode='template'))

    assert val is None
Пример #32
0
    def test_errors1(self, exopy_qtbot):
        """Test uniqueness of contribution id.

        """

        self.workbench.register(Contributor1())
        self.workbench.register(Contributor1(id='bis'))
        self.workbench.register(Contributor1(id='ter'))
        with handle_dialog(exopy_qtbot):
            self.workbench.get_plugin(PLUGIN_ID)
Пример #33
0
def test_open_browser_command(exopy_qtbot, prof_plugin):
    """Test opening the browsing window.

    """
    with enaml.imports():
        from enaml.workbench.ui.ui_manifest import UIManifest
    prof_plugin.workbench.register(UIManifest())
    core = prof_plugin.workbench.get_plugin('enaml.workbench.core')
    with handle_dialog(exopy_qtbot):
        core.invoke_command('exopy.instruments.open_browser')
Пример #34
0
def test_profile_edition_dialog_ok(prof_plugin, dialog_sleep, exopy_qtbot,
                                   profile_infos):
    """Test the dialog used to edit a profile.

    """
    # XXX need to test model selection
    profile_infos.connections.clear()
    profile_infos.settings.clear()

    ed = ProfileEditionDialog(plugin=prof_plugin, profile_infos=profile_infos)
    ed.show()
    wait_for_window_displayed(exopy_qtbot, ed)
    exopy_qtbot.wait(dialog_sleep)

    ed_widgets = ed.central_widget().widgets()
    ed_widget = ed_widgets[0]

    nb = ed_widget.widgets()[5]
    c_page, s_page = nb.pages()

    # Add a connection
    with handle_dialog(exopy_qtbot, cls=ConnectionCreationDialog):
        c_page.page_widget().widgets()[2].clicked = True

    exopy_qtbot.wait(10 + dialog_sleep)

    # Add a settings
    with handle_dialog(exopy_qtbot, cls=SettingsCreationDialog):
        s_page.page_widget().widgets()[2].clicked = True

    exopy_qtbot.wait(10 + dialog_sleep)

    assert len(ed_widget.connections) == 1
    assert len(ed_widget.settings) == 1

    ed_widgets[-1].clicked = True

    def assert_cn_st():
        assert len(profile_infos.connections) == 1
        assert len(profile_infos.settings) == 1

    exopy_qtbot.wait_until(assert_cn_st)
Пример #35
0
def test_measurement_view(measurement, exopy_qtbot, dialog_sleep, monkeypatch,
                          workspace):
    """Test that the displayed buttons do reflect the state of the measurement.

    """
    measurement.status = 'READY'
    view = MeasView(model=measurement)
    w = ContainerTestingWindow(widget=view)

    w.show()
    wait_for_window_displayed(exopy_qtbot, w)
    exopy_qtbot.wait(dialog_sleep)

    assert view.widgets()[2].enabled  # cd1 inserted its children before itself

    def test_state(bot, dial):
        assert dial.measurement.status == 'EDITING'

    with handle_dialog(exopy_qtbot, 'reject', handler=test_state):
        view.widgets()[2].clicked = True

    assert view.widgets()[-1].enabled
    measurement.plugin.processor.active = True

    def assert_enabled():
        assert not view.widgets()[-1].enabled

    exopy_qtbot.wait_until(assert_enabled)
    measurement.plugin.processor.active = False

    from exopy.measurement.workspace.workspace import MeasurementSpace
    spy = CallSpy()
    monkeypatch.setattr(MeasurementSpace, 'process_single_measurement', spy)
    view.widgets()[-1].clicked = True
    assert spy.called

    measurement.status = 'RUNNING'

    def assert_widgets():
        assert len(view.widgets()) == 2

    exopy_qtbot.wait_until(assert_widgets)

    measurement.status = 'COMPLETED'

    def assert_widgets():
        assert len(view.widgets()) == 3

    exopy_qtbot.wait_until(assert_widgets)
    spy = CallSpy()
    monkeypatch.setattr(MeasurementSpace, 'reenqueue_measurement', spy)
    view.widgets()[-1].clicked = True

    assert view.widgets()[1].text == 'COMPLETED'
Пример #36
0
def test_running_main_error_in_parsing(exopy_qtbot):
    """Test starting the main app but encountering an issue while adding
    arguments.

    """
    def check_dialog(qtbot, dial):
        assert 'cmd' in dial.text

    with pytest.raises(SystemExit):
        with handle_dialog(exopy_qtbot, 'reject', check_dialog):
            main(['dummy'])
Пример #37
0
def test_select_instrument_profile_command(exopy_qtbot, prof_plugin):
    """Test selecting an instrument profile.

    """
    core = prof_plugin.workbench.get_plugin('enaml.workbench.core')
    with handle_dialog(exopy_qtbot, 'reject'):
        res = core.invoke_command('exopy.instruments.select_instrument')

    assert res is None

    with handle_dialog(exopy_qtbot, 'accept'):
        res = core.invoke_command(
            'exopy.instruments.select_instrument',
            dict(profile='fp1',
                 driver='instruments.test.FalseDriver',
                 connection='false_connection3',
                 settings='false_settings3'))

    assert res == ('fp1', 'instruments.test.FalseDriver', 'false_connection3',
                   'false_settings3')
Пример #38
0
def test_signal_command_with_unknown(err_workbench, exopy_qtbot):
    """Test the signal command with a stupid kind of error.

    """
    core = err_workbench.get_plugin('enaml.workbench.core')

    with handle_dialog(exopy_qtbot):
        core.invoke_command('exopy.app.errors.signal', {
            'kind': 'stupid',
            'msg': None
        })

    with handle_dialog(exopy_qtbot):
        fail = FailedFormat()
        core.invoke_command('exopy.app.errors.signal', {
            'kind': 'stupid',
            'msg': fail
        })

    assert getattr(fail, 'called', None)
Пример #39
0
def test_profile_edition_dialog_ok(prof_plugin, dialog_sleep, exopy_qtbot,
                                   profile_infos):
    """Test the dialog used to edit a profile.

    """
    # XXX need to test model selection
    profile_infos.connections.clear()
    profile_infos.settings.clear()

    ed = ProfileEditionDialog(plugin=prof_plugin, profile_infos=profile_infos)
    ed.show()
    wait_for_window_displayed(exopy_qtbot, ed)
    exopy_qtbot.wait(dialog_sleep)

    ed_widgets = ed.central_widget().widgets()
    ed_widget = ed_widgets[0]

    nb = ed_widget.widgets()[5]
    c_page, s_page = nb.pages()

    # Add a connection
    with handle_dialog(exopy_qtbot, cls=ConnectionCreationDialog):
        c_page.page_widget().widgets()[2].clicked = True

    exopy_qtbot.wait(10 + dialog_sleep)

    # Add a settings
    with handle_dialog(exopy_qtbot, cls=SettingsCreationDialog):
        s_page.page_widget().widgets()[2].clicked = True

    exopy_qtbot.wait(10 + dialog_sleep)

    assert len(ed_widget.connections) == 1
    assert len(ed_widget.settings) == 1

    ed_widgets[-1].clicked = True

    def assert_cn_st():
        assert len(profile_infos.connections) == 1
        assert len(profile_infos.settings) == 1
    exopy_qtbot.wait_until(assert_cn_st)
Пример #40
0
def test_enqueueing_fail_checks(workspace, exopy_qtbot):
    """Test enqueueing a measurement not passing the checks.

    """
    m = workspace.plugin.edited_measurements.measurements[0]
    with handle_dialog(exopy_qtbot, 'reject'):
        workspace.enqueue_measurement(m)

    assert not workspace.plugin.enqueued_measurements.measurements

    # Check dependencies are cleaned up
    assert_dependencies_released(workspace, m)
Пример #41
0
def test_enqueueing_fail_checks(workspace, exopy_qtbot):
    """Test enqueueing a measurement not passing the checks.

    """
    m = workspace.plugin.edited_measurements.measurements[0]
    with handle_dialog(exopy_qtbot, 'reject'):
        workspace.enqueue_measurement(m)

    assert not workspace.plugin.enqueued_measurements.measurements

    # Check dependencies are cleaned up
    assert_dependencies_released(workspace, m)
Пример #42
0
def test_browing_dialog_profiles_edit(exopy_qtbot, prof_plugin, dialog_sleep):
    """Test the browsing dialog page dedicated to explore the profiles.

    """
    d = BrowsingDialog(plugin=prof_plugin)
    nb = d.central_widget().widgets()[0]
    nb.selected_tab = 'profiles'
    d.show()
    wait_for_window_displayed(exopy_qtbot, d)
    exopy_qtbot.wait(dialog_sleep)

    c = nb.pages()[0].page_widget()
    btn = c.widgets()[-2]
    c.p_id = 'fp1'

    manu = prof_plugin._manufacturers._manufacturers['Dummy']
    model = manu._series['dumb']._models['002']

    def handle(bot, dial):
        dial.profile_infos.model = model

    with handle_dialog(exopy_qtbot, 'reject', handle,
                       cls=ProfileEditionDialog):
        btn.clicked = True

    assert prof_plugin._profiles['fp1'].model != model

    def handle(bot, dial):
        assert not dial.creation
        dial.profile_infos.model = model
        dial.central_widget().widgets()[0].sync()

    with handle_dialog(exopy_qtbot, 'accept', handle,
                       cls=ProfileEditionDialog):
        btn.clicked = True

    assert prof_plugin._profiles['fp1'].model == model
    assert (ConfigObj(prof_plugin._profiles['fp1'].path)['model_id'] ==
            'Dummy.dumb.002')
Пример #43
0
    def test_display_current_log(self, app_dir, exopy_qtbot):
        """Test the log display window

        """
        cmd_args = CMDArgs()
        cmd_args.nocapture = True

        app = self.workbench.get_plugin('exopy.app')
        app.run_app_startup(cmd_args)

        core = self.workbench.get_plugin(u'enaml.workbench.core')
        with handle_dialog(exopy_qtbot):
            core.invoke_command('exopy.app.logging.display_current_log', {}, self)
Пример #44
0
def test_browing_dialog_profiles_edit(exopy_qtbot, prof_plugin, dialog_sleep):
    """Test the browsing dialog page dedicated to explore the profiles.

    """
    d = BrowsingDialog(plugin=prof_plugin)
    nb = d.central_widget().widgets()[0]
    nb.selected_tab = 'profiles'
    d.show()
    wait_for_window_displayed(exopy_qtbot, d)
    exopy_qtbot.wait(dialog_sleep)

    c = nb.pages()[0].page_widget()
    btn = c.widgets()[-2]
    c.p_id = 'fp1'

    manu = prof_plugin._manufacturers._manufacturers['Dummy']
    model = manu._series['dumb']._models['002']

    def handle(bot, dial):
        dial.profile_infos.model = model

    with handle_dialog(exopy_qtbot, 'reject', handle,
                       cls=ProfileEditionDialog):
        btn.clicked = True

    assert prof_plugin._profiles['fp1'].model != model

    def handle(bot, dial):
        assert not dial.creation
        dial.profile_infos.model = model
        dial.central_widget().widgets()[0].sync()

    with handle_dialog(exopy_qtbot, 'accept', handle,
                       cls=ProfileEditionDialog):
        btn.clicked = True

    assert prof_plugin._profiles['fp1'].model == model
    assert (ConfigObj(
        prof_plugin._profiles['fp1'].path)['model_id'] == 'Dummy.dumb.002')
Пример #45
0
def test_measurement_view(measurement, exopy_qtbot, dialog_sleep, monkeypatch,
                          workspace):
    """Test that the displayed buttons do reflect the state of the measurement.

    """
    measurement.status = 'READY'
    view = MeasView(model=measurement)
    w = ContainerTestingWindow(widget=view)

    w.show()
    wait_for_window_displayed(exopy_qtbot, w)
    exopy_qtbot.wait(dialog_sleep)

    assert view.widgets()[2].enabled  # cd1 inserted its children before itself

    def test_state(bot, dial):
        assert dial.measurement.status == 'EDITING'

    with handle_dialog(exopy_qtbot, 'reject', handler=test_state):
        view.widgets()[2].clicked = True

    assert view.widgets()[-1].enabled
    measurement.plugin.processor.active = True

    def assert_enabled():
        assert not view.widgets()[-1].enabled
    exopy_qtbot.wait_until(assert_enabled)
    measurement.plugin.processor.active = False

    from exopy.measurement.workspace.workspace import MeasurementSpace
    spy = CallSpy()
    monkeypatch.setattr(MeasurementSpace, 'process_single_measurement', spy)
    view.widgets()[-1].clicked = True
    assert spy.called

    measurement.status = 'RUNNING'

    def assert_widgets():
        assert len(view.widgets()) == 2
    exopy_qtbot.wait_until(assert_widgets)

    measurement.status = 'COMPLETED'

    def assert_widgets():
        assert len(view.widgets()) == 3
    exopy_qtbot.wait_until(assert_widgets)
    spy = CallSpy()
    monkeypatch.setattr(MeasurementSpace, 'reenqueue_measurement', spy)
    view.widgets()[-1].clicked = True

    assert view.widgets()[1].text == 'COMPLETED'
Пример #46
0
def test_browing_dialog_profiles_add(exopy_qtbot, prof_plugin, dialog_sleep):
    """Test the browsing dialog page dedicated to explore the profiles.

    """
    d = BrowsingDialog(plugin=prof_plugin)
    nb = d.central_widget().widgets()[0]
    nb.selected_tab = 'profiles'
    d.show()
    wait_for_window_displayed(exopy_qtbot, d)
    exopy_qtbot.wait(dialog_sleep)

    btn = nb.pages()[0].page_widget().widgets()[-3]

    origin = prof_plugin.profiles[:]
    with handle_dialog(exopy_qtbot, 'reject', cls=ProfileEditionDialog):
        btn.clicked = True

    assert prof_plugin.profiles == origin

    def handle(bot, dial):
        assert dial.creation
        dial.profile_infos.id = 'test'
        dial.profile_infos.model = prof_plugin._profiles['fp1'].model

    with handle_dialog(exopy_qtbot, 'accept', handle,
                       cls=ProfileEditionDialog):
        btn.clicked = True

    # Wait for file notification to be treated
    exopy_qtbot.wait(1000)

    def assert_profiles():
        assert 'test' in prof_plugin.profiles
        assert os.path.isfile(os.path.join(prof_plugin._profiles_folders[0],
                                           'test.instr.ini'))
    exopy_qtbot.wait_until(assert_profiles)
Пример #47
0
def test_gathering_mode(err_workbench, exopy_qtbot):
    """Test gathering multiple errors.

    """
    core = err_workbench.get_plugin('enaml.workbench.core')
    core.invoke_command('exopy.app.errors.enter_error_gathering')

    core.invoke_command('exopy.app.errors.signal',
                        {'kind': 'stupid', 'msg': None})

    with pytest.raises(AssertionError):
        get_window(exopy_qtbot)

    with handle_dialog(exopy_qtbot):
        core.invoke_command('exopy.app.errors.exit_error_gathering')
Пример #48
0
def test_enqueueing_fail_runtime(workspace, monkeypatch, exopy_qtbot):
    """Test enqueueing a measurement for which runtimes cannot be collected.

    """
    m = workspace.plugin.edited_measurements.measurements[0]
    m.add_tool('pre-hook', 'dummy')
    monkeypatch.setattr(Flags, 'RUNTIME2_FAIL_COLLECT', True)
    with handle_dialog(exopy_qtbot):
        workspace.enqueue_measurement(m)

    assert not workspace.plugin.enqueued_measurements.measurements

    # Check dependencies are cleaned up
    assert_dependencies_released(workspace, m)

    w = workspace.plugin.workbench
    d = w.get_manifest('test.measurement')
    assert d.find('runtime_dummy2').called
Пример #49
0
def test_unmet_requirement(monkeypatch, pack_workbench, exopy_qtbot):
    """Test loading an extension package for which some requirements are not
    met.

    """
    patch_pkg(monkeypatch, [FalseEntryPoint(name='test', missing_require=True),
                            FalseEntryPoint(name='test2',
                                            manifests=[])])

    app = pack_workbench.get_plugin(APP_ID)
    with handle_dialog(exopy_qtbot):
        app.run_app_startup(object())

    plugin = pack_workbench.get_plugin(PACKAGES_ID)

    assert 'test' in plugin.packages
    assert 'test2' in plugin.packages
    assert 'load' in plugin.packages['test']
    assert not plugin._registered
Пример #50
0
def test_wrong_return_type(monkeypatch, pack_workbench, exopy_qtbot):
    """Test handling a wrong return type from the callable returned by load.

    """
    patch_pkg(monkeypatch, [FalseEntryPoint(name='test',
                                            manifests=Manifest1),
                            FalseEntryPoint(name='test2',
                                            manifests=[])])

    app = pack_workbench.get_plugin(APP_ID)
    with handle_dialog(exopy_qtbot):
        app.run_app_startup(object())

    plugin = pack_workbench.get_plugin(PACKAGES_ID)

    assert 'test' in plugin.packages
    assert 'test2' in plugin.packages
    assert 'list' in plugin.packages['test']
    assert not plugin._registered
Пример #51
0
def test_non_manifest(monkeypatch, pack_workbench, exopy_qtbot):
    """Test handling a non PluginManifest in the list of manifests.

    """
    patch_pkg(monkeypatch, [FalseEntryPoint(name='test',
                                            manifests=[Manifest1, object]),
                            FalseEntryPoint(name='test2',
                                            manifests=[])])

    app = pack_workbench.get_plugin(APP_ID)
    with handle_dialog(exopy_qtbot):
        app.run_app_startup(object())

    plugin = pack_workbench.get_plugin(PACKAGES_ID)

    assert 'test' in plugin.packages
    assert 'test2' in plugin.packages
    assert 'PluginManifests' in plugin.packages['test']
    assert not plugin._registered
Пример #52
0
def test_registering_issue(monkeypatch, pack_workbench, exopy_qtbot):
    """Test handling an error when registering a manifest.

    """
    patch_pkg(monkeypatch, [FalseEntryPoint(name='test',
                                            manifests=[Manifest1, Manifest1]),
                            FalseEntryPoint(name='test2',
                                            manifests=[])])

    app = pack_workbench.get_plugin(APP_ID)
    with handle_dialog(exopy_qtbot):
        app.run_app_startup(object())

    plugin = pack_workbench.get_plugin(PACKAGES_ID)

    assert 'test' in plugin.packages
    assert 'test2' in plugin.packages
    assert 'exopy.test1' in plugin.packages['test']
    assert len(plugin.packages['test']) == 1