forked from datacamp/pythonwhat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_object.py
More file actions
59 lines (42 loc) · 1.84 KB
/
Copy pathtest_object.py
File metadata and controls
59 lines (42 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from pythonwhat.Reporter import Reporter
from pythonwhat.check_funcs import part_to_child, has_equal_value
from pythonwhat.check_object import check_object, MSG_UNDEFINED
MSG_UNDEFINED = "FMT:Have you defined `{index}`?"
MSG_INCORRECT = "FMT:The contents of `{parent[index]}` aren't correct."
def test_object(name,
eq_condition="equal",
eq_fun=None,
do_eval=True,
undefined_msg=None,
incorrect_msg=None,
state=None):
"""Test object.
The value of an object in the ending environment is compared in the student's environment and the
solution environment.
Args:
name (str): the name of the object which value has to be checked.
eq_condition (str): how objects are compared. Currently, only "equal" is supported,
meaning that the object in student and solution process should have exactly the same value.
do_eval (bool): if False, the object will only be checked for existence. Defaults to True.
undefined_msg (str): feedback message when the object is not defined
incorrect_msg (str): feedback message if the value of the object in the solution environment doesn't match
the one in the student environment.
:Example:
Student code::
a = 1
b = 5
Solution code::
a = 1
b = 2
SCT::
test_object("a") # pass
test_object("b") # fail
Note that the student code below would fail both tests::
a = 1
b = 2
a = 3 # incorrect final value of a
"""
rep = Reporter.active_reporter
child = check_object(name, undefined_msg or MSG_UNDEFINED, expand_msg = "", state=state)
if do_eval:
has_equal_value(incorrect_msg or MSG_INCORRECT, state=child)