Showing content from http://mail.python.org/pipermail/python-dev/attachments/20070825/df266f1e/attachment.py below:
class CycleError(Exception): pass class TestGraph: ignore_dependencies = False def __init__(self): self.graph = {} tests = [x for x in dir(self) if x.startswith('test')] for testname in tests: test = getattr(self, testname) if hasattr(test, 'deps'): self.graph[testname] = test.deps else: self.graph[testname] = set() def run(self): graph = self.graph toskip = set() msgs = [] if self.ignore_dependencies: for test in graph: graph[test].clear() # find tests without any pending dependencies queue = [test for test, deps in graph.items() if not deps] while queue: testname = queue.pop() if testname in toskip: msgs.append("%s... skipped" % testname) queue.extend(resolve(graph, testname)) continue test = getattr(self, testname) try: test() except AssertionError: toskip.update(getrevdeps(graph, testname)) msgs.append("%s... failed" % testname) except: toskip.update(getrevdeps(graph, testname)) msgs.append("%s... error" % testname) else: msgs.append("%s... ok" % testname) finally: queue.extend(resolve(graph, testname)) if graph: raise CycleError for msg in sorted(msgs): print(msg) def getrevdeps(graph, testname): """Return the reverse depencencies of a test""" rdeps = set() for x in graph: if testname in graph[x]: rdeps.add(x) if rdeps: # propagate depencencies recursively for x in rdeps.copy(): rdeps.update(getrevdeps(graph, x)) return rdeps def resolve(graph, testname): toqueue = [] for test in graph: if testname in graph[test]: graph[test].remove(testname) if not graph[test]: toqueue.append(test) del graph[testname] return toqueue def depends(*args): def decorator(test): if hasattr(test, 'deps'): test.deps.update(args) else: test.deps = set(args) return test return decorator class MyTest(TestGraph): ignore_dependencies = True @depends('test_foo') def test_nah(self): pass @depends('test_bar', 'test_baz') def test_foo(self): pass @depends('test_tin') def test_bar(self): self.fail() def test_baz(self): self.error() def test_tin(self): pass def error(self): raise ValueError def fail(self): raise AssertionError if __name__ == '__main__': t = MyTest() t.run()
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4