Beispiel #1
0
def test_proceed_follows_highest_priority_condition():
    plumb_eng = one_component_engine()
    proc_eng = top.ProceduresEngine(plumb_eng,
                                    branching_procedure_suite_two_options())

    proc_eng.execute_current()
    proc_eng.proceed()

    assert proc_eng.current_procedure_id == 'p1'
    assert proc_eng.current_step.step_id == 's2'
Beispiel #2
0
def test_proceed_requires_satisfaction():
    plumb_eng = one_component_engine()
    proc_eng = top.ProceduresEngine(plumb_eng,
                                    branching_procedure_suite_no_options())

    proc_eng.execute_current()
    proc_eng.proceed()

    assert proc_eng.current_procedure_id == 'p1'
    assert proc_eng.current_step.step_id == 's1'
Beispiel #3
0
def test_proceed_follows_satisfied_condition():
    plumb_eng = one_component_engine()
    proc_eng = top.ProceduresEngine(plumb_eng,
                                    branching_procedure_suite_one_option())

    proc_eng.execute_current()
    proc_eng.proceed()

    assert proc_eng.current_procedure_id == 'p2'
    assert proc_eng.current_step.step_id == 's3'
Beispiel #4
0
def test_execute_custom_action():
    plumb_eng = one_component_engine()
    proc_eng = top.ProceduresEngine(plumb_eng)

    action = top.StateChangeAction('c1', 'closed')

    assert plumb_eng.current_state('c1') == 'open'
    proc_eng.execute(action)
    assert plumb_eng.current_state('c1') == 'closed'

    misc_action = top.MiscAction('Approach the tower')
    proc_eng.execute(misc_action)
    assert plumb_eng.current_state('c1') == 'closed'
Beispiel #5
0
def test_step_advances_time_equally():
    managed_eng = one_component_engine()
    managed_eng.set_component_state('c1', 'open')

    unmanaged_eng = copy.deepcopy(managed_eng)

    proc_eng = top.ProceduresEngine(managed_eng, single_procedure_suite())

    assert managed_eng.current_pressures() == unmanaged_eng.current_pressures()

    proc_eng.step_time(1e6)
    unmanaged_eng.step(1e6)

    assert managed_eng.current_pressures() == unmanaged_eng.current_pressures()
Beispiel #6
0
def test_next_step():
    plumb_eng = one_component_engine()
    proc_eng = top.ProceduresEngine(plumb_eng, single_procedure_suite())

    assert proc_eng.current_step.step_id == 's1'
    assert plumb_eng.current_state('c1') == 'open'
    proc_eng.next_step()
    assert proc_eng.current_step.step_id == 's1'
    assert plumb_eng.current_state('c1') == 'closed'
    proc_eng.next_step()
    assert proc_eng.current_step.step_id == 's2'
    assert plumb_eng.current_state('c1') == 'open'
    proc_eng.next_step()
    assert proc_eng.current_step.step_id == 's2'
    assert plumb_eng.current_state('c1') == 'open'
Beispiel #7
0
def test_step_updates_conditions():
    plumb_eng = one_component_engine()
    plumb_eng.set_component_state('c1', 'open')

    s1 = top.ProcedureStep('s1', None, [(top.Less(1, 75), 's2')], 'PRIMARY')
    proc = top.Procedure('p1', [s1])
    proc_suite = top.ProcedureSuite([proc], 'p1')

    proc_eng = top.ProceduresEngine(plumb_eng, proc_suite)
    proc_eng.execute_current()

    assert proc_eng.ready_to_proceed() is False

    proc_eng.step_time(1e6)

    assert proc_eng.ready_to_proceed() is True
Beispiel #8
0
def test_execute_current():
    plumb_eng = one_component_engine()
    proc_eng = top.ProceduresEngine(plumb_eng, single_procedure_suite())

    assert proc_eng.current_step.step_id == 's1'
    assert proc_eng.step_position == top.StepPosition.Before
    assert plumb_eng.current_state('c1') == 'open'

    proc_eng.execute_current()

    assert proc_eng.current_step.step_id == 's1'
    assert proc_eng.step_position == top.StepPosition.After
    assert plumb_eng.current_state('c1') == 'closed'

    proc_eng.execute_current()  # No effect; engine is in a post-node

    assert proc_eng.current_step.step_id == 's1'
    assert proc_eng.step_position == top.StepPosition.After
    assert plumb_eng.current_state('c1') == 'closed'
Beispiel #9
0
def test_reset():
    plumb_eng = one_component_engine()
    proc_eng = top.ProceduresEngine(plumb_eng,
                                    branching_procedure_suite_one_option())

    assert proc_eng.current_procedure_id == 'p1'
    assert proc_eng.current_step.step_id == 's1'
    assert plumb_eng.current_state('c1') == 'open'
    proc_eng.next_step()
    assert proc_eng.current_procedure_id == 'p1'
    assert proc_eng.current_step.step_id == 's1'
    assert plumb_eng.current_state('c1') == 'closed'
    proc_eng.next_step()
    assert proc_eng.current_procedure_id == 'p2'
    assert proc_eng.current_step.step_id == 's3'
    assert plumb_eng.current_state('c1') == 'open'
    proc_eng.reset()
    assert proc_eng.current_procedure_id == 'p1'
    assert proc_eng.current_step.step_id == 's1'
    assert plumb_eng.current_state('c1') == 'open'
Beispiel #10
0
def test_transitions_respects_procedure_identifier():
    plumb_eng = one_component_engine()

    action = top.MiscAction('Do nothing')

    s1 = top.ProcedureStep(
        's1', action, [(NeverSatisfied(), top.Transition('p1', 'same_name')),
                       (top.Immediate(), top.Transition('p2', 'same_name'))],
        'PRIMARY')
    same_name_1 = top.ProcedureStep('same_name', action, [], 'PRIMARY')
    same_name_2 = top.ProcedureStep('same_name', action, [], 'PRIMARY')

    proc_1 = top.Procedure('p1', [s1, same_name_1])
    proc_2 = top.Procedure('p2', [same_name_2])
    proc_suite = top.ProcedureSuite([proc_1, proc_2], 'p1')

    proc_eng = top.ProceduresEngine(plumb_eng, proc_suite)
    proc_eng.execute_current()

    assert proc_eng.current_procedure_id == 'p1'
    assert proc_eng.current_step.step_id == 's1'
    proc_eng.next_step()
    assert proc_eng.current_procedure_id == 'p2'
    assert proc_eng.current_step.step_id == 'same_name'
Beispiel #11
0
def test_load_suite():
    p1s1 = top.ProcedureStep('p1s1',
                             top.StateChangeAction('injector_valve', 'open'),
                             [], 'PRIMARY')
    suite_1 = top.ProcedureSuite([top.Procedure('p1', [p1s1])], 'p1')

    p2s1 = top.ProcedureStep('p2s1',
                             top.StateChangeAction('injector_valve', 'closed'),
                             [], 'SECONDARY')
    suite_2 = top.ProcedureSuite([top.Procedure('p2', [p2s1])], 'p2')

    proc_eng = top.ProceduresEngine(None, suite_1)

    assert proc_eng._suite == suite_1
    assert proc_eng.current_procedure_id == 'p1'
    assert proc_eng.current_step == p1s1
    assert proc_eng.step_position == top.StepPosition.Before

    proc_eng.load_suite(suite_2)

    assert proc_eng._suite == suite_2
    assert proc_eng.current_procedure_id == 'p2'
    assert proc_eng.current_step == p2s1
    assert proc_eng.step_position == top.StepPosition.Before
Beispiel #12
0
def test_ready_to_proceed_no_options():
    proc_eng = top.ProceduresEngine(None,
                                    branching_procedure_suite_no_options())
    proc_eng.execute_current()

    assert proc_eng.ready_to_proceed() is False
Beispiel #13
0
def test_ready_to_proceed_one_is_enough():
    proc_eng = top.ProceduresEngine(None,
                                    branching_procedure_suite_one_option())
    proc_eng.execute_current()

    assert proc_eng.ready_to_proceed() is True
Beispiel #14
0
def test_ready_to_proceed_if_condition_satisfied():
    proc_eng = top.ProceduresEngine(None, single_procedure_suite())
    proc_eng.execute_current()

    assert proc_eng.ready_to_proceed() is True
Beispiel #15
0
def test_ready_to_proceed_requires_post():
    proc_eng = top.ProceduresEngine(None, single_procedure_suite())

    assert proc_eng.ready_to_proceed() is False