Skip to content
Snippets Groups Projects
Commit f8cd3d82 authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Make the workflow iterable

parent bbfca558
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,13 @@ class TestWorkflowCreation(SimpleTestCase): ...@@ -16,6 +16,13 @@ class TestWorkflowCreation(SimpleTestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
Workflow(name) Workflow(name)
def test_can_iterate_through_workflow(self):
stage1 = Stage('stage_one')
stage2 = Stage('stage_two')
workflow = Workflow('two_stage', stage1, stage2)
for stage, check in zip(workflow, [stage1, stage2]):
self.assertEqual(stage, check)
class TestStageCreation(SimpleTestCase): class TestStageCreation(SimpleTestCase):
def test_can_create_stage(self): def test_can_create_stage(self):
......
class Workflow: from typing import Iterator, Iterable
def __init__(self, name: str, *stages: Stage) -> None:
class Workflow(Iterable['Stage']):
def __init__(self, name: str, *stages: 'Stage') -> None:
self.name = name self.name = name
if not stages: if not stages:
raise ValueError('Stages must be supplied') raise ValueError('Stages must be supplied')
self.stages = stages self.stages = stages
def __iter__(self) -> Iterator['Stage']:
yield from self.stages
class Stage: class Stage:
def __init__(self, name: str) -> None: def __init__(self, name: str) -> None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment