def test_waitfor_latex_export(): suite = top.ProcedureSuite([ top.Procedure('main', [ top.ProcedureStep( '1', top.StateChangeAction('injector_valve', 'open'), [(top.And([ top.WaitFor(10e6), top.Or( [top.Less('p1', 400.0), top.GreaterEqual('p2', 17.0)]) ]), top.Transition('main', '2'))], 'PRIMARY'), top.ProcedureStep('2', top.StateChangeAction( 'vent_valve', 'closed'), [], 'PRIMARY') ]) ]) export = suite.export(top.ExportFormat.Latex) expected_export = textwrap.dedent(r''' \subsection{main} \begin{checklist} \item \PRIMARY{} Open injector\_valve \item Wait 10 seconds and p1 is less than 400psi or p2 is greater than or equal to 17psi \item \PRIMARY{} Close vent\_valve \end{checklist}''') assert export == expected_export
def test_greater_equal_condition_less(): cond = top.GreaterEqual('A1', 100) state = {'pressures': {'A1': 99}} assert cond.satisfied() is False cond.update(state) assert cond.satisfied() is False
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)'
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