def getdep(self, target, environ): if self._case is None or self._case() is None: raise DependencyError('no test case is associated with this test') for d in self._case().deps: if d.check.name == target and d.environ.name == environ: return d.check raise DependencyError('could not resolve dependency to (%s, %s)' % (target, environ))
def resolve_dep(target, from_map, *args): errmsg = 'could not resolve dependency: %s' % target try: ret = from_map[args] except KeyError: raise DependencyError(errmsg) else: if not ret: raise DependencyError(errmsg) return ret
def resolve_dep(src, dst): errmsg = f'could not resolve dependency: {src!r} -> {dst!r}' try: ret = all_cases_map[dst] except KeyError: # Try to resolve the dependency in the fallback map try: ret = default_cases_map[dst] except KeyError: raise DependencyError(errmsg) from None if not ret: raise DependencyError(errmsg) return ret
def resolve_dep(target, from_map, fallback_map, *args): errmsg = 'could not resolve dependency: %s -> %s' % (target, args) try: ret = from_map[args] except KeyError: # try to resolve the dependency in the fallback map try: ret = fallback_map[args] except KeyError: raise DependencyError(errmsg) from None if not ret: raise DependencyError(errmsg) return ret
def validate_deps(graph): """Validate dependency graph.""" # Reduce test case graph to a test name only graph; this disallows # pseudo-dependencies as follows: # # (t0, e1) -> (t1, e1) # (t1, e0) -> (t0, e0) # # This reduction step will result in a graph description with duplicate # entries in the adjacency list; this is not a problem, cos they will be # filtered out during the DFS traversal below. test_graph = {} for case, deps in graph.items(): test_deps = [d.check.name for d in deps] try: test_graph[case.check.name] += test_deps except KeyError: test_graph[case.check.name] = test_deps # Check for cyclic dependencies in the test name graph visited = set() sources = set(test_graph.keys()) path = [] # Since graph may comprise multiple not connected subgraphs, we search for # cycles starting from all possible sources while sources: unvisited = [(sources.pop(), None)] while unvisited: node, parent = unvisited.pop() while path and path[-1] != parent: path.pop() adjacent = reversed(test_graph[node]) path.append(node) for n in adjacent: if n in path: cycle_str = '->'.join(path + [n]) raise DependencyError( 'found cyclic dependency between tests: ' + cycle_str) if n not in visited: unvisited.append((n, node)) visited.add(node) sources -= visited
def validate_deps(graph): '''Validate dependency graph.''' # Reduce test case graph to a test name only graph; this disallows # pseudo-dependencies as follows: # # (t0, e1) -> (t1, e1) # (t1, e0) -> (t0, e0) # test_graph = _reduce_deps(graph) # Check for cyclic dependencies in the test name graph visited = set() sources = set(test_graph.keys()) path = [] # Since graph may comprise multiple not connected subgraphs, we search for # cycles starting from all possible sources while sources: unvisited = [(sources.pop(), None)] while unvisited: node, parent = unvisited.pop() while path and path[-1] != parent: path.pop() adjacent = test_graph[node] path.append(node) for n in adjacent: if n in path: cycle_str = '->'.join(path + [n]) raise DependencyError( 'found cyclic dependency between tests: ' + cycle_str) if n not in visited: unvisited.append((n, node)) visited.add(node) sources -= visited