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
55 lines (45 loc) · 1.33 KB
/
test_object.py
File metadata and controls
55 lines (45 loc) · 1.33 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
from pythonwhat.tasks import getColumnsInProcess
from pythonwhat.checks.check_object import check_object, check_df, check_keys
from pythonwhat.checks.has_funcs import has_equal_value
def test_object(
state,
name,
eq_condition="equal",
eq_fun=None,
do_eval=True,
undefined_msg=None,
incorrect_msg=None,
):
expand_msg = "" if undefined_msg or incorrect_msg else None
child = check_object(state, name, undefined_msg, expand_msg=expand_msg)
if do_eval:
has_equal_value(child, incorrect_msg)
def test_data_frame(
state,
name,
columns=None,
undefined_msg=None,
not_data_frame_msg=None,
undefined_cols_msg=None,
incorrect_msg=None,
):
"""Test a pandas dataframe.
"""
expand_msg = (
""
if undefined_msg or not_data_frame_msg or undefined_cols_msg or incorrect_msg
else None
)
child = check_df(
state,
name,
undefined_msg,
not_instance_msg=not_data_frame_msg,
expand_msg=expand_msg,
)
# if columns not set, figure them out from solution
if columns is None:
columns = getColumnsInProcess(name, child.solution_process)
for col in columns:
colstate = check_keys(child, col, missing_msg=undefined_cols_msg)
has_equal_value(colstate, incorrect_msg=incorrect_msg)