-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_state.py
More file actions
96 lines (78 loc) · 2.5 KB
/
Copy pathtest_state.py
File metadata and controls
96 lines (78 loc) · 2.5 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
from unittest.mock import MagicMock
from sqlwhat.sct_syntax import Ex
from sqlwhat.State import State
from protowhat.Reporter import Reporter
from protowhat.Test import TestFail as TF
from tests.helper import Connection
import pytest
@pytest.fixture(params=["postgresql", "mssql"])
def conn(request):
return Connection(request.param)
def test_pass(conn):
state = State(
student_code="SELECT * FROM company",
solution_code="SELECT * FROM company",
pre_exercise_code="",
student_result={"id": [1], "name": ["greg"]},
solution_result={"id": [1], "name": ["greg"]},
student_conn=conn,
solution_conn=None,
reporter=Reporter(),
)
Ex.root_state = state
assert Ex().check_result()
def test_fail(conn):
state = State(
student_code="SELECT * FROM company",
solution_code="SELECT * FROM company",
pre_exercise_code="",
student_result={"id": [1], "name": ["greg"]},
solution_result={"id": [0], "name": ["greg"]},
student_conn=conn,
solution_conn=None,
reporter=Reporter(),
)
Ex.root_state = state
with pytest.raises(TF):
Ex().check_result()
def test_multiple_state_init(conn):
state1 = State(
student_code="SELECT * FROM company",
solution_code="SELECT * FROM company",
pre_exercise_code="",
student_result={"id": [1], "name": ["greg"]},
solution_result={"id": [0], "name": ["greg"]},
student_conn=conn,
solution_conn=None,
reporter=Reporter(),
)
state2 = State(
student_code="SELECT * FROM company",
solution_code="SELECT * FROM company",
pre_exercise_code="",
student_result={"id": [1], "name": ["greg"]},
solution_result={"id": [0], "name": ["greg"]},
student_conn=conn,
solution_conn=None,
reporter=Reporter(),
)
def test_get_dispatcher_oracle():
# Given
conn2 = MagicMock()
dialect = MagicMock()
conn2.dialect = dialect
dialect.name = "oracle"
state = State(
student_code="SELECT * FROM company",
solution_code="SELECT * FROM company",
pre_exercise_code="",
student_result={"id": [1], "name": ["greg"]},
solution_result={"id": [1], "name": ["greg"]},
student_conn=conn2,
solution_conn=None,
reporter=Reporter(),
)
# When
output = state.get_dispatcher()
# Then
assert output.ast_mod.grammar.__spec__.name == 'antlr_plsql.antlr_py'