MCPcopy Index your code
hub / github.com/datacamp/pythonwhat / check_node

Function check_node

pythonwhat/checks/check_funcs.py:110–142  ·  view source on GitHub ↗
(
    state, name, index=0, typestr="{{ordinal}} node", missing_msg=None, expand_msg=None
)

Source from the content-addressed store, hash-verified

108
109
110def check_node(
111 state, name, index=0, typestr="{{ordinal}} node", missing_msg=None, expand_msg=None
112):
113
114 if missing_msg is None:
115 missing_msg = "The system wants to check the {{typestr}} but hasn't found it."
116 if expand_msg is None:
117 expand_msg = "Check the {{typestr}}. "
118
119 stu_out = state.ast_dispatcher.find(name, state.student_ast)
120 sol_out = state.ast_dispatcher.find(name, state.solution_ast)
121
122 # check if there are enough nodes for index
123 fmt_kwargs = {
124 "ordinal": get_ord(index + 1) if isinstance(index, int) else "",
125 "index": index,
126 "name": name,
127 }
128 fmt_kwargs["typestr"] = render(typestr, fmt_kwargs)
129
130 # test if node can be indexed succesfully
131 try:
132 stu_out[index]
133 except (KeyError, IndexError): # TODO comment errors
134 state.report(missing_msg, fmt_kwargs)
135
136 # get node at index
137 stu_part = stu_out[index]
138 sol_part = sol_out[index]
139
140 append_message = FeedbackComponent(expand_msg, fmt_kwargs)
141
142 return part_to_child(stu_part, sol_part, append_message, state, node_name=name)
143
144
145# context functions -----------------------------------------------------------

Callers 5

test_if_elseFunction · 0.90
test_for_loopFunction · 0.90
test_while_loopFunction · 0.90
test_function_definitionFunction · 0.90
test_compFunction · 0.90

Calls 3

renderFunction · 0.85
part_to_childFunction · 0.85
findMethod · 0.80

Tested by 5

test_if_elseFunction · 0.72
test_for_loopFunction · 0.72
test_while_loopFunction · 0.72
test_function_definitionFunction · 0.72
test_compFunction · 0.72