Пример #1
0
def test_changing_context_sequence(task_view, exopy_qtbot):
    """Test changing the context of a sequence.

    This should trigger a new validation of the driver.

    """
    show_widget(exopy_qtbot, task_view)
    task = task_view.task
    task.selected_instrument = ('p', 'exopy_pulses.TestDriver', 'c', 's')

    task.sequence.context = None
    assert task.selected_instrument[0]

    task.selected_instrument = ('p', '__dummy__', 'c', 's')
    with handle_question(exopy_qtbot, 'yes'):
        task.sequence.context = DummyContext()
    assert not task.selected_instrument[0]

    # Test changing the sequence.
    task.selected_instrument = ('p', '__dummy__', 'c', 's')
    with handle_question(exopy_qtbot, 'yes'):
        task.sequence = sequence()
    assert not task.selected_instrument[0]

    # Check  the observer has been installed on the new sequence.
    task.selected_instrument = ('p', 'exopy_pulses.TestDriver', 'c', 's')

    task.sequence.context = None
    assert task.selected_instrument[0]

    task.selected_instrument = ('p', '__dummy__', 'c', 's')
    with handle_question(exopy_qtbot, 'yes'):
        task.sequence.context = DummyContext()
    assert not task.selected_instrument[0]
Пример #2
0
def test_closing_measurement(exopy_qtbot, edition_view, monkeypatch,
                             dialog_sleep):
    """Test closing the measurement dock item.

    """
    edition_view.show()
    wait_for_window_displayed(exopy_qtbot, edition_view)
    exopy_qtbot.wait(dialog_sleep)

    # Open the tools edition panel to check that we will properly close the
    # it later
    ed = edition_view.widget.dock_widget().widgets()[0]
    btn = ed.widgets()[4]

    btn.clicked = True
    exopy_qtbot.wait(10)

    with handle_question(exopy_qtbot, None):
        edition_view.widget.proxy.on_closed()
    edition_view.widget.measurement.name = 'First'

    def assert_dock():
        assert len(edition_view.area.dock_items()) == 2

    exopy_qtbot.wait_until(assert_dock)
    exopy_qtbot.wait(dialog_sleep)

    with handle_question(exopy_qtbot, 'no'):
        edition_view.widget.proxy.on_closed()
    edition_view.widget.measurement.name = 'Second'

    exopy_qtbot.wait_until(assert_dock)
    exopy_qtbot.wait(dialog_sleep)

    with handle_question(exopy_qtbot, 'yes'):
        edition_view.widget.proxy.on_closed()

    def assert_dock_zero():
        assert len(edition_view.area.dock_items()) == 0

    exopy_qtbot.wait_until(assert_dock_zero)
Пример #3
0
def test_closing_measurement(exopy_qtbot, edition_view, monkeypatch, dialog_sleep):
    """Test closing the measurement dock item.

    """
    edition_view.show()
    wait_for_window_displayed(exopy_qtbot, edition_view)
    exopy_qtbot.wait(dialog_sleep)

    # Open the tools edition panel to check that we will properly close the
    # it later
    ed = edition_view.widget.dock_widget().widgets()[0]
    btn = ed.widgets()[4]

    btn.clicked = True
    exopy_qtbot.wait(10)

    with handle_question(exopy_qtbot, None):
        edition_view.widget.proxy.on_closed()
    edition_view.widget.measurement.name = 'First'

    def assert_dock():
        assert len(edition_view.area.dock_items()) == 2
    exopy_qtbot.wait_until(assert_dock)
    exopy_qtbot.wait(dialog_sleep)

    with handle_question(exopy_qtbot, 'no'):
        edition_view.widget.proxy.on_closed()
    edition_view.widget.measurement.name = 'Second'

    exopy_qtbot.wait_until(assert_dock)
    exopy_qtbot.wait(dialog_sleep)

    with handle_question(exopy_qtbot, 'yes'):
        edition_view.widget.proxy.on_closed()

    def assert_dock_zero():
        assert len(edition_view.area.dock_items()) == 0
    exopy_qtbot.wait_until(assert_dock_zero)
Пример #4
0
def test_new_sequence(workspace, exopy_qtbot, dialog_sleep):
    """Test creating a new sequence.

    """
    workbench = workspace.workbench
    ui = workbench.get_plugin('enaml.workbench.ui')
    ui.show_window()
    exopy_qtbot.wait(10 + dialog_sleep)

    core = workbench.get_plugin('enaml.workbench.core')
    old_seq = workspace.state.sequence

    with handle_question(exopy_qtbot, 'yes'):
        cmd = 'exopy.pulses.workspace.new'
        core.invoke_command(cmd, dict())

    assert old_seq is not workspace.state.sequence
    old_seq = workspace.state.sequence

    with handle_question(exopy_qtbot, 'no'):
        cmd = 'exopy.pulses.workspace.new'
        core.invoke_command(cmd, dict())

    assert old_seq is workspace.state.sequence
Пример #5
0
def test_checks_display_not_warning_force_enqueue(exopy_qtbot, dialog_sleep):
    """Test displaying checks for a situation that do not allow enqueuing.

    """
    dial = ChecksDisplay(errors={'test': 'dummy', 'complex': {'rr': 'tt'}})

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

    assert dial.central_widget().widgets()[-1].text == 'Force enqueue'

    with handle_question(exopy_qtbot, 'yes'):
        dial.central_widget().widgets()[-1].clicked = True

    def assert_result():
        assert dial.result
    exopy_qtbot.wait_until(assert_result)
Пример #6
0
def test_load_refresh_save2(task_view, monkeypatch, exopy_qtbot):
    """Test loading a sequence, refreshing, modifying and saving.

    Test handling the case of an empty sequence_path

    """
    from enaml.widgets.api import FileDialogEx

    @classmethod
    def get_filename(cls, parent, current_path, name_filters):
        return task_view.task.sequence_path

    monkeypatch.setattr(FileDialogEx, 'get_open_file_name', get_filename)

    task_view.task.sequence_path = ''

    show_widget(exopy_qtbot, task_view)

    task_view.task.sequence_vars = OrderedDict()
    # Refresh
    button = task_view.widgets()[4]
    assert not button.enabled

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

    with enaml.imports():
        from exopy_pulses.tasks.tasks.instrs.views\
            import transfer_sequence_task_view
    old = transfer_sequence_task_view.load_sequence
    monkeypatch.setattr(transfer_sequence_task_view, 'load_sequence',
                        false_load)
    with handle_question(exopy_qtbot, 'OK'):
        button.clicked = True

    monkeypatch.setattr(transfer_sequence_task_view, 'load_sequence', old)

    # Save
    btn = task_view.widgets()[5]
    actions = btn.menu().items()
    assert not actions[0].enabled
Пример #7
0
def test_load_refresh_save(task_view, monkeypatch, exopy_qtbot, dialog_sleep):
    """Test loading a sequence, refreshing, modifying and saving.

    """
    from enaml.widgets.api import FileDialogEx

    @classmethod
    def get_filename(cls, parent, current_path, name_filters):
        return task_view.task.sequence_path

    monkeypatch.setattr(FileDialogEx, 'get_open_file_name', get_filename)

    task_view.task.sequence_timestamp = -1

    show_widget(exopy_qtbot, task_view)
    # Check detection of outdated sequence
    assert task_view.widgets()[4].style_class

    old_seq = task_view.task.sequence
    task_view.task.sequence_vars = OrderedDict([('a', '1*23'), ('c', '1')])
    # Load
    task_view.widgets()[2].clicked = True

    def assert_exec():
        assert task_view.task.sequence is not old_seq
        assert task_view.task.sequence_vars == OrderedDict({'a': '1*23'})
        assert not task_view.widgets()[4].style_class

    exopy_qtbot.wait_until(assert_exec)

    old_seq = task_view.task.sequence
    task_view.task.sequence_vars = OrderedDict()
    # Refresh
    with handle_question(exopy_qtbot, 'no'):
        task_view.widgets()[4].clicked = True
    assert task_view.task.sequence is old_seq
    with handle_question(exopy_qtbot, 'yes'):
        task_view.widgets()[4].clicked = True
    assert task_view.task.sequence is not old_seq
    assert task_view.task.sequence_vars == OrderedDict({'a': ''})

    old_timestamp = task_view.task.sequence_timestamp
    # Save
    btn = task_view.widgets()[5]
    actions = btn.menu().items()
    with handle_question(exopy_qtbot, 'no'):
        btn.clicked = True
        actions[0].triggered = True
    assert task_view.task.sequence_timestamp == old_timestamp
    with handle_question(exopy_qtbot, 'yes'):
        btn.clicked = True
        actions[0].triggered = True
    sleep(0.1)
    assert task_view.task.sequence_timestamp != old_timestamp

    @classmethod
    def get_save_filename1(cls, parent, current_path, name_filters):
        return ''

    new_path = task_view.task.sequence_path.rstrip('.pulse.ini')
    new_path += '2'

    @classmethod
    def get_save_filename2(cls, parent, current_path, name_filters):
        return new_path

    old_timestamp = task_view.task.sequence_timestamp
    # Save as
    monkeypatch.setattr(FileDialogEx, 'get_save_file_name', get_save_filename1)
    btn.clicked = True
    actions[1].triggered = True
    assert task_view.task.sequence_timestamp == old_timestamp

    monkeypatch.setattr(FileDialogEx, 'get_save_file_name', get_save_filename2)
    btn.clicked = True
    actions[1].triggered = True
    assert task_view.task.sequence_timestamp != old_timestamp
    assert task_view.task.sequence_path == new_path + '.pulse.ini'