-
Notifications
You must be signed in to change notification settings - Fork 320
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
Bugfix/depth calc and task dict fixes #355
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you writing a computer science textbook here or what? :)