MCPcopy Create free account
hub / github.com/datacamp/pythonwhat / build_sub_test_nodes

Method build_sub_test_nodes

pythonwhat/probe.py:223–248  ·  view source on GitHub ↗
(test, tree, node, arg_name)

Source from the content-addressed store, hash-verified

221
222 @staticmethod
223 def build_sub_test_nodes(test, tree, node, arg_name):
224 # note that I've made the strong assumption that
225 # if not a function, then test is a dict, list or tuple of them
226 if isinstance(test, (list, tuple)):
227 nl = NodeList(name="List", arg_name=arg_name)
228 node.add_child(nl)
229 for ii, f in enumerate(test):
230 Probe.build_sub_test_nodes(f, tree, nl, str(ii))
231 elif isinstance(test, Node):
232 # test was a lambdaless subtest call, which produced a node
233 # so need to tell it what its arg_name was on parent test
234 test.arg_name = arg_name
235 node.add_child(test)
236 elif callable(test):
237 # test was inside a lambda, function containing subtests or v2 F() chain object with subtests
238 # since either may contain multiple subtests, we put them in a node list
239 nl = NodeList(name="ListDeferred", arg_name=arg_name)
240 node.add_child(nl)
241 if tree is not None:
242 prev_node, tree.crnt_node = tree.crnt_node, nl
243 test()
244 tree.crnt_node = prev_node
245 else:
246 test()
247 elif test is not None:
248 raise Exception("Expected a function or list/tuple/dict of functions")
249
250
251def build_probe_context():

Callers 1

__call__Method · 0.95

Calls 2

NodeListClass · 0.85
add_childMethod · 0.80

Tested by

no test coverage detected