For taskflow patterns don't show taskflow.patterns prefix

Showing the full name in flow __str__() isn't expecially
helpful and clutters up graphviz usage and similar so if a taskflow
built-in pattern is stringified just use the short name (that does
not start with taskflow.patterns instead of the full long name).

Change-Id: Icd8c26eab1e19d6ecf9c4e8e82e6d6902ce5b6ea
This commit is contained in:
Joshua Harlow
2015-12-14 11:06:48 -08:00
parent c444e656f8
commit a79ca4883a
4 changed files with 47 additions and 14 deletions

View File

@@ -35,6 +35,10 @@ LINK_REASONS = 'reasons'
# This key denotes a callable that will determine if the target is visited.
LINK_DECIDER = 'decider'
# Chop off full module names of patterns that are built-in to taskflow...
_CHOP_PAT = "taskflow.patterns."
_CHOP_PAT_LEN = len(_CHOP_PAT)
@six.add_metaclass(abc.ABCMeta)
class Flow(object):
@@ -108,8 +112,10 @@ class Flow(object):
"""
def __str__(self):
return "%s: %s(len=%d)" % (reflection.get_class_name(self),
self.name, len(self))
cls_name = reflection.get_class_name(self)
if cls_name.startswith(_CHOP_PAT):
cls_name = cls_name[_CHOP_PAT_LEN:]
return "%s: %s(len=%d)" % (cls_name, self.name, len(self))
@property
def provides(self):

View File

@@ -27,6 +27,19 @@ def _task(name, provides=None, requires=None):
class GraphFlowTest(test.TestCase):
def test_graph_flow_stringy(self):
f = gf.Flow('test')
expected = 'graph_flow.Flow: test(len=0)'
self.assertEqual(expected, str(f))
task1 = _task(name='task1')
task2 = _task(name='task2')
task3 = _task(name='task3')
f = gf.Flow('test')
f.add(task1, task2, task3)
expected = 'graph_flow.Flow: test(len=3)'
self.assertEqual(expected, str(f))
def test_graph_flow_starts_as_empty(self):
f = gf.Flow('test')
@@ -37,9 +50,6 @@ class GraphFlowTest(test.TestCase):
self.assertEqual(set(), f.requires)
self.assertEqual(set(), f.provides)
expected = 'taskflow.patterns.graph_flow.Flow: test(len=0)'
self.assertEqual(expected, str(f))
def test_graph_flow_add_nothing(self):
f = gf.Flow('test')
result = f.add()

View File

@@ -26,6 +26,19 @@ def _task(name, provides=None, requires=None):
class LinearFlowTest(test.TestCase):
def test_linear_flow_stringy(self):
f = lf.Flow('test')
expected = 'linear_flow.Flow: test(len=0)'
self.assertEqual(expected, str(f))
task1 = _task(name='task1')
task2 = _task(name='task2')
task3 = _task(name='task3')
f = lf.Flow('test')
f.add(task1, task2, task3)
expected = 'linear_flow.Flow: test(len=3)'
self.assertEqual(expected, str(f))
def test_linear_flow_starts_as_empty(self):
f = lf.Flow('test')
@@ -36,9 +49,6 @@ class LinearFlowTest(test.TestCase):
self.assertEqual(set(), f.requires)
self.assertEqual(set(), f.provides)
expected = 'taskflow.patterns.linear_flow.Flow: test(len=0)'
self.assertEqual(expected, str(f))
def test_linear_flow_add_nothing(self):
f = lf.Flow('test')
result = f.add()
@@ -104,9 +114,6 @@ class LinearFlowTest(test.TestCase):
(task2, task3, {'invariant': True})
], list(f.iter_links()))
expected = 'taskflow.patterns.linear_flow.Flow: test(len=3)'
self.assertEqual(expected, str(f))
def test_linear_flow_with_retry(self):
ret = retry.AlwaysRevert(requires=['a'], provides=['b'])
f = lf.Flow('test', ret)

View File

@@ -26,6 +26,19 @@ def _task(name, provides=None, requires=None):
class UnorderedFlowTest(test.TestCase):
def test_unordered_flow_stringy(self):
f = uf.Flow('test')
expected = 'unordered_flow.Flow: test(len=0)'
self.assertEqual(expected, str(f))
task1 = _task(name='task1')
task2 = _task(name='task2')
task3 = _task(name='task3')
f = uf.Flow('test')
f.add(task1, task2, task3)
expected = 'unordered_flow.Flow: test(len=3)'
self.assertEqual(expected, str(f))
def test_unordered_flow_starts_as_empty(self):
f = uf.Flow('test')
@@ -36,9 +49,6 @@ class UnorderedFlowTest(test.TestCase):
self.assertEqual(set(), f.requires)
self.assertEqual(set(), f.provides)
expected = 'taskflow.patterns.unordered_flow.Flow: test(len=0)'
self.assertEqual(expected, str(f))
def test_unordered_flow_add_nothing(self):
f = uf.Flow('test')
result = f.add()