def test_changing_context_sequence(task_view, windows):
    """Test changing the context of a sequence.

    This should trigger a new validation of the driver.

    """
    show_widget(task_view)
    task = task_view.task
    task.selected_instrument = ("p", "ecpy_pulses.TestDriver", "c", "s")

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

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

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

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

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

    task.selected_instrument = ("p", "__dummy__", "c", "s")
    with handle_question("yes"):
        task.sequence.context = TestContext()
    assert not task.selected_instrument[0]
Example #2
0
def test_changing_context_sequence(task_view, windows):
    """Test changing the context of a sequence.

    This should trigger a new validation of the driver.

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

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

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

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

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

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

    task.selected_instrument = ('p', '__dummy__',  'c', 's')
    with handle_question('yes'):
        task.sequence.context = TestContext()
    assert not task.selected_instrument[0]
Example #3
0
def test_new_sequence(workspace, windows, process_and_sleep):
    """Test creating a new sequence.

    """
    workbench = workspace.workbench
    ui = workbench.get_plugin('enaml.workbench.ui')
    ui.show_window()
    process_and_sleep()

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

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

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

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

    assert old_seq is workspace.state.sequence
Example #4
0
def test_new_sequence(workspace, windows, process_and_sleep):
    """Test creating a new sequence.

    """
    workbench = workspace.workbench
    ui = workbench.get_plugin('enaml.workbench.ui')
    ui.show_window()
    process_and_sleep()

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

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

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

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

    assert old_seq is workspace.state.sequence
Example #5
0
def test_checks_display_not_warning_force_enqueue(windows, dialog_sleep):
    """Test displaying checks for a situation that do not allow enqueuing.

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

    dial.show()
    process_app_events()
    sleep(dialog_sleep)

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

    with handle_question('yes'):
        dial.central_widget().widgets()[-1].clicked = True
    process_app_events()
    assert dial.result
Example #6
0
def test_load_refresh_save2(task_view, monkeypatch, process_and_sleep,
                            windows):
    """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(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 ecpy_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('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
Example #7
0
def test_load_refresh_save(task_view, monkeypatch, process_and_sleep, windows):
    """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(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
    process_and_sleep()
    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

    old_seq = task_view.task.sequence
    task_view.task.sequence_vars = OrderedDict()
    # Refresh
    with handle_question('no'):
        task_view.widgets()[4].clicked = True
    assert task_view.task.sequence is old_seq
    with handle_question('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('no'):
        btn.clicked = True
        actions[0].triggered = True
    assert task_view.task.sequence_timestamp == old_timestamp
    with handle_question('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'
def test_load_refresh_save(task_view, monkeypatch, process_and_sleep, windows):
    """Test loading a sequence, refreshing, modifying and saving.

    """
    from enaml.widgets.api import FileDialogEx

    @classmethod
    def get_filename(cls, parent, 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(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 = {"a": "1*23", "c": "1"}
    # Load
    task_view.widgets()[2].clicked = True
    process_and_sleep()
    assert task_view.task.sequence is not old_seq
    assert task_view.task.sequence_vars == {"a": "1*23"}
    assert not task_view.widgets()[4].style_class

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

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

    @classmethod
    def get_save_filename1(cls, parent, path, name_filters):
        return ""

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

    @classmethod
    def get_save_filename2(cls, parent, 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"