forked from nogibjj/sqlite-lab
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_main.py
159 lines (144 loc) · 4.06 KB
/
test_main.py
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
148
149
150
151
152
153
154
155
156
157
158
159
"""
Test Script for Main Code and Lib Files.
The main file calls the libs files hence no separate test file for libs.
"""
import subprocess
import os
def test_main():
# log file check
# check if log file already exists
# delete Data file
if os.path.exists("./Data/Master.csv"):
os.remove("./Data/Master.csv")
# check creation of Data file
result = subprocess.run(
[
"python",
"main.py",
"create_data",
"https://github.com/Opensourcefordatascience/Data-sets/raw/master/automotive_data.csv",
"./Data/Master.csv",
"F",
],
capture_output=True,
text=True,
check=True,
)
assert "processed" in result.stdout
assert os.path.exists("./Data/Master.csv")
# check creation of DB file
result = subprocess.run(
["python", "main.py", "create", "Master.db", "./Data/Master.csv", "F"],
capture_output=True,
text=True,
check=True,
)
assert "created" in result.stdout
assert os.path.exists("./Master.db")
# check read from DB file
result = subprocess.run(
[
"python",
"main.py",
"read",
"Master.db",
"Master",
"SELECT * FROM Master LIMIT 1",
],
capture_output=True,
text=True,
check=True,
)
assert "(1, '3', '?', 'alfa-romero'" in result.stdout
# check update from DB file
result = subprocess.run(
[
"python",
"main.py",
"update",
"Master.db",
"Master",
"UPDATE Master SET make = 'alfa_romero' WHERE make = 'alfa-romero'",
],
capture_output=True,
text=True,
check=True,
)
result = subprocess.run(
[
"python",
"main.py",
"read",
"Master.db",
"Master",
"SELECT * FROM Master LIMIT 1",
],
capture_output=True,
text=True,
check=True,
)
assert "(1, '3', '?', 'alfa_romero'" in result.stdout
# check delete from DB file
result = subprocess.run(
[
"python",
"main.py",
"delete",
"Master.db",
"Master",
"DELETE FROM Master WHERE make = 'alfa_romero'",
],
capture_output=True,
text=True,
check=True,
)
result = subprocess.run(
["python", "main.py", "read", "Master.db", "Master", "SELECT * FROM Master"],
capture_output=True,
text=True,
check=True,
)
assert "alfa_romero" not in result.stdout
print("manual Checks complete")
print("checking auto generation")
# checking autocase of files
subprocess.run(["python", "main.py", "delete_data"])
subprocess.run(["python", "main.py", "create_data"])
subprocess.run(["python", "main.py", "create"])
subprocess.run(["python", "main.py", "read"])
subprocess.run(["python", "main.py", "update"])
subprocess.run(["python", "main.py", "delete"])
# assert output after expected auto generation
result = subprocess.run(
[
"python",
"main.py",
"read",
"Master.db",
"Master",
"SELECT * FROM Master LIMIT 1",
],
capture_output=True,
text=True,
check=True,
)
assert "(2, '3', 'Unknown', 'alfa-romero'" in result.stdout
assert "(1, '3', 'Unknown', 'alfa-romero'" not in result.stdout
# testing error messages
result = subprocess.run(
["python", "main.py", "read", "Master.db", "Master", "testing error"],
capture_output=True,
text=True,
check=True,
)
assert "Invalid Query" in result.stdout
result = subprocess.run(
["python", "main.py", "read", "Master.db", "Master", "READ testing error"],
capture_output=True,
text=True,
check=True,
)
assert "Invalid Query" in result.stdout
if __name__ == "__main__":
test_main()
pass