Esempio n. 1
0
def test_parse_steps_with_complex_comparisons():
    proclang = '''
    main:
        1. PRIMARY: set injector_valve to open
        2. PRIMARY: [p1 < 100 and p2 > 200] set vent_valve to closed
        3. SECONDARY: [p1 > 100 or  p2 < 200] set vent_valve to open
        4. SECONDARY: [(p1 <= 100)] set vent_valve to closed
        5. OPS: [p1 < 100 or p2 > 200 and p3 < 100] set vent_valve to open
        6. OPS: [p1 < 100 and p2 > 200 or p3 < 100] set vent_valve to open
        7. OPS: [(p1 < 100 or p2 > 200) and p3 < 100] set vent_valve to closed
    '''
    suite = top.proclang.parse(proclang)

    comp_and = top.And([top.Less('p1', 100), top.Greater('p2', 200)])
    comp_or = top.Or([top.Greater('p1', 100), top.Less('p2', 200)])
    comp_and_or_1 = top.Or([
        top.Less('p1', 100),
        top.And([top.Greater('p2', 200),
                 top.Less('p3', 100)])
    ])
    comp_and_or_2 = top.Or([
        top.And([top.Less('p1', 100),
                 top.Greater('p2', 200)]),
        top.Less('p3', 100)
    ])
    comp_and_or_3 = top.And([
        top.Or([top.Less('p1', 100),
                top.Greater('p2', 200)]),
        top.Less('p3', 100)
    ])

    expected_suite = top.ProcedureSuite([
        top.Procedure('main', [
            top.ProcedureStep(
                '1', top.StateChangeAction('injector_valve', 'open'),
                [(comp_and, top.Transition('main', '2'))], 'PRIMARY'),
            top.ProcedureStep(
                '2', top.StateChangeAction('vent_valve', 'closed'),
                [(comp_or, top.Transition('main', '3'))], 'PRIMARY'),
            top.ProcedureStep('3', top.StateChangeAction(
                'vent_valve', 'open'), [(top.LessEqual(
                    'p1', 100), top.Transition('main', '4'))], 'SECONDARY'),
            top.ProcedureStep(
                '4', top.StateChangeAction('vent_valve', 'closed'),
                [(comp_and_or_1, top.Transition('main', '5'))], 'SECONDARY'),
            top.ProcedureStep('5', top.StateChangeAction('vent_valve', 'open'),
                              [(comp_and_or_2, top.Transition('main', '6'))],
                              'OPS'),
            top.ProcedureStep('6', top.StateChangeAction('vent_valve', 'open'),
                              [(comp_and_or_3, top.Transition('main', '7'))],
                              'OPS'),
            top.ProcedureStep('7', top.StateChangeAction(
                'vent_valve', 'closed'), [], 'OPS')
        ])
    ])

    assert suite == expected_suite
def test_greater_condition_less():
    cond = top.Greater('A1', 100)
    state = {'pressures': {'A1': 99}}

    assert cond.satisfied() is False
    cond.update(state)
    assert cond.satisfied() is False
Esempio n. 3
0
def test_parse_from_file():
    filepath = os.path.join(os.path.dirname(__file__), 'example.proc')
    suite = top.proclang.parse_from_file(filepath)

    expected_suite = top.ProcedureSuite([
        top.Procedure('main', [
            top.ProcedureStep(
                '1', top.StateChangeAction('series_fill_valve', 'closed'),
                [(top.WaitFor(5e6), top.Transition('main', '2'))], 'PRIMARY'),
            top.ProcedureStep(
                '2', top.StateChangeAction('supply_valve', 'open'),
                [(top.Less('p1', 600), top.Transition('abort_1', '1')),
                 (top.Greater('p1', 1000), top.Transition('abort_2', '1')),
                 (top.Immediate(), top.Transition('main', '3'))], 'PRIMARY'),
            top.ProcedureStep(
                '3', top.StateChangeAction('series_fill_valve', 'open'),
                [(top.Immediate(), top.Transition('main', '4'))], 'PRIMARY'),
            top.ProcedureStep(
                '4', top.StateChangeAction('remote_fill_valve', 'open'), [
                    (top.WaitFor(180e6), top.Transition('main', '5'))
                ], 'PRIMARY'),
            top.ProcedureStep(
                '5', top.StateChangeAction('remote_fill_valve', 'closed'),
                [(top.Immediate(), top.Transition('main', '6'))], 'PRIMARY'),
            top.ProcedureStep(
                '6', top.StateChangeAction('remote_vent_valve', 'open'),
                [(top.Immediate(), top.Transition('main', '7'))], 'PRIMARY'),
            top.ProcedureStep('7', top.MiscAction('Proceed with teardown'), [],
                              'OPS')
        ]),
        top.Procedure('abort_1', [
            top.ProcedureStep(
                '1', top.StateChangeAction('supply_valve', 'closed'), [
                    (top.WaitFor(10e6), top.Transition('abort_1', '2'))
                ], 'SECONDARY'),
            top.ProcedureStep(
                '2', top.StateChangeAction('remote_vent_valve', 'open'), [
                    (top.Immediate(), top.Transition('abort_1', '3'))
                ], 'SECONDARY'),
            top.ProcedureStep('3', top.MiscAction('Proceed with teardown'), [],
                              'OPS')
        ]),
        top.Procedure('abort_2', [
            top.ProcedureStep(
                '1', top.StateChangeAction('supply_valve', 'closed'), [
                    (top.Immediate(), top.Transition('abort_2', '2'))
                ], 'CONTROL'),
            top.ProcedureStep(
                '2', top.StateChangeAction('line_vent_valve', 'open'), [
                    (top.Immediate(), top.Transition('abort_2', '3'))
                ], 'CONTROL'),
            top.ProcedureStep('3', top.MiscAction('Proceed with teardown'), [],
                              'OPS')
        ]),
    ])

    assert suite == expected_suite
def test_comparison_equality():
    c1 = top.Less('a1', 100)
    c2 = top.Less('a1', 100)  # same
    c3 = top.Less('b2', 100)  # different node
    c4 = top.Less('a1', 200)  # different reference
    c5 = top.Greater('a1', 100)  # different type

    assert c1 == c2
    assert c1 != c3
    assert c1 != c4
    assert c1 != c5
def test_string_representations():
    immediate_cond = top.Immediate()
    waitFor_cond = top.WaitFor(1000000)
    equal_cond = top.Equal('A1', 100)
    less_cond = top.Less('A2', 100)
    greater_cond = top.Greater('A3', 100)
    lessEqual_cond = top.LessEqual('A4', 100)
    greaterEqual_cond = top.GreaterEqual('A5', 100)
    and_cond = top.And([less_cond, greater_cond])
    or_cond = top.Or([lessEqual_cond, greaterEqual_cond])

    assert str(immediate_cond) == 'Immediately'
    assert str(waitFor_cond) == 'Wait for 1 seconds'
    assert str(equal_cond) == 'A1 == 100'
    assert str(less_cond) == 'A2 < 100'
    assert str(greater_cond) == 'A3 > 100'
    assert str(lessEqual_cond) == 'A4 <= 100'
    assert str(greaterEqual_cond) == 'A5 >= 100'
    assert str(and_cond) == '(A2 < 100 and A3 > 100)'
    assert str(or_cond) == '(A4 <= 100 or A5 >= 100)'
Esempio n. 6
0
def test_parse_steps_with_comparisons():
    proclang = '''
    main:
        1. PRIMARY: set injector_valve to open
        2. PRIMARY: [p1 < 100] set vent_valve to closed
        3. PRIMARY: [p1 > 100] set vent_valve to open
        4. PRIMARY: [p1 <= 100] set vent_valve to closed
        5. SECONDARY: [p1 >= 100] set vent_valve to open
        6. SECONDARY: [p1 == 100] set vent_valve to closed
    '''
    suite = top.proclang.parse(proclang)

    expected_suite = top.ProcedureSuite([
        top.Procedure('main', [
            top.ProcedureStep(
                '1', top.StateChangeAction('injector_valve', 'open'), [
                    (top.Less('p1', 100), top.Transition('main', '2'))
                ], 'PRIMARY'),
            top.ProcedureStep('2', top.StateChangeAction(
                'vent_valve', 'closed'), [(top.Greater(
                    'p1', 100), top.Transition('main', '3'))], 'PRIMARY'),
            top.ProcedureStep('3', top.StateChangeAction(
                'vent_valve', 'open'), [(top.LessEqual(
                    'p1', 100), top.Transition('main', '4'))], 'PRIMARY'),
            top.ProcedureStep('4', top.StateChangeAction(
                'vent_valve', 'closed'), [(top.GreaterEqual(
                    'p1', 100), top.Transition('main', '5'))], 'PRIMARY'),
            top.ProcedureStep('5', top.StateChangeAction(
                'vent_valve', 'open'), [(top.Equal(
                    'p1', 100), top.Transition('main', '6'))], 'SECONDARY'),
            top.ProcedureStep('6', top.StateChangeAction(
                'vent_valve', 'closed'), [], 'SECONDARY')
        ])
    ])

    assert suite == expected_suite