Example #1
0
def test_get_accessible_vars():
    """Test getting the accessible vars of a sequence.

    """
    root = RootSequence(external_vars={'a': 1}, local_vars={'a2': '5'},
                        time_constrained=True)
    context = TestContext()
    root.context = context
    sequence1 = BaseSequence(local_vars={'b': '1'})
    sequence2 = BaseSequence(local_vars={'c': '2'})
    pulse = Pulse()

    sequence2.add_child_item(0, pulse)
    sequence1.add_child_item(0, sequence2)
    root.add_child_item(0, sequence1)

    variables = ['sequence_end', 'a', 'a2', '3_start', '3_stop',
                 '3_duration', 'b', 'c']
    lv = sequence2.get_accessible_vars()
    for v in variables:
        assert v in lv

    variables.pop()
    lv = sequence1.get_accessible_vars()
    for v in variables:
        assert v in lv

    variables.pop()
    lv = root.get_accessible_vars()
    for v in variables:
        assert v in lv
def test_build_from_config3(template_sequence, template_dependencies):
    """Test rebuilding a sequence including twice the same template sequence

    """
    conf = {'template_id': template_sequence, 'name': 'Template',
            'template_vars': "{'b': '19'}"}
    seq = TemplateSequence.build_from_config(conf, template_dependencies)
    seq.context.channel_mapping = {'A': 'Ch1_L', 'B': 'Ch2_L',
                                   'Ch1': 'Ch2_A', 'Ch2': 'Ch1_A'}

    conf = {'template_id': 'test', 'name': 'Template',
            'template_vars': "{'b': '12'}"}
    seq2 = TemplateSequence.build_from_config(conf, template_dependencies)
    seq2.context.channel_mapping = {'A': 'Ch1_L', 'B': 'Ch2_L',
                                    'Ch1': 'Ch1_A', 'Ch2': 'Ch2_A'}

    root = RootSequence()
    context = TestContext(sampling=0.5)
    root.context = context
    root.add_child_item(0, seq)
    root.add_child_item(0, seq2)
    pref = root.preferences_from_members()

    new = RootSequence.build_from_config(pref, template_dependencies)
    assert new.items[0].index == 1

    seq = new.items[0]
    assert seq.name == 'Template'
    assert seq.template_id == template_sequence
    assert seq.template_vars == dict(b='19')
    assert seq.local_vars == dict(a='1.5')
    assert len(seq.items) == 4
    assert seq.items[3].index == 5
    assert seq.docs == 'Basic user comment\nff'

    context = seq.context
    assert context.template == seq
    assert context.logical_channels == ['A', 'B']
    assert context.analogical_channel == ['Ch1', 'Ch2']
    assert context.channel_mapping == {'A': 'Ch1_L', 'B': 'Ch2_L',
                                       'Ch1': 'Ch2_A', 'Ch2': 'Ch1_A'}

    assert new.items[1].index == 2

    seq = new.items[1]
    assert seq.name == 'Template'
    assert seq.template_id == 'test'
    assert seq.template_vars == dict(b='12')
    assert seq.local_vars == dict(a='1.5')
    assert len(seq.items) == 4
    assert seq.items[3].index == 5
    assert seq.docs == 'Basic user comment\nff'

    context = seq.context
    assert context.template == seq
    assert context.logical_channels == ['A', 'B']
    assert context.analogical_channels == ['Ch1', 'Ch2']
    assert context.channel_mapping == {'A': 'Ch1_L', 'B': 'Ch2_L',
                                       'Ch1': 'Ch1_A', 'Ch2': 'Ch2_A'}
Example #3
0
def test_build_from_config():
    """Test building a pulse sequence.

    """
    root = RootSequence()
    context = TestContext()
    root.context = context
    root.external_vars = {'a': 1.5}

    pulse1 = Pulse(def_1='1.0', def_2='{a}')
    pulse2 = Pulse(def_1='{a} + 1.0', def_2='3.0')
    pulse3 = Pulse(def_1='{2_stop} + 0.5', def_2='10',
                   kind='Analogical', shape=SquareShape())
    pulse4 = Pulse(def_1='{2_stop} + 0.5', def_2='10',
                   kind='Analogical', shape=SquareShape())
    seq = BaseSequence()
    add_children(root, [pulse1, pulse2, pulse3, seq])
    add_children(seq, [pulse4])

    pref = root.preferences_from_members()
    dependecies = {'ecpy.pulses.items':
                   {'ecpy_pulses.BaseSequence': BaseSequence,
                    'ecpy_pulses.Pulse': Pulse},
                   'ecpy.pulses.shapes':
                   {'ecpy_pulses.SquareShape': SquareShape},
                   'ecpy.pulses.contexts':
                   {'ecpy_pulses.TestContext': TestContext}}

    aux = RootSequence.build_from_config(pref, dependecies)
    assert aux.external_vars == {'a': 1.5}
    assert len(aux.items) == 4
    assert isinstance(aux.context, TestContext)

    pulse1 = aux.items[0]
    assert pulse1.def_1 == '1.0'
    assert pulse1.def_2 == '{a}'

    pulse2 = aux.items[1]
    assert pulse2.def_1 == '{a} + 1.0'
    assert pulse2.def_2 == '3.0'

    pulse3 = aux.items[2]
    assert pulse3.def_1 == '{2_stop} + 0.5'
    assert pulse3.def_2 == '10'
    assert pulse3.kind == 'Analogical'
    assert isinstance(pulse3.shape, SquareShape)

    seq = aux.items[3]
    assert len(seq.items) == 1
def test_pulse_view(windows, workbench, process_and_sleep):
    """Test the view of the Pulse class.

    """
    from ecpy.testing.util import show_widget
    with enaml.imports():
        from ecpy_pulses.pulses.sequences.views.base_sequences_views\
            import RootSequenceView

    pulse = Pulse(root=RootSequence(context=TestContext()))
    pulse.kind = 'Analogical'
    root = pulse.root
    root.add_child_item(0, pulse)
    core = workbench.get_plugin('enaml.workbench.core')
    root_view = RootSequenceView(item=root, core=core)
    pulse_view = root_view.view_for(pulse)
    show_widget(root_view)
    process_and_sleep()

    # Test selecting a slope shape
    shape_select = pulse_view.widgets()[-1].widgets()[-1]
    shape_select.selected = 'ecpy_pulses.SlopeShape'
    process_and_sleep()

    shape_view = pulse_view.widgets()[-1]
    sv_widgets = shape_view.split_items()[0].split_widget().widgets()

    for mode in ('Start/Stop', 'Start/Slope', 'Slope/Stop'):
        sv_widgets[1].selected = mode
        process_and_sleep()
        assert sv_widgets[2].text == mode.split('/')[0]
        assert sv_widgets[4].text == mode.split('/')[1]
def root_with_template(template_sequence, template_dependencies):
    """Build a root using the template sequence.

    """
    root = RootSequence()
    root.context = TestContext(sampling=0.5)

    conf = {'template_id': template_sequence, 'name': 'Template',
            'template_vars': "{'b': '19'}"}
    seq = TemplateSequence.build_from_config(conf, template_dependencies)
    seq.context.channel_mapping = {'A': 'Ch1_L', 'B': 'Ch2_L',
                                   'Ch1': 'Ch2_A', 'Ch2': 'Ch1_A'}
    seq.def_1 = '1.0'
    seq.def_2 = '20.0'

    root.add_child_item(0, seq)
    return root
def test_get_accessible_vars():
    """Test getting the accessible vars of a sequence.

    """
    root = RootSequence(external_vars=OrderedDict({'a': 1}),
                        local_vars=OrderedDict({'a2': '5'}),
                        time_constrained=True)
    context = TestContext()
    root.context = context
    sequence1 = BaseSequence(local_vars=OrderedDict({'b': '1'}))
    sequence2 = BaseSequence(local_vars=OrderedDict({'c': '2'}))
    pulse = Pulse()

    sequence2.add_child_item(0, pulse)
    sequence1.add_child_item(0, sequence2)
    root.add_child_item(0, sequence1)

    variables = [
        'sequence_end', 'a', 'a2', '3_start', '3_stop', '3_duration', 'b', 'c'
    ]
    lv = sequence2.get_accessible_vars()
    for v in variables:
        assert v in lv

    variables.pop()
    lv = sequence1.get_accessible_vars()
    for v in variables:
        assert v in lv

    variables.pop()
    lv = root.get_accessible_vars()
    for v in variables:
        assert v in lv
def test_traverse_sequence():
    """Test traversing a pulse sequence.

    """
    root = RootSequence()
    context = TestContext()
    root.context = context
    root.external_vars = OrderedDict({'a': 1.5})

    pulse1 = Pulse(def_1='1.0', def_2='{a}')
    pulse2 = Pulse(def_1='{a} + 1.0', def_2='3.0')
    pulse3 = Pulse(def_1='{2_stop} + 0.5',
                   def_2='10',
                   kind='Analogical',
                   shape=SquareShape())
    pulse4 = Pulse(def_1='{2_stop} + 0.5',
                   def_2='10',
                   kind='Analogical',
                   shape=SquareShape())
    seq = BaseSequence()
    add_children(root, [pulse1, pulse2, pulse3, seq])
    add_children(seq, [pulse4])

    items = root.traverse()
    assert len(list(items)) == 11

    assert list(
        root.traverse(0)) == [root, pulse1, pulse2, pulse3, seq, context]
Example #8
0
def template_sequence(pulses_plugin):
    """Create a template sequence and make sure the plugin pick it up.

    """
    from ecpy_pulses.pulses.pulse import Pulse
    from ecpy_pulses.pulses.sequences.base_sequences import (RootSequence,
                                                             BaseSequence)
    from ecpy_pulses.pulses.shapes.square_shape import SquareShape
    from ecpy_pulses.pulses.contexts.template_context import TemplateContext

    root = RootSequence()
    context = TemplateContext(logical_channels=['A', 'B'],
                              analogical_channels=['Ch1', 'Ch2'],
                              channel_mapping={
                                  'A': '',
                                  'B': '',
                                  'Ch1': '',
                                  'Ch2': ''
                              })
    root.context = context
    root.local_vars = OrderedDict({'a': '1.5'})

    pulse1 = Pulse(channel='A', def_1='1.0', def_2='{a}')
    pulse2 = Pulse(channel='B', def_1='{a} + 1.0', def_2='3.0')
    pulse3 = Pulse(channel='Ch1',
                   def_1='{2_stop} + 0.5',
                   def_2='{b}',
                   kind='Analogical',
                   shape=SquareShape())
    seq = BaseSequence()
    seq.add_child_item(
        0,
        Pulse(channel='Ch2',
              def_1='{2_stop} + 0.5',
              def_2='{sequence_end}',
              kind='Analogical',
              shape=SquareShape()))
    for i in [pulse1, pulse2, seq, pulse3][::-1]:
        root.add_child_item(0, i)

    pref = root.preferences_from_members()
    pref['template_vars'] = repr(dict(b=''))
    del pref['item_id']
    del pref['external_vars']
    del pref['time_constrained']

    temp_path = os.path.join(pulses_plugin.templates_folders[0],
                             '__dummy__.temp_pulse.ini')
    save_sequence_prefs(temp_path, pref, 'dummy doc')

    pulses_plugin._refresh_known_template_sequences()

    return '__dummy__'
Example #9
0
def test_sequence_time_constaints_observation():
    """Test observation of time constraint by the root.

    """
    root = RootSequence()
    context = TestContext()
    root.context = context
    sequence = BaseSequence()
    root.add_child_item(0, sequence)

    assert root.global_vars == []

    sequence.time_constrained = True

    assert (sorted(root.global_vars) ==
            sorted(['1_start', '1_stop', '1_duration']))

    sequence.time_constrained = False

    assert root.global_vars == []

    root.time_constrained = True
    assert root.linkable_vars
def root_with_template(template_sequence, template_dependencies):
    """Build a root using the template sequence.

    """
    root = RootSequence()
    root.context = TestContext(sampling=0.5)

    conf = {
        'template_id': template_sequence,
        'name': 'Template',
        'template_vars': "{'b': '19'}"
    }
    seq = TemplateSequence.build_from_config(conf, template_dependencies)
    seq.context.channel_mapping = {
        'A': 'Ch1_L',
        'B': 'Ch2_L',
        'Ch1': 'Ch2_A',
        'Ch2': 'Ch1_A'
    }
    seq.def_1 = '1.0'
    seq.def_2 = '20.0'

    root.add_child_item(0, seq)
    return root
def test_collect_dependencies(workbench):
    """Test collecting build dependencies.

    """
    from ecpy_pulses.pulses.sequences.base_sequences import RootSequence
    root = RootSequence(context=TestContext())

    pulse1 = Pulse(def_1='1.0', def_2='{7_start} - 1.0')
    pulse2 = Pulse(def_1='{a} + 1.0', def_2='{6_start} + 1.0')
    pulse3 = Pulse(def_1='{3_stop} + 0.5', def_2='10.0')
    pulse4 = Pulse(def_1='2.0', def_2='0.5', def_mode='Start/Duration')
    pulse5 = Pulse(def_1='{1_stop}', def_2='0.5', def_mode='Start/Duration')
    pulse5.shape = SquareShape(amplitude='0.5')
    pulse5.kind = 'Analogical'

    pulse5.modulation.frequency = '1.0**'
    pulse5.modulation.phase = '1.0'
    pulse5.modulation.activated = True

    sequence2 = BaseSequence()
    sequence2.add_child_item(0, pulse3)
    sequence1 = BaseSequence()
    sequence1.add_child_item(0, pulse2)
    sequence1.add_child_item(1, sequence2)
    sequence1.add_child_item(2, pulse4)

    root.add_child_item(0, pulse1)
    root.add_child_item(1, sequence1)
    root.add_child_item(2, pulse5)

    core = workbench.get_plugin(u'enaml.workbench.core')
    com = 'ecpy.app.dependencies.analyse'
    dep = core.invoke_command(com, {'obj': root, 'dependencies': 'build'})
    assert not dep.errors

    com = 'ecpy.app.dependencies.collect'
    dep = core.invoke_command(com, {
        'kind': 'build',
        'dependencies': dep.dependencies
    })

    assert not dep.errors
    assert 'ecpy.pulses.item' in dep.dependencies
    assert 'ecpy.pulses.context' in dep.dependencies
    assert 'ecpy.pulses.shape' in dep.dependencies
    assert 'ecpy.pulses.modulation' in dep.dependencies
Example #12
0
def test_traverse_sequence():
    """Test traversing a pulse sequence.

    """
    root = RootSequence()
    context = TestContext()
    root.context = context
    root.external_vars = {'a': 1.5}

    pulse1 = Pulse(def_1='1.0', def_2='{a}')
    pulse2 = Pulse(def_1='{a} + 1.0', def_2='3.0')
    pulse3 = Pulse(def_1='{2_stop} + 0.5', def_2='10',
                   kind='Analogical', shape=SquareShape())
    pulse4 = Pulse(def_1='{2_stop} + 0.5', def_2='10',
                   kind='Analogical', shape=SquareShape())
    seq = BaseSequence()
    add_children(root, [pulse1, pulse2, pulse3, seq])
    add_children(seq, [pulse4])

    items = root.traverse()
    assert len(list(items)) == 11

    assert list(root.traverse(0)) == [root, pulse1, pulse2, pulse3, seq,
                                      context]
Example #13
0
def test_root_sequence_view(windows, workbench):
    """Test the root sequence view.

    """
    core = workbench.get_plugin('enaml.workbench.core')
    view = RootSequenceView(item=RootSequence(), core=core)

    show_widget(view)
    seq = BaseSequence()
    view.item.add_child_item(0, seq)
    assert seq in view._cache
    view.item.remove_child_item(0)
    assert seq not in view._cache

    but = view.widgets()[-1].pages()[1].page_widget().widgets()[0]
    with handle_dialog('reject'):
        but.clicked = True
def test_build_from_config2(template_sequence, template_dependencies):
    """ Test rebuilding a sequence including a template sequence.

    Channel mapping of template_vars values are known.

    """
    conf = {
        'template_id': 'test',
        'name': 'Template',
        'template_vars': "{'b': '25'}"
    }
    seq = TemplateSequence.build_from_config(conf, template_dependencies)
    seq.context.channel_mapping = {
        'A': 'Ch1_L',
        'B': 'Ch2_L',
        'Ch1': 'Ch2_A',
        'Ch2': 'Ch1_A'
    }
    root = RootSequence()
    context = TestContext(sampling=0.5)
    root.context = context
    root.add_child_item(0, seq)
    pref = root.preferences_from_members()

    new = RootSequence.build_from_config(pref, template_dependencies)
    assert new.items[0].index == 1

    seq = new.items[0]
    assert seq.name == 'Template'
    assert seq.template_id == template_sequence
    assert seq.template_vars == dict(b='25')
    assert seq.local_vars == dict(a='1.5')
    assert len(seq.items) == 4
    assert seq.items[3].index == 5
    assert seq.docs == 'Basic user comment\nff'

    context = seq.context
    assert context.template is seq
    assert context.logical_channels == ['A', 'B']
    assert context.analogical_channels == ['Ch1', 'Ch2']
    assert context.channel_mapping == {
        'A': 'Ch1_L',
        'B': 'Ch2_L',
        'Ch1': 'Ch2_A',
        'Ch2': 'Ch1_A'
    }
Example #15
0
def test_collect_dependencies(workbench):
    """Test collecting build dependencies.

    """
    from ecpy_pulses.pulses.sequences.base_sequences import RootSequence
    root = RootSequence(context=TestContext())

    pulse1 = Pulse(def_1='1.0', def_2='{7_start} - 1.0')
    pulse2 = Pulse(def_1='{a} + 1.0', def_2='{6_start} + 1.0')
    pulse3 = Pulse(def_1='{3_stop} + 0.5', def_2='10.0')
    pulse4 = Pulse(def_1='2.0', def_2='0.5', def_mode='Start/Duration')
    pulse5 = Pulse(def_1='{1_stop}', def_2='0.5',
                   def_mode='Start/Duration')
    pulse5.shape = SquareShape(amplitude='0.5')
    pulse5.kind = 'Analogical'

    pulse5.modulation.frequency = '1.0**'
    pulse5.modulation.phase = '1.0'
    pulse5.modulation.activated = True

    sequence2 = BaseSequence()
    sequence2.add_child_item(0, pulse3)
    sequence1 = BaseSequence()
    sequence1.add_child_item(0, pulse2)
    sequence1.add_child_item(1, sequence2)
    sequence1.add_child_item(2, pulse4)

    root.add_child_item(0, pulse1)
    root.add_child_item(1, sequence1)
    root.add_child_item(2, pulse5)

    core = workbench.get_plugin(u'enaml.workbench.core')
    com = 'ecpy.app.dependencies.analyse'
    dep = core.invoke_command(com, {'obj': root, 'dependencies': 'build'})
    assert not dep.errors

    com = 'ecpy.app.dependencies.collect'
    dep = core.invoke_command(com, {'kind': 'build',
                                    'dependencies': dep.dependencies})

    assert not dep.errors
    assert 'ecpy.pulses.items' in dep.dependencies
    assert 'ecpy.pulses.contexts' in dep.dependencies
    assert 'ecpy.pulses.shapes' in dep.dependencies
    assert 'ecpy.pulses.modulation' in dep.dependencies
Example #16
0
def sequence():
    """Create a sequence.

    """
    root = RootSequence()
    context = TestContext(sampling=0.5)
    root.context = context

    root.external_vars = OrderedDict({'a': None})
    root.local_vars = OrderedDict({'b': '2*{a}'})

    pulse1 = Pulse(def_1='1.0', def_2='{a}', def_mode=str('Start/Stop'))
    pulse2 = Pulse(def_1='{a} + 1.0', def_2='3.0')
    pulse3 = Pulse(def_1='{2_stop} + 0.5', def_2='10 + {b}')
    for i, c in enumerate((pulse1, pulse2, pulse3)):
        root.add_child_item(i, c)

    return root
def test_root_handling():
    """Test updating of item when a sequence get/lose the root.

    """
    root = RootSequence()
    context = TestContext()
    root.context = context
    sequence1 = BaseSequence()
    sequence2 = BaseSequence()
    pulse = Pulse()

    sequence2.add_child_item(0, pulse)
    sequence1.add_child_item(0, sequence2)
    root.add_child_item(0, sequence1)

    assert pulse.root is root and sequence2.root is root
    assert sequence2.has_observers('_last_index')

    root.remove_child_item(0)
    assert pulse.root is None and sequence2.root is None
    assert not sequence2.has_observers('_last_index')
def sequence():
    """Create a sequence.

    """
    root = RootSequence()
    context = TestContext(sampling=0.5)
    root.context = context

    root.external_vars = {"a": 1.5}
    root.local_vars = {"b": "2*{a}"}

    pulse1 = Pulse(def_1="1.0", def_2="{a}")
    pulse2 = Pulse(def_1="{a} + 1.0", def_2="3.0")
    pulse3 = Pulse(def_1="{2_stop} + 0.5", def_2="10 + {b}")
    for i, c in enumerate((pulse1, pulse2, pulse3)):
        root.add_child_item(i, c)

    return root
Example #19
0
def test_root_handling():
    """Test updating of item when a sequence get/lose the root.

    """
    root = RootSequence()
    context = TestContext()
    root.context = context
    sequence1 = BaseSequence()
    sequence2 = BaseSequence()
    pulse = Pulse()

    sequence2.add_child_item(0, pulse)
    sequence1.add_child_item(0, sequence2)
    root.add_child_item(0, sequence1)

    assert pulse.root is root and sequence2.root is root
    assert sequence2.has_observers('_last_index')

    root.remove_child_item(0)
    assert pulse.root is None and sequence2.root is None
    assert not sequence2.has_observers('_last_index')
Example #20
0
def template_sequence(pulses_plugin):
    """Create a template sequence and make sure the plugin pick it up.

    """
    from ecpy_pulses.pulses.pulse import Pulse
    from ecpy_pulses.pulses.sequences.base_sequences import RootSequence, BaseSequence
    from ecpy_pulses.pulses.shapes.square_shape import SquareShape
    from ecpy_pulses.pulses.contexts.template_context import TemplateContext

    root = RootSequence()
    context = TemplateContext(
        logical_channels=["A", "B"],
        analogical_channels=["Ch1", "Ch2"],
        channel_mapping={"A": "", "B": "", "Ch1": "", "Ch2": ""},
    )
    root.context = context
    root.local_vars = {"a": "1.5"}

    pulse1 = Pulse(channel="A", def_1="1.0", def_2="{a}")
    pulse2 = Pulse(channel="B", def_1="{a} + 1.0", def_2="3.0")
    pulse3 = Pulse(channel="Ch1", def_1="{2_stop} + 0.5", def_2="{b}", kind="Analogical", shape=SquareShape())
    seq = BaseSequence()
    seq.add_child_item(
        0, Pulse(channel="Ch2", def_1="{2_stop} + 0.5", def_2="{sequence_end}", kind="Analogical", shape=SquareShape())
    )
    for i in [pulse1, pulse2, seq, pulse3][::-1]:
        root.add_child_item(0, i)

    pref = root.preferences_from_members()
    pref["template_vars"] = repr(dict(b=""))
    del pref["item_id"]
    del pref["external_vars"]
    del pref["time_constrained"]

    temp_path = os.path.join(pulses_plugin.templates_folders[0], "__dummy__.temp_pulse.ini")
    save_sequence_prefs(temp_path, pref, "dummy doc")

    pulses_plugin._refresh_known_template_sequences()

    return "__dummy__"
def test_sequence_time_constaints_observation():
    """Test observation of time constraint by the root.

    """
    root = RootSequence()
    context = TestContext()
    root.context = context
    sequence = BaseSequence()
    root.add_child_item(0, sequence)

    assert root.global_vars == []

    sequence.time_constrained = True

    assert (sorted(root.global_vars) == sorted(
        ['1_start', '1_stop', '1_duration']))

    sequence.time_constrained = False

    assert root.global_vars == []

    root.time_constrained = True
    assert root.linkable_vars
def test_sequence_indexing1():
    """Test adding, moving, deleting pulse in a sequence.

    """
    root = RootSequence()
    root.time_constrained = True
    root.sequence_duration = '1.0'
    context = TestContext()
    root.context = context

    pulse1 = Pulse()
    pulse2 = Pulse()
    pulse3 = Pulse()

    root.add_child_item(0, pulse1)
    assert pulse1.index == 1
    assert pulse1.root is root
    assert (sorted(root.get_accessible_vars()) == (sorted(
        ['sequence_end', '1_start', '1_stop', '1_duration'])))

    root.add_child_item(1, pulse2)
    assert pulse1.index == 1
    assert pulse2.index == 2
    assert pulse2.root is root
    assert (sorted(root.get_accessible_vars()) == sorted([
        'sequence_end', '1_start', '1_stop', '1_duration', '2_start', '2_stop',
        '2_duration'
    ]))

    root.move_child_item(0, 1)
    assert pulse1.index == 2
    assert pulse2.index == 1
    assert (sorted(root.get_accessible_vars()) == sorted([
        'sequence_end', '1_start', '1_stop', '1_duration', '2_start', '2_stop',
        '2_duration'
    ]))

    root.move_child_item(0, 1)

    root.add_child_item(2, pulse3)
    assert pulse1.index == 1
    assert pulse2.index == 2
    assert pulse3.index == 3
    assert pulse3.root is root
    assert (sorted(root.get_accessible_vars()) == sorted([
        'sequence_end', '1_start', '1_stop', '1_duration', '2_start', '2_stop',
        '2_duration', '3_start', '3_stop', '3_duration'
    ]))

    root.time_constrained = False
    root.remove_child_item(1)
    assert pulse1.index == 1
    assert pulse2.index == 0
    assert pulse3.index == 2
    assert pulse2.root is None
    assert (sorted(root.get_accessible_vars()) == sorted(
        ['1_start', '1_stop', '1_duration', '2_start', '2_stop',
         '2_duration']))

    root.add_child_item(1, pulse2)
    assert pulse1.index == 1
    assert pulse2.index == 2
    assert pulse3.index == 3
    assert pulse2.root is root
    assert (sorted(root.get_accessible_vars()) == sorted([
        '1_start', '1_stop', '1_duration', '2_start', '2_stop', '2_duration',
        '3_start', '3_stop', '3_duration'
    ]))
def test_sequence_indexing2():
    """Test adding, moving, deleting a sequence in a sequence.

    """
    root = RootSequence()
    context = TestContext()
    root.context = context

    pulse1 = Pulse()
    pulse2 = Pulse()
    pulse3 = Pulse()
    pulse4 = Pulse()

    sequence1 = BaseSequence()
    sequence2 = BaseSequence()

    root.add_child_item(0, pulse1)
    root.add_child_item(1, sequence1)
    root.add_child_item(2, pulse2)

    assert sequence1.parent is root
    assert sequence1.root is root

    sequence1.add_child_item(0, sequence2)

    assert sequence2.parent is sequence1
    assert sequence2.root is root
    assert pulse1.index == 1
    assert pulse2.index == 4
    assert (sorted(root.get_accessible_vars()) == sorted(
        ['1_start', '1_stop', '1_duration', '4_start', '4_stop',
         '4_duration']))

    pulse1.index = 200
    sequence2.add_child_item(0, pulse3)

    assert pulse3.parent is sequence2
    assert pulse3.root is root
    assert pulse2.index == 5
    assert pulse3.index == 4
    assert (sorted(root.get_accessible_vars()) == sorted([
        '1_start', '1_stop', '1_duration', '4_start', '4_stop', '4_duration',
        '5_start', '5_stop', '5_duration'
    ]))

    # Check that only the pulse below the modified sequence are updated.
    assert pulse1.index == 200
    pulse1.index = 0

    sequence1.add_child_item(0, pulse4)

    assert pulse4.index == 3
    assert sequence2.index == 4
    assert pulse3.index == 5
    assert pulse2.index == 6
    assert (sorted(root.get_accessible_vars()) == sorted([
        '1_start', '1_stop', '1_duration', '3_start', '3_stop', '3_duration',
        '5_start', '5_stop', '5_duration', '6_start', '6_stop', '6_duration'
    ]))

    sequence1.remove_child_item(1)

    assert sequence2.parent is None
    assert sequence2.index == 0
    assert pulse2.index == 4
    assert (sorted(root.get_accessible_vars()) == sorted([
        '1_start', '1_stop', '1_duration', '3_start', '3_stop', '3_duration',
        '4_start', '4_stop', '4_duration'
    ]))

    sequence1.index = 200
    root2 = RootSequence()
    sequence2.root = root2
    while True:
        sequence2.remove_child_item(0)
        if not sequence2.items:
            break

    # Check the observer was properly removed
    assert sequence1.index == 200
Example #24
0
def test_sequence_indexing2():
    """Test adding, moving, deleting a sequence in a sequence.

    """
    root = RootSequence()
    context = TestContext()
    root.context = context

    pulse1 = Pulse()
    pulse2 = Pulse()
    pulse3 = Pulse()
    pulse4 = Pulse()

    sequence1 = BaseSequence()
    sequence2 = BaseSequence()

    root.add_child_item(0, pulse1)
    root.add_child_item(1, sequence1)
    root.add_child_item(2, pulse2)

    assert sequence1.parent is root
    assert sequence1.root is root

    sequence1.add_child_item(0, sequence2)

    assert sequence2.parent is sequence1
    assert sequence2.root is root
    assert pulse1.index == 1
    assert pulse2.index == 4
    assert (sorted(root.get_accessible_vars()) ==
            sorted(['1_start', '1_stop', '1_duration',
                    '4_start', '4_stop', '4_duration']))

    pulse1.index = 200
    sequence2.add_child_item(0, pulse3)

    assert pulse3.parent is sequence2
    assert pulse3.root is root
    assert pulse2.index == 5
    assert pulse3.index == 4
    assert (sorted(root.get_accessible_vars()) ==
            sorted(['1_start', '1_stop', '1_duration',
                    '4_start', '4_stop', '4_duration',
                    '5_start', '5_stop', '5_duration']))

    # Check that only the pulse below the modified sequence are updated.
    assert pulse1.index == 200
    pulse1.index = 0

    sequence1.add_child_item(0, pulse4)

    assert pulse4.index == 3
    assert sequence2.index == 4
    assert pulse3.index == 5
    assert pulse2.index == 6
    assert (sorted(root.get_accessible_vars()) ==
            sorted(['1_start', '1_stop', '1_duration',
                    '3_start', '3_stop', '3_duration',
                    '5_start', '5_stop', '5_duration',
                    '6_start', '6_stop', '6_duration']))

    sequence1.remove_child_item(1)

    assert sequence2.parent is None
    assert sequence2.index == 0
    assert pulse2.index == 4
    assert (sorted(root.get_accessible_vars()) ==
            sorted(['1_start', '1_stop', '1_duration',
                    '3_start', '3_stop', '3_duration',
                    '4_start', '4_stop', '4_duration']))

    sequence1.index = 200
    root2 = RootSequence()
    sequence2.root = root2
    while True:
        sequence2.remove_child_item(0)
        if not sequence2.items:
            break

    # Check the observer was properly removed
    assert sequence1.index == 200
Example #25
0
def test_sequence_indexing1():
    """Test adding, moving, deleting pulse in a sequence.

    """
    root = RootSequence()
    root.time_constrained = True
    root.sequence_duration = '1.0'
    context = TestContext()
    root.context = context

    pulse1 = Pulse()
    pulse2 = Pulse()
    pulse3 = Pulse()

    root.add_child_item(0, pulse1)
    assert pulse1.index == 1
    assert pulse1.root is root
    assert (sorted(root.get_accessible_vars()) ==
            (sorted(['sequence_end', '1_start', '1_stop', '1_duration'])))

    root.add_child_item(1, pulse2)
    assert pulse1.index == 1
    assert pulse2.index == 2
    assert pulse2.root is root
    assert (sorted(root.get_accessible_vars()) ==
            sorted(['sequence_end', '1_start', '1_stop', '1_duration',
                    '2_start', '2_stop', '2_duration']))

    root.move_child_item(0, 1)
    assert pulse1.index == 2
    assert pulse2.index == 1
    assert (sorted(root.get_accessible_vars()) ==
            sorted(['sequence_end', '1_start', '1_stop', '1_duration',
                    '2_start', '2_stop', '2_duration']))

    root.move_child_item(0, 1)

    root.add_child_item(2, pulse3)
    assert pulse1.index == 1
    assert pulse2.index == 2
    assert pulse3.index == 3
    assert pulse3.root is root
    assert (sorted(root.get_accessible_vars()) ==
            sorted(['sequence_end', '1_start', '1_stop', '1_duration',
                    '2_start', '2_stop', '2_duration',
                    '3_start', '3_stop', '3_duration']))

    root.time_constrained = False
    root.remove_child_item(1)
    assert pulse1.index == 1
    assert pulse2.index == 0
    assert pulse3.index == 2
    assert pulse2.root is None
    assert (sorted(root.get_accessible_vars()) ==
            sorted(['1_start', '1_stop', '1_duration',
                    '2_start', '2_stop', '2_duration']))

    root.add_child_item(1, pulse2)
    assert pulse1.index == 1
    assert pulse2.index == 2
    assert pulse3.index == 3
    assert pulse2.root is root
    assert (sorted(root.get_accessible_vars()) ==
            sorted(['1_start', '1_stop', '1_duration',
                    '2_start', '2_stop', '2_duration',
                    '3_start', '3_stop', '3_duration']))
Example #26
0
def item():
    return Item(root=RootSequence(context=TestContext()))
def test_build_from_config():
    """Test building a pulse sequence.

    """
    root = RootSequence()
    context = TestContext()
    root.context = context
    root.external_vars = OrderedDict({'a': 1.5})

    pulse1 = Pulse(def_1='1.0', def_2='{a}')
    pulse2 = Pulse(def_1='{a} + 1.0', def_2='3.0')
    pulse3 = Pulse(def_1='{2_stop} + 0.5',
                   def_2='10',
                   kind='Analogical',
                   shape=SquareShape())
    pulse4 = Pulse(def_1='{2_stop} + 0.5',
                   def_2='10',
                   kind='Analogical',
                   shape=SquareShape())
    seq = BaseSequence()
    add_children(root, [pulse1, pulse2, pulse3, seq])
    add_children(seq, [pulse4])

    pref = root.preferences_from_members()
    dependecies = {
        'ecpy.pulses.item': {
            'ecpy_pulses.BaseSequence': BaseSequence,
            'ecpy_pulses.Pulse': Pulse
        },
        'ecpy.pulses.shape': {
            'ecpy_pulses.SquareShape': SquareShape
        },
        'ecpy.pulses.context': {
            'ecpy_pulses.TestContext': TestContext
        }
    }

    aux = RootSequence.build_from_config(pref, dependecies)
    assert aux.external_vars == {'a': 1.5}
    assert len(aux.items) == 4
    assert isinstance(aux.context, TestContext)

    pulse1 = aux.items[0]
    assert pulse1.parent
    assert pulse1.def_1 == '1.0'
    assert pulse1.def_2 == '{a}'

    pulse2 = aux.items[1]
    assert pulse2.parent
    assert pulse2.def_1 == '{a} + 1.0'
    assert pulse2.def_2 == '3.0'

    pulse3 = aux.items[2]
    assert pulse3.parent
    assert pulse3.def_1 == '{2_stop} + 0.5'
    assert pulse3.def_2 == '10'
    assert pulse3.kind == 'Analogical'
    assert isinstance(pulse3.shape, SquareShape)

    seq = aux.items[3]
    assert seq.parent
    assert len(seq.items) == 1
Example #28
0
def root():
    root = RootSequence()
    context = TestContext(sampling=0.5)
    root.context = context
    return root
def root():
    root = RootSequence()
    context = TestContext(sampling=0.5)
    root.context = context
    return root
Example #30
0
def pulse():
    return Pulse(root=RootSequence(context=TestContext()))
Example #31
0
def root():
    root = RootSequence(context=TestContext())
    return root