Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hypha
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ots
hypha
Commits
c7e5201b
Commit
c7e5201b
authored
7 years ago
by
Todd Dembrey
Browse files
Options
Downloads
Patches
Plain Diff
Allow the action to be callable
parent
84bb498e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
opentech/apply/tests/test_workflow.py
+17
-1
17 additions, 1 deletion
opentech/apply/tests/test_workflow.py
opentech/apply/workflow.py
+20
-4
20 additions, 4 deletions
opentech/apply/workflow.py
with
37 additions
and
5 deletions
opentech/apply/tests/test_workflow.py
+
17
−
1
View file @
c7e5201b
...
...
@@ -18,6 +18,11 @@ class TestWorkflowCreation(SimpleTestCase):
workflow
=
WorkflowFactory
(
num_stages
=
1
,
stages__num_phases
=
1
)
self
.
assertEqual
(
workflow
.
next
(),
workflow
.
stages
[
0
].
phases
[
0
])
def
test_can_get_the_current_phase
(
self
):
workflow
=
WorkflowFactory
(
num_stages
=
1
,
stages__num_phases
=
2
)
phase
=
workflow
.
stages
[
0
].
phases
[
0
]
self
.
assertEqual
(
workflow
.
current
(
str
(
phase
)),
phase
)
def
test_returns_none_if_no_next
(
self
):
workflow
=
WorkflowFactory
(
num_stages
=
1
,
stages__num_phases
=
1
)
self
.
assertEqual
(
workflow
.
next
(
workflow
.
stages
[
0
].
phases
[
0
]),
None
)
...
...
@@ -53,7 +58,13 @@ class TestPhaseCreation(SimpleTestCase):
name
=
'
the_phase
'
phase
=
Phase
(
name
,
actions
)
self
.
assertEqual
(
phase
.
name
,
name
)
self
.
assertEqual
(
phase
.
actions
,
actions
)
self
.
assertEqual
(
phase
.
actions
,
{
action
.
name
:
action
for
action
in
actions
})
def
test_can_get_action_from_phase
(
self
):
actions
=
ActionFactory
.
create_batch
(
3
)
action
=
actions
[
1
]
phase
=
PhaseFactory
(
actions
=
actions
)
self
.
assertEqual
(
phase
[
action
.
name
],
action
)
class
TestActions
(
SimpleTestCase
):
...
...
@@ -61,3 +72,8 @@ class TestActions(SimpleTestCase):
name
=
'
action stations
'
action
=
Action
(
name
)
self
.
assertEqual
(
action
.
name
,
name
)
def
test_calling_processes_the_action
(
self
):
action
=
ActionFactory
()
with
self
.
assertRaises
(
NotImplementedError
):
action
()
This diff is collapsed.
Click to expand it.
opentech/apply/workflow.py
+
20
−
4
View file @
c7e5201b
...
...
@@ -26,13 +26,19 @@ class Workflow:
except
KeyError
:
return
0
,
-
1
def
__getitem__
(
self
,
value
):
return
self
.
stages
[
value
[
0
]].
phases
[
value
[
1
]]
def
current
(
self
,
current_phase
:
str
):
return
self
[
self
.
current_index
(
current_phase
)]
def
next
(
self
,
current_phase
:
Union
[
'
Phase
'
,
str
]
=
None
)
->
Union
[
'
Phase
'
,
None
]:
stage_idx
,
phase_idx
=
self
.
current_index
(
current_phase
)
try
:
return
self
.
stages
[
stage_idx
].
phases
[
phase_idx
+
1
]
return
self
[
stage_idx
,
phase_idx
+
1
]
except
IndexError
:
try
:
return
self
.
stages
[
stage_idx
+
1
].
phases
[
0
]
return
self
[
stage_idx
+
1
,
0
]
except
IndexError
:
return
None
...
...
@@ -57,17 +63,27 @@ class Phase:
def
__init__
(
self
,
name
:
str
,
actions
:
Sequence
[
'
Action
'
])
->
None
:
self
.
name
=
name
self
.
stage
:
Union
[
'
Stage
'
,
None
]
=
None
self
.
actions
=
actions
self
.
occurance
=
0
self
.
actions
=
{
action
.
name
:
action
for
action
in
actions
}
self
.
occurance
:
int
=
0
def
__str__
(
self
):
return
'
__
'
.
join
([
self
.
stage
.
name
,
self
.
name
,
str
(
self
.
occurance
)])
def
__getitem__
(
self
,
value
):
return
self
.
actions
[
value
]
class
Action
:
def
__init__
(
self
,
name
:
str
)
->
None
:
self
.
name
=
name
def
__call__
(
self
,
*
args
,
**
kwargs
):
return
self
.
process
(
*
args
,
**
kwargs
)
def
process
(
self
,
*
args
,
**
kwargs
):
# Use this to define the behaviour of the action
raise
NotImplementedError
# --- OTF Workflow ---
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment