Esempio n. 1
0
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
Esempio n. 2
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
Esempio n. 3
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'
    ]))