diff --git a/taskflow/exceptions.py b/taskflow/exceptions.py index 29ae711e..2e3f772e 100644 --- a/taskflow/exceptions.py +++ b/taskflow/exceptions.py @@ -45,24 +45,19 @@ class AlreadyExists(TaskFlowException): pass -class ClosedException(TaskFlowException): - """Raised when an access on a closed object occurs.""" - pass - - -class InvalidStateException(TaskFlowException): +class InvalidState(TaskFlowException): """Raised when a task/job/workflow is in an invalid state when an operation is attempting to apply to said task/job/workflow. """ pass -class InvariantViolationException(TaskFlowException): +class InvariantViolation(TaskFlowException): """Raised when flow invariant violation is attempted.""" pass -class UnclaimableJobException(TaskFlowException): +class UnclaimableJob(TaskFlowException): """Raised when a job can not be claimed.""" pass @@ -72,7 +67,7 @@ class JobNotFound(TaskFlowException): pass -class MissingDependencies(InvalidStateException): +class MissingDependencies(InvariantViolation): """Raised when a entity has dependencies that can not be satisfied.""" message = ("%(who)s requires %(requirements)s but no other entity produces" " said requirements") diff --git a/taskflow/patterns/linear_flow.py b/taskflow/patterns/linear_flow.py index 9f85efe9..6864fbec 100644 --- a/taskflow/patterns/linear_flow.py +++ b/taskflow/patterns/linear_flow.py @@ -45,7 +45,7 @@ class Flow(flow.Flow): requires |= item.requires out_of_order = requires & item.provides if out_of_order: - raise exceptions.InvariantViolationException( + raise exceptions.InvariantViolation( "%(item)s provides %(oo)s that are required " "by previous item(s) of linear flow %(flow)s" % dict(item=item.name, flow=self.name, diff --git a/taskflow/patterns/unordered_flow.py b/taskflow/patterns/unordered_flow.py index 200fbdd0..328fcadb 100644 --- a/taskflow/patterns/unordered_flow.py +++ b/taskflow/patterns/unordered_flow.py @@ -47,7 +47,7 @@ class Flow(flow.Flow): item_provides = item.provides bad_provs = item_provides & old_requires if bad_provs: - raise exceptions.InvariantViolationException( + raise exceptions.InvariantViolation( "%(item)s provides %(oo)s that are required " "by other item(s) of unordered flow %(flow)s" % dict(item=item.name, flow=self.name, @@ -65,7 +65,7 @@ class Flow(flow.Flow): for item in items: bad_reqs = provides & item.requires if bad_reqs: - raise exceptions.InvariantViolationException( + raise exceptions.InvariantViolation( "%(item)s requires %(oo)s that are provided " "by other item(s) of unordered flow %(flow)s" % dict(item=item.name, flow=self.name, diff --git a/taskflow/states.py b/taskflow/states.py index 40c1f28a..d3a4b06b 100644 --- a/taskflow/states.py +++ b/taskflow/states.py @@ -112,7 +112,7 @@ def check_flow_transition(old_state, new_state): If transition can be performed, it returns True. If transition should be ignored, it returns False. If transition is not - valid, it raises InvalidStateException. + valid, it raises InvalidState exception. """ if old_state == new_state: return False @@ -121,8 +121,8 @@ def check_flow_transition(old_state, new_state): return True if pair in _IGNORED_FLOW_TRANSITIONS: return False - raise exc.InvalidStateException( - "Flow transition from %s to %s is not allowed" % pair) + raise exc.InvalidState("Flow transition from %s to %s is not allowed" + % pair) ## Task state transitions diff --git a/taskflow/tests/unit/test_check_transition.py b/taskflow/tests/unit/test_check_transition.py index cb0388ac..f2495411 100644 --- a/taskflow/tests/unit/test_check_transition.py +++ b/taskflow/tests/unit/test_check_transition.py @@ -40,7 +40,7 @@ class CheckFlowTransitionTest(test.TestCase): states.check_flow_transition(states.RUNNING, states.RESUMING)) def test_bad_transition_raises(self): - self.assertRaisesRegexp(exc.InvalidStateException, + self.assertRaisesRegexp(exc.InvalidState, '^Flow transition.*not allowed', states.check_flow_transition, states.FAILURE, states.SUCCESS) diff --git a/taskflow/tests/unit/test_flattening.py b/taskflow/tests/unit/test_flattening.py index 9f8eade4..232b0734 100644 --- a/taskflow/tests/unit/test_flattening.py +++ b/taskflow/tests/unit/test_flattening.py @@ -174,7 +174,7 @@ class FlattenTest(test.TestCase): t_utils.DummyTask(name="a"), t_utils.DummyTask(name="a") ) - self.assertRaisesRegexp(exc.InvariantViolationException, + self.assertRaisesRegexp(exc.InvariantViolation, '^Tasks with duplicate names', f_utils.flatten, flo) @@ -182,6 +182,6 @@ class FlattenTest(test.TestCase): flo = gf.Flow("test").add( gf.Flow("int1").add(t_utils.DummyTask(name="a")), gf.Flow("int2").add(t_utils.DummyTask(name="a"))) - self.assertRaisesRegexp(exc.InvariantViolationException, + self.assertRaisesRegexp(exc.InvariantViolation, '^Tasks with duplicate names', f_utils.flatten, flo) diff --git a/taskflow/tests/unit/test_flow_dependencies.py b/taskflow/tests/unit/test_flow_dependencies.py index 8aa502b9..5d326307 100644 --- a/taskflow/tests/unit/test_flow_dependencies.py +++ b/taskflow/tests/unit/test_flow_dependencies.py @@ -87,7 +87,7 @@ class FlowDependenciesTest(test.TestCase): def test_linear_flow_provides_out_of_order(self): flow = lf.Flow('lf') - self.assertRaises(exceptions.InvariantViolationException, + self.assertRaises(exceptions.InvariantViolation, flow.add, utils.TaskOneArg('task2'), utils.TaskOneReturn('task1', provides='x')) @@ -111,7 +111,7 @@ class FlowDependenciesTest(test.TestCase): def test_linear_flow_self_requires(self): flow = lf.Flow('lf') - self.assertRaises(exceptions.InvariantViolationException, + self.assertRaises(exceptions.InvariantViolation, flow.add, utils.TaskNoRequiresNoReturns(rebind=['x'], provides='x')) @@ -138,7 +138,7 @@ class FlowDependenciesTest(test.TestCase): def test_unordered_flow_self_requires(self): flow = uf.Flow('uf') - self.assertRaises(exceptions.InvariantViolationException, + self.assertRaises(exceptions.InvariantViolation, flow.add, utils.TaskNoRequiresNoReturns(rebind=['x'], provides='x')) @@ -166,7 +166,7 @@ class FlowDependenciesTest(test.TestCase): def test_unordered_flow_provides_required_values(self): flow = uf.Flow('uf') - self.assertRaises(exceptions.InvariantViolationException, + self.assertRaises(exceptions.InvariantViolation, flow.add, utils.TaskOneReturn('task1', provides='x'), utils.TaskOneArg('task2')) @@ -174,14 +174,14 @@ class FlowDependenciesTest(test.TestCase): def test_unordered_flow_requires_provided_value_other_call(self): flow = uf.Flow('uf') flow.add(utils.TaskOneReturn('task1', provides='x')) - self.assertRaises(exceptions.InvariantViolationException, + self.assertRaises(exceptions.InvariantViolation, flow.add, utils.TaskOneArg('task2')) def test_unordered_flow_provides_required_value_other_call(self): flow = uf.Flow('uf') flow.add(utils.TaskOneArg('task2')) - self.assertRaises(exceptions.InvariantViolationException, + self.assertRaises(exceptions.InvariantViolation, flow.add, utils.TaskOneReturn('task1', provides='x')) diff --git a/taskflow/utils/flow_utils.py b/taskflow/utils/flow_utils.py index d446889f..1fa2f1d3 100644 --- a/taskflow/utils/flow_utils.py +++ b/taskflow/utils/flow_utils.py @@ -147,7 +147,7 @@ def _post_flatten(graph): dup_names = misc.get_duplicate_keys(graph.nodes_iter(), key=lambda node: node.name) if dup_names: - raise exceptions.InvariantViolationException( + raise exceptions.InvariantViolation( "Tasks with duplicate names found: %s" % ', '.join(sorted(dup_names))) return graph