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

Function set_env

pythonwhat/checks/check_logic.py:256–294  ·  view source on GitHub ↗

Update/set environemnt variables for student and solution environments. When ``has_equal_x()`` is used after this, the variables specified through this function will be available in the student and solution process. Note that you will not see these variables in the student process of th

(state, **kwargs)

Source from the content-addressed store, hash-verified

254
255
256def set_env(state, **kwargs):
257 """Update/set environemnt variables for student and solution environments.
258
259 When ``has_equal_x()`` is used after this, the variables specified through this function will
260 be available in the student and solution process. Note that you will not see these variables
261 in the student process of the state produced by this function: the values are saved on the state
262 and are only added to the student and solution processes when ``has_equal_ast()`` is called.
263
264 :Example:
265
266 Student and Solution Code::
267
268 a = 1
269 if a > 4:
270 print('pretty large')
271
272 SCT::
273
274 # check if condition works with different values of a
275 Ex().check_if_else().check_test().multi(
276 set_env(a = 3).has_equal_value(),
277 set_env(a = 4).has_equal_value(),
278 set_env(a = 5).has_equal_value()
279 )
280
281 # equivalent SCT, by setting extra_env in has_equal_value()
282 Ex().check_if_else().check_test().\\
283 multi([has_equal_value(extra_env={'a': i}) for i in range(3, 6)])
284 """
285
286 stu_crnt = state.student_env.context
287 sol_crnt = state.solution_env.context
288
289 stu_new = stu_crnt.update(kwargs)
290 sol_new = sol_crnt.update(kwargs)
291
292 return state.to_child(
293 student_env=stu_new, solution_env=sol_new, highlight=state.highlight
294 )
295
296
297disable_highlighting.__doc__ = (

Callers 1

test_set_env_failFunction · 0.85

Calls 2

updateMethod · 0.80
to_childMethod · 0.80

Tested by 1

test_set_env_failFunction · 0.68