-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_check_funcs.py
More file actions
147 lines (128 loc) · 3.91 KB
/
test_check_funcs.py
File metadata and controls
147 lines (128 loc) · 3.91 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import pytest
from protowhat.failure import TestFail as TF
from tests.helper import (
prepare_state,
passes,
check_row,
check_column,
check_all_columns,
check_result,
lowercase,
has_equal_value,
)
@pytest.mark.parametrize(
"stu, stu_sub, success",
[
({}, None, False),
({"a": [1]}, None, False),
({"a": [1, 2]}, {"a": [2]}, True),
({"b": [1, 2]}, {"b": [2]}, True),
({"a": [1, 2], "b": [3, 4]}, {"a": [2], "b": [4]}, True),
({"a": [1, 2, 3], "b": [4, 5, 6]}, {"a": [2], "b": [5]}, True),
],
)
def test_check_row(stu, stu_sub, success):
state = prepare_state({"a": [1, 2, 3], "b": [4, 5, 6]}, stu)
if success:
x = check_row(state, 1)
passes(x)
assert x.solution_result == {"a": [2], "b": [5]}
assert x.student_result == stu_sub
else:
with pytest.raises(TF):
check_row(state, 1)
def test_check_row_wrong_usage():
state = prepare_state({"a": [1]}, {"a": [1]})
with pytest.raises(BaseException):
check_row(state, 1)
@pytest.mark.parametrize(
"stu, stu_sub, success",
[
({}, None, False),
({"b": []}, None, False),
({"A": [1]}, None, False),
({"a": []}, {"a": []}, True),
({"a": [1]}, {"a": [1]}, True),
({"a": [1], "b": [2]}, {"a": [1]}, True),
],
)
def test_check_column(stu, stu_sub, success):
state = prepare_state({"a": [1]}, stu)
if success:
x = check_column(state, "a")
passes(x)
assert x.solution_result == {"a": [1]}
assert x.student_result == stu_sub
else:
with pytest.raises(TF):
check_column(state, "a")
def test_check_column_wrong_usage():
state = prepare_state({"a": [1]}, {"a": [1]})
with pytest.raises(BaseException):
check_column(state, "b")
@pytest.mark.parametrize(
"stu, stu_sub, success",
[
({}, None, False),
({"a": [1]}, None, False),
({"A": [1], "b": [2]}, None, False),
({"a": [1], "b": [2]}, {"a": [1], "b": [2]}, True),
({"a": [4], "b": [5]}, {"a": [4], "b": [5]}, True),
({"a": [1], "b": [2], "c": [3]}, {"a": [1], "b": [2]}, True),
],
)
def test_check_all_columns(stu, stu_sub, success):
state = prepare_state({"a": [1], "b": [2]}, stu)
if success:
x = check_all_columns(state)
passes(x)
assert x.solution_result == {"a": [1], "b": [2]}
assert x.student_result == stu_sub
else:
with pytest.raises(TF):
check_all_columns(state)
@pytest.mark.parametrize(
"stu, success",
[
({"a": [1], "b": [2]}, True),
({"a": [4], "b": [5]}, True),
({"A": [1], "b": [2]}, False),
],
)
def test_check_all_columns_stricter(stu, success):
state = prepare_state({"a": [1], "b": [2]}, stu)
if success:
passes(check_all_columns(state, allow_extra=False))
else:
with pytest.raises(TF):
check_all_columns(state, allow_extra=False)
def test_lower_case():
state = prepare_state({"a": [1]}, {"A": [1]})
# fails if not using lowercase
with pytest.raises(TF):
check_column(state, "a")
# passes if lowercase is being used
child = lowercase(state)
child2 = check_column(child, "a")
passes(child2)
passes(has_equal_value(child2))
@pytest.mark.parametrize(
"stu, success",
[
({"a": [1]}, False),
({"a": [1, 1]}, False),
({"a": [1, 2]}, False),
({"a": [1, 2], "b": [5, 6]}, False),
({"a": [1, 2, 3], "b": [3, 4, 5]}, False),
({"a": [1, 2], "b": [3, 4]}, True),
({"a": [1, 2], "B": [3, 4]}, True),
({"a": [1, 2], "b": [3, 4], "c": [5, 6]}, True),
],
)
def test_check_result(stu, success):
state = prepare_state({"a": [1, 2], "b": [3, 4]}, stu)
if success:
passes(check_result(state))
else:
with pytest.raises(TF):
check_result(state)