diff --git a/taskflow/tests/unit/test_action_engine.py b/taskflow/tests/unit/test_action_engine.py index 759416a8..7c535adb 100644 --- a/taskflow/tests/unit/test_action_engine.py +++ b/taskflow/tests/unit/test_action_engine.py @@ -202,7 +202,7 @@ class EngineTaskTest(EngineTestBase): 'flow FAILURE', 'flow REVERTING', 'fail REVERTING', - 'fail reverted(Failure: exceptions.RuntimeError: Woot!)', + 'fail reverted(Failure: RuntimeError: Woot!)', 'fail REVERTED', 'fail PENDING', 'flow REVERTED']) @@ -382,7 +382,7 @@ class EngineLinearFlowTest(EngineTestBase): engine.run() self.assertEquals( self.values, - ['fail reverted(Failure: exceptions.RuntimeError: Woot!)']) + ['fail reverted(Failure: RuntimeError: Woot!)']) def test_correctly_reverts_children(self): flow = lf.Flow('root-1').add( @@ -398,7 +398,7 @@ class EngineLinearFlowTest(EngineTestBase): self.assertEquals( self.values, ['task1', 'task2', - 'fail reverted(Failure: exceptions.RuntimeError: Woot!)', + 'fail reverted(Failure: RuntimeError: Woot!)', 'task2 reverted(5)', 'task1 reverted(5)']) @@ -540,7 +540,7 @@ class EngineGraphFlowTest(EngineTestBase): self.assertEquals( self.values, ['task1', 'task2', - 'task3 reverted(Failure: exceptions.RuntimeError: Woot!)', + 'task3 reverted(Failure: RuntimeError: Woot!)', 'task2 reverted(5)', 'task1 reverted(5)']) def test_graph_flow_four_tasks_revert_failure(self): @@ -634,7 +634,7 @@ class SuspendFlowTest(EngineTestBase): self.assertEquals( self.values, ['a', 'b', - 'c reverted(Failure: exceptions.RuntimeError: Woot!)', + 'c reverted(Failure: RuntimeError: Woot!)', 'b reverted(5)']) with self.assertRaisesRegexp(RuntimeError, '^Woot'): engine.run() @@ -643,7 +643,7 @@ class SuspendFlowTest(EngineTestBase): self.values, ['a', 'b', - 'c reverted(Failure: exceptions.RuntimeError: Woot!)', + 'c reverted(Failure: RuntimeError: Woot!)', 'b reverted(5)', 'a reverted(5)']) @@ -852,7 +852,7 @@ class MultiThreadedEngineTest(EngineTaskTest, 'task1', 'task1 reverted(5)', 'task2', 'task2 reverted(5)', 'task3', 'task3 reverted(5)', - 'fail reverted(Failure: exceptions.RuntimeError: Woot!)' + 'fail reverted(Failure: RuntimeError: Woot!)' ]) self.assertIsSubset(possible_result, result) diff --git a/taskflow/tests/unit/test_utils.py b/taskflow/tests/unit/test_utils.py index b745491c..65835761 100644 --- a/taskflow/tests/unit/test_utils.py +++ b/taskflow/tests/unit/test_utils.py @@ -19,6 +19,7 @@ import sys from taskflow import test +from taskflow.tests import utils as test_utils from taskflow.utils import lock_utils from taskflow.utils import misc from taskflow.utils import reflection @@ -149,9 +150,13 @@ class AcceptsKwargsTest(test.TestCase): class GetClassNameTest(test.TestCase): - def test_std_class(self): + def test_std_exception(self): name = reflection.get_class_name(RuntimeError) - self.assertEquals(name, 'exceptions.RuntimeError') + self.assertEquals(name, 'RuntimeError') + + def test_global_class(self): + name = reflection.get_class_name(misc.Failure) + self.assertEquals(name, 'taskflow.utils.misc.Failure') def test_class(self): name = reflection.get_class_name(Class) @@ -163,27 +168,19 @@ class GetClassNameTest(test.TestCase): def test_int(self): name = reflection.get_class_name(42) - self.assertEquals(name, '__builtin__.int') + self.assertEquals(name, 'int') class GetAllClassNamesTest(test.TestCase): def test_std_class(self): names = list(reflection.get_all_class_names(RuntimeError)) - self.assertEquals(names, [ - 'exceptions.RuntimeError', - 'exceptions.StandardError', - 'exceptions.Exception', - 'exceptions.BaseException', - '__builtin__.object']) + self.assertEquals(names, test_utils.RUNTIME_ERROR_CLASSES) def test_std_class_up_to(self): names = list(reflection.get_all_class_names(RuntimeError, up_to=Exception)) - self.assertEquals(names, [ - 'exceptions.RuntimeError', - 'exceptions.StandardError', - 'exceptions.Exception']) + self.assertEquals(names, test_utils.RUNTIME_ERROR_CLASSES[:-2]) class ExcInfoUtilsTest(test.TestCase): diff --git a/taskflow/tests/unit/test_utils_failure.py b/taskflow/tests/unit/test_utils_failure.py index 38a3ff2f..fc076ba3 100644 --- a/taskflow/tests/unit/test_utils_failure.py +++ b/taskflow/tests/unit/test_utils_failure.py @@ -19,6 +19,7 @@ from taskflow import exceptions from taskflow import test +from taskflow.tests import utils as test_utils from taskflow.utils import misc @@ -37,20 +38,18 @@ class GeneralFailureObjTestsMixin(object): def test_str(self): self.assertEquals(str(self.fail_obj), - 'Failure: exceptions.RuntimeError: Woot!') + 'Failure: RuntimeError: Woot!') def test_exception_types(self): self.assertEquals(list(self.fail_obj), - ['exceptions.RuntimeError', - 'exceptions.StandardError', - 'exceptions.Exception']) + test_utils.RUNTIME_ERROR_CLASSES[:-2]) def test_check_str(self): - val = 'exceptions.StandardError' + val = 'Exception' self.assertEquals(self.fail_obj.check(val), val) def test_check_str_not_there(self): - val = 'exceptions.ValueError' + val = 'ValueError' self.assertEquals(self.fail_obj.check(val), None) def test_check_type(self): @@ -115,7 +114,7 @@ class FailureObjectTestCase(test.TestCase): misc.Failure( exception_str='Woot!', traceback_str=None, - exc_type_names=['exceptions.Exception'], + exc_type_names=['Exception'], hi='hi there') expected = "Failure.__init__ got unexpected keyword argument: 'hi'" self.assertEquals(str(ctx.exception), expected) diff --git a/taskflow/tests/utils.py b/taskflow/tests/utils.py index 7ebd69b2..b4f33dad 100644 --- a/taskflow/tests/utils.py +++ b/taskflow/tests/utils.py @@ -16,6 +16,8 @@ # License for the specific language governing permissions and limitations # under the License. +import six + from taskflow import task ARGS_KEY = '__args__' @@ -75,17 +77,19 @@ class ProvidesRequiresTask(task.Task): ARGS_KEY: args, }) if self.return_tuple: - outs = [] - for i in xrange(0, len(self.provides)): - outs.append(i) - return tuple(outs) + return tuple(range(len(self.provides))) else: - outs = {} - for k in self.provides: - outs[k] = k - return outs + return dict((k, k) for k in self.provides) class DummyTask(task.Task): def execute(self, context, *args, **kwargs): pass + + +if six.PY3: + RUNTIME_ERROR_CLASSES = ['RuntimeError', 'Exception', + 'BaseException', 'object'] +else: + RUNTIME_ERROR_CLASSES = ['RuntimeError', 'StandardError', 'Exception', + 'BaseException', 'object'] diff --git a/taskflow/utils/reflection.py b/taskflow/utils/reflection.py index 171e31e9..0f3fef16 100644 --- a/taskflow/utils/reflection.py +++ b/taskflow/utils/reflection.py @@ -17,6 +17,7 @@ # under the License. import inspect +import six import types @@ -25,9 +26,12 @@ def get_class_name(obj): If object is a type, fully qualified name of the type is returned. Else, fully qualified name of the type of the object is returned. + For builtin types, just name is returned. """ - if not isinstance(obj, type): + if not isinstance(obj, six.class_types): obj = type(obj) + if obj.__module__ in ('builtins', '__builtin__', 'exceptions'): + return obj.__name__ return '.'.join((obj.__module__, obj.__name__))