Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added components to ProcedureStep and Procedure #132

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions topside/procedures/procedure.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class ProcedureStep:

operator: str
The person who performs the step

"""
step_id: str
action: Action
Expand Down Expand Up @@ -143,18 +144,28 @@ 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:
raise ValueError(
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 step.action:
self.components.add(step.action[0])
jlsajfj marked this conversation as resolved.
Show resolved Hide resolved

def index_of(self, step_id):
"""
Expand Down Expand Up @@ -226,9 +237,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
Expand All @@ -239,6 +259,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 '
Expand Down
12 changes: 12 additions & 0 deletions topside/procedures/tests/test_procedure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}