forked from datacamp/pythonwhat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_v2_only.py
More file actions
61 lines (53 loc) · 1.75 KB
/
Copy pathtest_v2_only.py
File metadata and controls
61 lines (53 loc) · 1.75 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
import pytest
import tests.helper as helper
import importlib
def relooooad():
import pythonwhat.sct_syntax
importlib.reload(pythonwhat.sct_syntax)
@pytest.fixture
def data():
return {"DC_CODE": "x = round(4)", "DC_SOLUTION": "x = round(5)"}
@pytest.mark.parametrize(
"sct",
[
"test_object('x')",
"Ex().test_object('x')",
"test_function('round')",
"Ex().check_object('x').has_equal_value()",
"Ex() >> check_object('x').has_equal_value()",
"x = check_object('x').has_equal_value(); Ex() >> x",
],
)
def test_without_env_all_works(data, sct):
data["DC_SCT"] = sct
with helper.set_v2_only_env(""):
relooooad()
sct_payload = helper.run(data)
assert not sct_payload["correct"]
@pytest.mark.parametrize(
"sct, should_err",
[
("test_object('x')", True),
("test_function('round')", True),
("Ex().test_object('x')", True),
("Ex().test_or(check_object('x').has_equal_value())", True),
("Ex().check_or(test_object('x'))", True),
("Ex().check_object('x').has_equal_value()", False),
("Ex() >> check_object('x').has_equal_value()", False),
(
"Ex().check_or(check_object('x').has_equal_value(), check_object('x').has_equal_value())",
False,
),
("x = check_object('x').has_equal_value(); Ex() >> x", False),
],
)
def test_with_env_old_fail(data, sct, should_err):
data["DC_SCT"] = sct
with helper.set_v2_only_env("1"):
relooooad()
if should_err:
with pytest.raises((NameError, AttributeError)):
sct_payload = helper.run(data)
else:
sct_payload = helper.run(data)
assert not sct_payload["correct"]