예제 #1
0
파일: test_saving.py 프로젝트: Ecpy/ecpy
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']
예제 #2
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']
예제 #3
0
def test_measurement_edition_dialog(exopy_qtbot, workspace, measurement,
                                    monkeypatch, dialog_sleep):
    """Test creating a measurement edition dialog.

    """
    dialog = MeasureEditorDialog(workspace=workspace, measurement=measurement)
    dialog.show()
    wait_for_window_displayed(exopy_qtbot, dialog)
    exopy_qtbot.wait(dialog_sleep)

    from exopy.measurement.workspace.workspace import MeasurementSpace

    def false_save(self, meas, *args, **kwargs):
        false_save.called = 1

    monkeypatch.setattr(MeasurementSpace, 'save_measurement', false_save)

    btn = dialog.central_widget().widgets()[-1]
    btn.clicked = True

    def assert_called():
        assert false_save.called
    exopy_qtbot.wait_until(assert_called)

    dialog.close()
    wait_for_destruction(exopy_qtbot, dialog)
예제 #4
0
def test_measurement_edition_dialog(exopy_qtbot, workspace, measurement,
                                    monkeypatch, dialog_sleep):
    """Test creating a measurement edition dialog.

    """
    dialog = MeasureEditorDialog(workspace=workspace, measurement=measurement)
    dialog.show()
    wait_for_window_displayed(exopy_qtbot, dialog)
    exopy_qtbot.wait(dialog_sleep)

    from exopy.measurement.workspace.workspace import MeasurementSpace

    def false_save(self, meas, *args, **kwargs):
        false_save.called = 1

    monkeypatch.setattr(MeasurementSpace, 'save_measurement', false_save)

    btn = dialog.central_widget().widgets()[-1]
    btn.clicked = True

    def assert_called():
        assert false_save.called

    exopy_qtbot.wait_until(assert_called)

    dialog.close()
    wait_for_destruction(exopy_qtbot, dialog)
예제 #5
0
def test_creating_a_visa_connection(prof_plugin, exopy_qtbot, caplog):
    """Test creating a Visa connection through VisaConnection.new

    """
    c = prof_plugin.create_connection('VisaTCPIP', {'__junk': ''}, True)
    w = show_widget(exopy_qtbot, c)
    assert caplog.records
    assert c.read_only
    w.close()
    wait_for_destruction(exopy_qtbot, w)
예제 #6
0
def test_creating_new_custom_entry(monitor, exopy_qtbot, dialog_sleep):
    """Test creating an  entry using the dialog.

    """
    d = EntryDialog(monitor=monitor)
    d.show()
    wait_for_window_displayed(exopy_qtbot, d)
    exopy_qtbot.wait(dialog_sleep)

    w = d.central_widget().widgets()
    w[1].text = 'test'
    exopy_qtbot.wait(10 + dialog_sleep)

    w[5].text = '{root/test}, {simp/test}, {comp/test}'
    exopy_qtbot.wait(10 + dialog_sleep)

    b = d.builder
    for e in ('root/test', 'simp/test', 'comp/test'):
        assert e in b.map_entries
    b.add_entry(0, 'after')
    assert b.used_entries
    exopy_qtbot.wait(10 + dialog_sleep)

    b.used_entries[0].entry = 'root/test'
    exopy_qtbot.wait(10 + dialog_sleep)

    b.add_entry(0, 'after')
    assert not b.used_entries[-1].entry
    exopy_qtbot.wait(10 + dialog_sleep)

    b.used_entries[-1].entry = 'simp/test'
    exopy_qtbot.wait(10 + dialog_sleep)

    b.add_entry(0, 'before')
    assert not b.used_entries[0].entry
    exopy_qtbot.wait(10 + dialog_sleep)

    b.used_entries[0].entry = 'comp/test'
    exopy_qtbot.wait(10 + dialog_sleep)

    w[-2].clicked = True

    def assert_entry():
        assert d.entry

    exopy_qtbot.wait_until(assert_entry)

    e = d.entry
    assert e.name == 'test'
    assert (sorted(e.depend_on) == sorted(
        ('root/test', 'root/simp/test', 'root/comp/test')))

    d.close()
    wait_for_destruction(exopy_qtbot, d)
예제 #7
0
파일: test_custom.py 프로젝트: Ecpy/ecpy
def test_creating_new_custom_entry(monitor, exopy_qtbot, dialog_sleep):
    """Test creating an  entry using the dialog.

    """
    d = EntryDialog(monitor=monitor)
    d.show()
    wait_for_window_displayed(exopy_qtbot, d)
    exopy_qtbot.wait(dialog_sleep)

    w = d.central_widget().widgets()
    w[1].text = 'test'
    exopy_qtbot.wait(10 + dialog_sleep)

    w[5].text = '{root/test}, {simp/test}, {comp/test}'
    exopy_qtbot.wait(10 + dialog_sleep)

    b = d.builder
    for e in ('root/test', 'simp/test', 'comp/test'):
        assert e in b.map_entries
    b.add_entry(0, 'after')
    assert b.used_entries
    exopy_qtbot.wait(10 + dialog_sleep)

    b.used_entries[0].entry = 'root/test'
    exopy_qtbot.wait(10 + dialog_sleep)

    b.add_entry(0, 'after')
    assert not b.used_entries[-1].entry
    exopy_qtbot.wait(10 + dialog_sleep)

    b.used_entries[-1].entry = 'simp/test'
    exopy_qtbot.wait(10 + dialog_sleep)

    b.add_entry(0, 'before')
    assert not b.used_entries[0].entry
    exopy_qtbot.wait(10 + dialog_sleep)

    b.used_entries[0].entry = 'comp/test'
    exopy_qtbot.wait(10 + dialog_sleep)

    w[-2].clicked = True

    def assert_entry():
        assert d.entry
    exopy_qtbot.wait_until(assert_entry)

    e = d.entry
    assert e.name == 'test'
    assert (sorted(e.depend_on) ==
            sorted(('root/test', 'root/simp/test', 'root/comp/test')))

    d.close()
    wait_for_destruction(exopy_qtbot, d)
예제 #8
0
def test_validating_connection_default(id, defaults, should_log, exopy_qtbot,
                                       caplog, prof_plugin):
    """Test that keyword filtering works as expected.

    """
    caplog.set_level(logging.INFO)
    c = prof_plugin.create_connection(id, defaults, False)
    w = show_widget(exopy_qtbot, c)
    if should_log:
        assert caplog.records
    else:
        assert not caplog.records
    assert not c.read_only
    w.close()
    wait_for_destruction(exopy_qtbot, w)
예제 #9
0
def test_rule_edition_dialog(text_monitor_workbench, exopy_qtbot,
                             dialog_sleep):
    """Test editing a rule using the dialog widget.

    """
    p = text_monitor_workbench.get_plugin(PLUGIN_ID)
    m = p.create_monitor(False)
    m.handle_database_entries_change(('added', 'root/test_f', 0))

    d = EditRulesView(monitor=m)
    d.show()
    wait_for_window_displayed(exopy_qtbot, d)
    exopy_qtbot.wait(dialog_sleep)

    # Create a new rule
    psh_btn = d.central_widget().widgets()[-4]

    def create(bot, dial):
        dial.rule = RejectRule(id='__dummy', suffixes=['f'])

    with handle_dialog(exopy_qtbot, handler=create, cls=CreateRuleDialog):
        psh_btn.clicked = True

    assert any([r.id == '__dummy' for r in m.rules])
    assert not m.displayed_entries

    qlist = d.central_widget().widgets()[0]
    qlist.selected_item = [r for r in m.rules if r.id == '__dummy'][0]

    def assert_rule():
        assert d.central_widget().widgets()[1].rule
    exopy_qtbot.wait_until(assert_rule)
    exopy_qtbot.wait(dialog_sleep)

    # Save rule and save and add to default
    try:
        psh_btn = d.central_widget().widgets()[-2]
        act = psh_btn.children[0].children[0]
        act.triggered = True

        def assert_rules():
            assert '__dummy' in p.rules
            assert '__dummy' not in p.default_rules
        exopy_qtbot.wait_until(assert_rules)
        del p._user_rules['__dummy']

        act = psh_btn.children[0].children[1]
        act.triggered = True

        def assert_rules():
            assert '__dummy' in p.rules
            assert '__dummy' in p.default_rules
        exopy_qtbot.wait_until(assert_rules)

    finally:
        if '__dummy' in p._user_rules:
            del p._user_rules['__dummy']

    # Delete rule
    psh_btn = d.central_widget().widgets()[-3]
    psh_btn.clicked = True

    def assert_rules():
        assert '__dummy' not in m.rules
        assert m.displayed_entries
    exopy_qtbot.wait_until(assert_rules)

    d.central_widget().widgets()[-1].clicked = True
    wait_for_destruction(exopy_qtbot, d)
예제 #10
0
def test_execution_editor_widget(exopy_qtbot, task, dialog_sleep):
    """Test the behavior of the execution editor widget.

    """
    task.children[1].children[0].parallel = {}

    def get_task_widget(editor):
        """Get the widget associated with the currently selected task.

        """
        return editor.page_widget().widgets()[0].scroll_widget().widgets()[0]

    editor = ExecutionEditor(declaration=Editor(id='exopy.execution_editor'),
                             selected_task=task)
    window = PageTestingWindow(widget=editor)
    window.show()
    wait_for_window_displayed(exopy_qtbot, window)
    exopy_qtbot.wait(dialog_sleep)

    # Select the complex task (ref ctask)
    ctask = task.children[1]
    editor.selected_task = ctask
    exopy_qtbot.wait(10 + dialog_sleep)

    # Get the widget (ced) associated with ctask and alter the stoppable
    # setting and the change propagation
    ced = get_task_widget(editor)
    ced.widgets()[0].checked = not ctask.stoppable

    def assert_stoppable():
        assert ced.widgets()[0].checked == ctask.stoppable
    exopy_qtbot.wait_until(assert_stoppable)
    exopy_qtbot.wait(dialog_sleep)

    # Ask the editor to hide its children by clicking the button (this does
    # not check that the layout actually changed simply that is is correct)
    full_ced = ced.parent
    full_ced.widgets()[-2].clicked = True
    assert full_ced.widgets()[-1].visible is False
    assert not full_ced.widgets()[-1].layout_constraints()

    # Undo
    full_ced.widgets()[-2].clicked = True
    assert full_ced.widgets()[-1].visible is True
    assert full_ced.widgets()[-1].layout_constraints()

    # Set the complex task in parallel and check the update of the list of
    # pools
    ctask.parallel['pool'] = 'test_'
    ced.widgets()[1].checked = True

    def assert_pools():
        assert 'test_' in editor.pool_model.pools
    exopy_qtbot.wait_until(assert_pools)
    exopy_qtbot.wait(dialog_sleep)

    # Unset the wait setting, change the waiting pool, set the wait and check
    # the list of pools
    ced.widgets()[3].checked = False
    exopy_qtbot.wait(10 + dialog_sleep)
    ctask.wait['no_wait'] = ['test2']
    ced.widgets()[3].checked = True

    def assert_pools():
        assert 'test2' in editor.pool_model.pools
    exopy_qtbot.wait_until(assert_pools)
    exopy_qtbot.wait(dialog_sleep)

    # Change the selected pool for parallel and check the list of pools
    ced.widgets()[2].selected = 'test2'

    def assert_pools():
        assert 'test' not in editor.pool_model.pools
    exopy_qtbot.wait_until(assert_pools)
    exopy_qtbot.wait(dialog_sleep)

    def get_popup_content(popup):
        return popup.central_widget().widgets()

    # Create a new pool using the context menu on parallell
    ced.widgets()[2].children[0].children[0].triggered = True
    popup = get_popup(exopy_qtbot)
    popup_content = get_popup_content(popup)
    popup_content[0].text = 'test3'
    popup_content[1].clicked = True

    def assert_pools():
        assert 'test3' in editor.pool_model.pools
    exopy_qtbot.wait_until(assert_pools)
    exopy_qtbot.wait(dialog_sleep)
    wait_for_destruction(exopy_qtbot, popup)

    # Create a new pool using the context menu on parallell, but cancel it
    ced.widgets()[2].children[0].children[0].triggered = True
    popup = get_popup(exopy_qtbot)
    popup_content = get_popup_content(popup)
    popup_content[0].text = 'test4'
    popup_content[2].clicked = True

    def assert_pools():
        assert 'test4' not in editor.pool_model.pools
    exopy_qtbot.wait_until(assert_pools)
    exopy_qtbot.wait(dialog_sleep)
    wait_for_destruction(exopy_qtbot, popup)

    # Check we were set on no_wait and switch to wait
    assert ced.widgets()[4].widgets()[0].checked is False
    ced.widgets()[4].widgets()[0].checked = True

    def assert_wait():
        assert 'wait' in ctask.wait and 'no_wait' not in ctask.wait
    exopy_qtbot.wait_until(assert_wait)
    exopy_qtbot.wait(dialog_sleep)

    # Use the popup to edit the list of pools on which to wait.
    # Click ok at the end
    btt = ced.widgets()[4].widgets()[-1]  # ref to the push button
    btt.clicked = True
    popup = get_popup(exopy_qtbot)
    popup_content = get_popup_content(popup)
    check_box = popup_content[0].scroll_widget().widgets()[1]
    assert not check_box.checked
    check_box.checked = True
    exopy_qtbot.wait(10 + dialog_sleep)
    popup_content[-2].clicked = True

    def assert_wait():
        assert 'test3' in ctask.wait['wait']
    exopy_qtbot.wait_until(assert_wait)
    wait_for_destruction(exopy_qtbot, popup)
    exopy_qtbot.wait(dialog_sleep)

    # Use the popup to edit the list of pools on which to wait.
    # Click cancel at the end
    btt.clicked = True
    popup = get_popup(exopy_qtbot)
    popup_content = get_popup_content(popup)
    check_box = popup_content[0].scroll_widget().widgets()[2]
    assert not check_box.checked
    check_box.checked = True
    exopy_qtbot.wait(10 + dialog_sleep)
    popup_content[-1].clicked = True

    def assert_wait():
        assert 'test_' not in ctask.wait['wait']
    exopy_qtbot.wait_until(assert_wait)
    wait_for_destruction(exopy_qtbot, popup)
    exopy_qtbot.wait(dialog_sleep)

    # Test moving a task and switching between different editors
    editor.selected_task = task
    task.move_child_task(0, 1)
    exopy_qtbot.wait(10 + dialog_sleep)
    editor.selected_task = task.children[0]
    exopy_qtbot.wait(10 + dialog_sleep)
    editor.selected_task = task.children[1]
    exopy_qtbot.wait(10 + dialog_sleep)
    editor.selected_task = task

    # Test removing a task and switching between different editors
    # First select the ctask child so that its view is not parented to the view
    editor.selected_task = ctask.children[0]

    # Then select a task that will not reparent it
    editor.selected_task = task.children[0]
    task.remove_child_task(0)
    exopy_qtbot.wait(10 + dialog_sleep)
    editor.selected_task = task.children[0]
    exopy_qtbot.wait(10 + dialog_sleep)
    editor.selected_task = task
    exopy_qtbot.wait(10 + dialog_sleep)
    assert ctask not in editor._cache
    # Try removing again this view which should not crash
    editor.discard_view(task)
    # Check the view was properly destroyed and removed
    assert ctask.children[0] not in editor._cache

    editor.ended = True
예제 #11
0
def test_execution_editor_widget(exopy_qtbot, task, dialog_sleep):
    """Test the behavior of the execution editor widget.

    """
    task.children[1].children[0].parallel = {}

    def get_task_widget(editor):
        """Get the widget associated with the currently selected task.

        """
        return editor.page_widget().widgets()[0].scroll_widget().widgets()[0]

    editor = ExecutionEditor(declaration=Editor(id='exopy.execution_editor'),
                             selected_task=task)
    window = PageTestingWindow(widget=editor)
    window.show()
    wait_for_window_displayed(exopy_qtbot, window)
    exopy_qtbot.wait(dialog_sleep)

    # Select the complex task (ref ctask)
    ctask = task.children[1]
    editor.selected_task = ctask
    exopy_qtbot.wait(10 + dialog_sleep)

    # Get the widget (ced) associated with ctask and alter the stoppable
    # setting and the change propagation
    ced = get_task_widget(editor)
    ced.widgets()[0].checked = not ctask.stoppable

    def assert_stoppable():
        assert ced.widgets()[0].checked == ctask.stoppable

    exopy_qtbot.wait_until(assert_stoppable)
    exopy_qtbot.wait(dialog_sleep)

    # Ask the editor to hide its children by clicking the button (this does
    # not check that the layout actually changed simply that is is correct)
    full_ced = ced.parent
    full_ced.widgets()[-2].clicked = True
    assert full_ced.widgets()[-1].visible is False
    assert not full_ced.widgets()[-1].layout_constraints()

    # Undo
    full_ced.widgets()[-2].clicked = True
    assert full_ced.widgets()[-1].visible is True
    assert full_ced.widgets()[-1].layout_constraints()

    # Set the complex task in parallel and check the update of the list of
    # pools
    ctask.parallel['pool'] = 'test_'
    ced.widgets()[1].checked = True

    def assert_pools():
        assert 'test_' in editor.pool_model.pools

    exopy_qtbot.wait_until(assert_pools)
    exopy_qtbot.wait(dialog_sleep)

    # Unset the wait setting, change the waiting pool, set the wait and check
    # the list of pools
    ced.widgets()[3].checked = False
    exopy_qtbot.wait(10 + dialog_sleep)
    ctask.wait['no_wait'] = ['test2']
    ced.widgets()[3].checked = True

    def assert_pools():
        assert 'test2' in editor.pool_model.pools

    exopy_qtbot.wait_until(assert_pools)
    exopy_qtbot.wait(dialog_sleep)

    # Change the selected pool for parallel and check the list of pools
    ced.widgets()[2].selected = 'test2'

    def assert_pools():
        assert 'test' not in editor.pool_model.pools

    exopy_qtbot.wait_until(assert_pools)
    exopy_qtbot.wait(dialog_sleep)

    def get_popup_content(popup):
        return popup.central_widget().widgets()

    # Create a new pool using the context menu on parallell
    ced.widgets()[2].children[0].children[0].triggered = True
    popup = get_popup(exopy_qtbot)
    popup_content = get_popup_content(popup)
    popup_content[0].text = 'test3'
    popup_content[1].clicked = True

    def assert_pools():
        assert 'test3' in editor.pool_model.pools

    exopy_qtbot.wait_until(assert_pools)
    exopy_qtbot.wait(dialog_sleep)
    wait_for_destruction(exopy_qtbot, popup)

    # Create a new pool using the context menu on parallell, but cancel it
    ced.widgets()[2].children[0].children[0].triggered = True
    popup = get_popup(exopy_qtbot)
    popup_content = get_popup_content(popup)
    popup_content[0].text = 'test4'
    popup_content[2].clicked = True

    def assert_pools():
        assert 'test4' not in editor.pool_model.pools

    exopy_qtbot.wait_until(assert_pools)
    exopy_qtbot.wait(dialog_sleep)
    wait_for_destruction(exopy_qtbot, popup)

    # Check we were set on no_wait and switch to wait
    assert ced.widgets()[4].widgets()[0].checked is False
    ced.widgets()[4].widgets()[0].checked = True

    def assert_wait():
        assert 'wait' in ctask.wait and 'no_wait' not in ctask.wait

    exopy_qtbot.wait_until(assert_wait)
    exopy_qtbot.wait(dialog_sleep)

    # Use the popup to edit the list of pools on which to wait.
    # Click ok at the end
    btt = ced.widgets()[4].widgets()[-1]  # ref to the push button
    btt.clicked = True
    popup = get_popup(exopy_qtbot)
    popup_content = get_popup_content(popup)
    check_box = popup_content[0].scroll_widget().widgets()[1]
    assert not check_box.checked
    check_box.checked = True
    exopy_qtbot.wait(10 + dialog_sleep)
    popup_content[-2].clicked = True

    def assert_wait():
        assert 'test3' in ctask.wait['wait']

    exopy_qtbot.wait_until(assert_wait)
    wait_for_destruction(exopy_qtbot, popup)
    exopy_qtbot.wait(dialog_sleep)

    # Use the popup to edit the list of pools on which to wait.
    # Click cancel at the end
    btt.clicked = True
    popup = get_popup(exopy_qtbot)
    popup_content = get_popup_content(popup)
    check_box = popup_content[0].scroll_widget().widgets()[2]
    assert not check_box.checked
    check_box.checked = True
    exopy_qtbot.wait(10 + dialog_sleep)
    popup_content[-1].clicked = True

    def assert_wait():
        assert 'test_' not in ctask.wait['wait']

    exopy_qtbot.wait_until(assert_wait)
    wait_for_destruction(exopy_qtbot, popup)
    exopy_qtbot.wait(dialog_sleep)

    # Test moving a task and switching between different editors
    editor.selected_task = task
    task.move_child_task(0, 1)
    exopy_qtbot.wait(10 + dialog_sleep)
    editor.selected_task = task.children[0]
    exopy_qtbot.wait(10 + dialog_sleep)
    editor.selected_task = task.children[1]
    exopy_qtbot.wait(10 + dialog_sleep)
    editor.selected_task = task

    # Test removing a task and switching between different editors
    # First select the ctask child so that its view is not parented to the view
    editor.selected_task = ctask.children[0]

    # Then select a task that will not reparent it
    editor.selected_task = task.children[0]
    task.remove_child_task(0)
    exopy_qtbot.wait(10 + dialog_sleep)
    editor.selected_task = task.children[0]
    exopy_qtbot.wait(10 + dialog_sleep)
    editor.selected_task = task
    exopy_qtbot.wait(10 + dialog_sleep)
    assert ctask not in editor._cache
    # Try removing again this view which should not crash
    editor.discard_view(task)
    # Check the view was properly destroyed and removed
    assert ctask.children[0] not in editor._cache

    editor.ended = True