-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #355 from sartography/bugfix/depth-calc-and-task-d…
…ict-fixes Bugfix/depth calc and task dict fixes
- Loading branch information
Showing
7 changed files
with
198 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import unittest | ||
import os | ||
from datetime import datetime | ||
|
||
from lxml import etree | ||
|
||
from SpiffWorkflow.workflow import Workflow | ||
from SpiffWorkflow.specs.Cancel import Cancel | ||
from SpiffWorkflow.specs.Simple import Simple | ||
from SpiffWorkflow.specs.WorkflowSpec import WorkflowSpec | ||
from SpiffWorkflow.util.task import TaskState, TaskIterator, TaskFilter | ||
from SpiffWorkflow.serializer.prettyxml import XmlSerializer | ||
|
||
data_dir = os.path.join(os.path.dirname(__file__), 'data') | ||
|
||
class IterationTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
xml_file = os.path.join(data_dir, 'iteration_test.xml') | ||
with open(xml_file) as fp: | ||
xml = etree.parse(fp).getroot() | ||
wf_spec = WorkflowSpec.deserialize(XmlSerializer(), xml) | ||
self.workflow = Workflow(wf_spec) | ||
|
||
def get_tasks_updated_after(self): | ||
start = self.workflow.get_next_task(end_at_spec='Start') | ||
start.run() | ||
updated = datetime.now().timestamp() | ||
for task in self.workflow.get_tasks(state=TaskState.READY): | ||
task.run() | ||
return updated | ||
|
||
class DepthFirstTest(IterationTest): | ||
|
||
def test_get_tasks_updated_after(self): | ||
updated = super().get_tasks_updated_after() | ||
tasks = self.workflow.get_tasks(updated_ts=updated) | ||
self.assertListEqual( | ||
[t.task_spec.name for t in tasks], | ||
['a', 'a1', 'a2', 'c', 'b', 'b1', 'b2'] | ||
) | ||
|
||
def test_get_tasks_end_at(self): | ||
tasks = self.workflow.get_tasks(end_at_spec='c') | ||
self.assertEqual( | ||
[t.task_spec.name for t in tasks], | ||
['Start', 'a', 'a1', 'last', 'End', 'a2', 'last', 'End', 'c'] | ||
) | ||
|
||
def test_get_tasks_max_depth(self): | ||
tasks = self.workflow.get_tasks(max_depth=2) | ||
self.assertEqual( | ||
[t.task_spec.name for t in tasks], | ||
['Start', 'a', 'a1', 'a2', 'c', 'b', 'b1', 'b2'] | ||
) | ||
|
||
class BreadthFirstTest(IterationTest): | ||
|
||
def test_get_tasks_updated_after(self): | ||
updated = super().get_tasks_updated_after() | ||
tasks = self.workflow.get_tasks(updated_ts=updated, depth_first=False) | ||
self.assertListEqual( | ||
[t.task_spec.name for t in tasks], | ||
['a', 'b', 'a1', 'a2', 'c', 'b1', 'b2'] | ||
) | ||
|
||
def test_get_tasks_end_at(self): | ||
tasks = self.workflow.get_tasks(end_at_spec='c', depth_first=False) | ||
self.assertEqual( | ||
[t.task_spec.name for t in tasks], | ||
['Start', 'a', 'b', 'a1', 'a2', 'c'] | ||
) | ||
|
||
def test_get_tasks_max_depth(self): | ||
tasks = self.workflow.get_tasks(max_depth=2, depth_first=False) | ||
self.assertEqual( | ||
[t.task_spec.name for t in tasks], | ||
['Start', 'a', 'b', 'a1', 'a2', 'c', 'b1', 'b2'] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<process-definition name="Test Iteration" revision="1.0"> | ||
<description> | ||
A test workflow to be used to test task iteration. | ||
</description> | ||
|
||
<!-- Start with an implicit simple split. --> | ||
<start-task> | ||
<successor>a</successor> | ||
<successor>b</successor> | ||
</start-task> | ||
|
||
<task name="a"> | ||
<successor>a1</successor> | ||
<successor>a2</successor> | ||
<successor>c</successor> | ||
</task> | ||
|
||
<task name="b"> | ||
<successor>b1</successor> | ||
<successor>b2</successor> | ||
</task> | ||
|
||
<task name="c"> | ||
<successor>c1</successor> | ||
<successor>c2</successor> | ||
</task> | ||
|
||
<task name="a1"> | ||
<successor>last</successor> | ||
</task> | ||
<task name="a2"> | ||
<successor>last</successor> | ||
</task> | ||
|
||
<task name="b1"> | ||
<successor>last</successor> | ||
</task> | ||
<task name="b2"> | ||
<successor>last</successor> | ||
</task> | ||
|
||
<task name="c1"> | ||
<successor>last</successor> | ||
</task> | ||
<task name="c2"> | ||
<successor>last</successor> | ||
</task> | ||
|
||
<task name="last"> | ||
<successor>end</successor> | ||
</task> | ||
</process-definition> |