diff --git a/topside/procedures/procedure.py b/topside/procedures/procedure.py index 922b1a4..a21adb6 100644 --- a/topside/procedures/procedure.py +++ b/topside/procedures/procedure.py @@ -35,6 +35,9 @@ class StateChangeAction(Action): component: str state: str + def get_action_type(self): + return self.component + def export(self, fmt): if fmt == top.ExportFormat.Latex: if self.state == 'open': @@ -59,6 +62,9 @@ class MiscAction(Action): """ action_type: str + def get_action_type(self): + return self.action_type + def export(self, fmt): if fmt == top.ExportFormat.Latex: return self.action_type @@ -109,6 +115,7 @@ class ProcedureStep: operator: str The person who performs the step + """ step_id: str action: Action @@ -143,11 +150,19 @@ def __init__(self, procedure_id, steps): steps: iterable An iterable of ProcedureStep objects ordered from first step to last step. + + Members + ------- + + components: set + An unordered collection of components used from each of the + steps from before. Added to set if the action contains a component """ self.procedure_id = procedure_id self.steps = {} self.step_list = list(steps) self.step_id_to_idx = {} + self.components = set() for i, step in enumerate(steps): if step.step_id in self.steps: @@ -155,6 +170,10 @@ def __init__(self, procedure_id, steps): f'duplicate step ID {step.step_id} encountered in Procedure initialization') self.steps[step.step_id] = step self.step_id_to_idx[step.step_id] = i + if type(step.action) is tuple: + self.components.add(step.action[0]) + elif step.action: + self.components.add(step.action.get_action_type()) def index_of(self, step_id): """ @@ -226,9 +245,18 @@ def __init__(self, procedures, starting_procedure_id='main'): The procedure ID for the starting procedure used when this procedure suite is executed. Defaults to "main" if not specified. + + Members + ------- + + components: set + An unordered collection of components used from each of the + Procedures passed into it. Components are received from the property + within ProcedureStep """ self.starting_procedure_id = starting_procedure_id self.procedures = {} + self.components = set() # TODO(jacob): Allow invalid procedure suites to be created, but # keep track of the invalid reasons (same way plumbing code @@ -239,6 +267,7 @@ def __init__(self, procedures, starting_procedure_id='main'): raise ValueError(f'duplicate procedure ID {proc.procedure_id} encountered in ' + 'ProcedureSuite initialization') self.procedures[proc.procedure_id] = proc + self.components.update(proc.components) if self.starting_procedure_id not in self.procedures: raise ValueError(f'starting procedure ID {self.starting_procedure_id} not found in ' diff --git a/topside/procedures/tests/test_procedure.py b/topside/procedures/tests/test_procedure.py index 39f2a50..5f54068 100644 --- a/topside/procedures/tests/test_procedure.py +++ b/topside/procedures/tests/test_procedure.py @@ -244,3 +244,15 @@ def test_action_types(): assert isinstance(a1, top.Action) assert isinstance(a2, top.Action) + + +def test_components(): + s1 = top.ProcedureStep('s1', ('p1', 'open'), [], 'PRIMARY') + s2 = top.ProcedureStep('s2', ('p2', 'open'), [], 'PRIMARY') + s3 = top.ProcedureStep('s3', ('p3', 'open'), [], 'PRIMARY') + + proc_1 = top.Procedure('p1', [s1, s2, s3]) + + components_1 = proc_1.components + + assert components_1 == {'p1', 'p2', 'p3'}