From 038d284687b4628f50746b1888e77f3787a0eb39 Mon Sep 17 00:00:00 2001 From: Greg Leclercq Date: Sun, 6 Jul 2014 18:03:52 +0200 Subject: [PATCH] Update activity: put full module in name --- simpleflow/activity.py | 13 ++++++++----- tests/test_dataflow.py | 36 ++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/simpleflow/activity.py b/simpleflow/activity.py index 204044773..730365986 100644 --- a/simpleflow/activity.py +++ b/simpleflow/activity.py @@ -58,13 +58,16 @@ def name(self): return self._name callable = self._callable - if hasattr(callable, 'name'): - return callable.name + prefix = self._callable.__module__ - if isinstance(callable, types.FunctionType): - return callable.func_name + if hasattr(callable, 'name'): + name = callable.name + elif isinstance(callable, types.FunctionType): + name = callable.func_name + else: + name = callable.__class__.__name__ - return callable.__class__.__name__ + return '.'.join([prefix, name]) def __repr__(self): return 'Activity(name={}, version={}, task_list={})'.format( diff --git a/tests/test_dataflow.py b/tests/test_dataflow.py index 0dc8c9cd8..e36f7b29a 100644 --- a/tests/test_dataflow.py +++ b/tests/test_dataflow.py @@ -81,7 +81,7 @@ def test_workflow_with_input(): .add_activity_task(increment, decision_id=decision_id, last_state='completed', - activity_id='activity-increment-1', + activity_id='activity-tests.test_dataflow.increment-1', input={'args': 1}, result=result) .add_decision_task_scheduled() @@ -127,7 +127,7 @@ def test_workflow_with_two_tasks(): .add_activity_task(increment, decision_id=decision_id, last_state='completed', - activity_id='activity-increment-1', + activity_id='activity-tests.test_dataflow.increment-1', input={'args': 1}, result=2) .add_decision_task_scheduled() @@ -145,7 +145,7 @@ def test_workflow_with_two_tasks(): .add_activity_task(double, decision_id=decision_id, last_state='completed', - activity_id='activity-double-1', + activity_id='activity-tests.test_dataflow.double-1', input={'args': 2}, result=4) .add_decision_task_scheduled() @@ -184,7 +184,7 @@ def test_workflow_with_two_tasks_not_completed(): .add_activity_task(increment, decision_id=decision_id, last_state='started', - activity_id='activity-increment-1', + activity_id='activity-tests.test_dataflow.increment-1', input={'args': 1}, result=5) .add_decision_task_scheduled() @@ -247,7 +247,7 @@ def test_workflow_with_same_task_called_two_times(): .add_activity_task(increment, decision_id=decision_id, last_state='completed', - activity_id='activity-increment-1', + activity_id='activity-tests.test_dataflow.increment-1', input={'args': 1}, result=2) .add_decision_task_scheduled() @@ -264,7 +264,7 @@ def test_workflow_with_same_task_called_two_times(): .add_activity_task(increment, decision_id=decision_id, last_state='completed', - activity_id='activity-increment-2', + activity_id='activity-tests.test_dataflow.increment-2', input={'args': 2}, result=3) .add_decision_task_scheduled() @@ -309,7 +309,7 @@ def test_workflow_reuse_same_future(): decision_id=decision_id, last_state='completed', input={'args': 1}, - activity_id='activity-increment-1', + activity_id='activity-tests.test_dataflow.increment-1', result=2) .add_decision_task_scheduled() .add_decision_task_started()) @@ -324,7 +324,7 @@ def test_workflow_reuse_same_future(): .add_activity_task(double, decision_id=decision_id, last_state='completed', - activity_id='activity-double-1', + activity_id='activity-tests.test_dataflow.double-1', input={'args': 2}, result=4) .add_decision_task_scheduled() @@ -370,7 +370,7 @@ def test_workflow_with_two_tasks_same_future(): .add_activity_task(increment, decision_id=decision_id, last_state='completed', - activity_id='activity-increment-1', + activity_id='activity-tests.test_dataflow.increment-1', input={'args': 1}, result=2) .add_decision_task_scheduled() @@ -388,13 +388,13 @@ def test_workflow_with_two_tasks_same_future(): .add_activity_task(double, decision_id=decision_id, last_state='completed', - activity_id='activity-double-1', + activity_id='activity-tests.test_dataflow.double-1', input={'args': 2}, result=4) .add_activity_task(increment, decision_id=decision_id, last_state='completed', - activity_id='activity-increment-2', + activity_id='activity-tests.test_dataflow.increment-2', input={'args': 2}, result=3) .add_decision_task_scheduled() @@ -444,7 +444,7 @@ def test_workflow_map(): history.add_activity_task( increment, decision_id=decision_id, - activity_id='activity-increment-{}'.format( + activity_id='activity-tests.test_dataflow.increment-{}'.format( i + 1), last_state='completed', input={'args': i}, @@ -494,7 +494,7 @@ def test_workflow_retry_activity(): .add_activity_task(increment_retry, decision_id=decision_id, last_state='failed', - activity_id='activity-increment_retry-1') + activity_id='activity-tests.test_dataflow.increment_retry-1') .add_decision_task_scheduled() .add_decision_task_started()) @@ -509,7 +509,7 @@ def test_workflow_retry_activity(): .add_activity_task(increment_retry, decision_id=decision_id, last_state='completed', - activity_id='activity-increment_retry-1', + activity_id='activity-tests.test_dataflow.increment_retry-1', input={'args': 7}, result=8) .add_decision_task_scheduled() @@ -606,7 +606,7 @@ def test_workflow_with_more_than_max_decisions(): history.add_activity_task( increment, decision_id=decision_id, - activity_id='activity-increment-{}'.format( + activity_id='activity-tests.test_dataflow.increment-{}'.format( i + 1), last_state='completed', result=i + 1) @@ -623,7 +623,7 @@ def test_workflow_with_more_than_max_decisions(): history.add_activity_task( increment, decision_id=decision_id, - activity_id='activity-increment-{}'.format( + activity_id='activity-tests.test_dataflow.increment-{}'.format( i + 1), last_state='completed', result=i + 1) @@ -668,7 +668,7 @@ def test_workflow_failed_from_definition(): history.add_activity_task( raise_error, decision_id=history.last_id, - activity_id='activity-raise_error-1', + activity_id='activity-tests.test_dataflow.raise_error-1', last_state='failed', result=json.dumps(None)) @@ -709,7 +709,7 @@ def test_workflow_activity_raises_on_failure(): history.add_activity_task( raise_on_failure, decision_id=history.last_id, - activity_id='activity-raise_on_failure-1', + activity_id='activity-tests.test_dataflow.raise_on_failure-1', last_state='failed', reason='error')