-
Notifications
You must be signed in to change notification settings - Fork 5
/
tests.py
208 lines (151 loc) Β· 6.16 KB
/
tests.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import unittest
from coderunner import coderunner
from coderunner.coderunner import InvalidURL, ValueTooLargeError
# # test for Java program
# class TestRunA(unittest.TestCase):
# def test_run(self):
# source_code = "testfiles/" + "test_java.java"
# language = "Java"
# output = "testfiles/output/" + "output.txt"
# r = coderunner.code(source_code, language, output)
# r.api(key=API_KEY)
# r.run()
# self.assertEqual(r.getStatus(), "Accepted", "Something Wrong")
# # test for Java program with input
# class TestRunB(unittest.TestCase):
# def test_run(self):
# source_code = "testfiles/" + "test_java_input.java"
# language = "Java"
# output = "testfiles/output/" + "output5.txt"
# Input = "testfiles/input/" + "input4.txt"
# r = coderunner.code(source_code, language, output, Input)
# r.api(key=API_KEY)
# r.run()
# self.assertEqual(r.getStatus(), "Accepted", "Something Wrong")
# # test for Python3 program
# class TestRunC(unittest.TestCase):
# def test_run(self):
# source_code = "testfiles/" + "test_python.py"
# language = "Python3"
# output = "testfiles/output/" + "output6.txt"
# r = coderunner.code(source_code, language, output)
# r.api(key=API_KEY)
# r.run()
# self.assertEqual(r.getStatus(), "Accepted", "Something Wrong")
# # test for Python3 program with input
# class TestRunD(unittest.TestCase):
# def test_run(self):
# source_code = "testfiles/" + "test_python_input.py"
# language = "Python3"
# output = "testfiles/output/" + "output2.txt"
# Input = "testfiles/input/" + "input.txt"
# r = coderunner.code(source_code, language, output, Input)
# r.api(key=API_KEY)
# r.run()
# self.assertEqual(r.getStatus(), "Accepted", "Something Wrong")
# # test for C program
# class TestRunE(unittest.TestCase):
# def test_run(self):
# source_code = "testfiles/" + "test_c.c"
# language = "C"
# output = "testfiles/output/" + "output7.txt"
# r = coderunner.code(source_code, language, output)
# r.api(key=API_KEY)
# r.run()
# self.assertEqual(r.getStatus(), "Accepted", "Something Wrong")
# # test for C program with input
# class TestRunF(unittest.TestCase):
# def test_run(self):
# source_code = "testfiles/" + "test_c_input.c"
# language = "C"
# output = "testfiles/output/" + "output3.txt"
# Input = "testfiles/input/" + "input2.txt"
# r = coderunner.code(source_code, language, output, Input)
# r.api(key=API_KEY)
# r.run()
# self.assertEqual(r.getStatus(), "Accepted", "Something Wrong")
# # test for C++ program
# class TestRunG(unittest.TestCase):
# def test_run(self):
# source_code = "testfiles/" + "test_c++.cpp"
# language = "C++"
# output = "testfiles/output/" + "output8.txt"
# r = coderunner.code(source_code, language, output)
# r.api(key=API_KEY)
# r.run()
# self.assertEqual(r.getStatus(), "Accepted", "Something Wrong")
# # test for C++ program with input
# class TestRunH(unittest.TestCase):
# def test_run(self):
# source_code = "testfiles/" + "test_c++_input.cpp"
# language = "C++"
# output = "testfiles/output/" + "output4.txt"
# Input = "testfiles/input/" + "input3.txt"
# r = coderunner.code(source_code, language, output, Input)
# r.api(key=API_KEY)
# r.run()
# self.assertEqual(r.getStatus(), "Accepted", "Something Wrong")
# test to check ValueError exception
class TestRunI(unittest.TestCase):
def test_run(self):
with self.assertRaises(ValueError):
coderunner.code("Hello World", "fgbh", "Hello World", path=False)
# test to check OSError exception
class TestRunJ(unittest.TestCase):
def test_run(self):
with self.assertRaises(OSError):
coderunner.code("Hello World", "C++", "Hello World")
# test to check OSError exception
class TestRunK(unittest.TestCase):
def test_run(self):
with self.assertRaises(OSError):
coderunner.code("testfiles/" + "test_c++.cpp", "C++", "Hello World")
# test to check OSError exception
class TestRunL(unittest.TestCase):
def test_run(self):
with self.assertRaises(OSError):
coderunner.code(
"testfiles/" + "test_c++.cpp",
"C++",
"testfiles/output/" + "output4.txt",
"my_input",
)
# test to check Wrong Answer Status
# class TestRunM(unittest.TestCase):
# def test_run(self):
# source_code = 'print("This will return Wrong Answer")'
# language = "Python3"
# output = "Wrong Answer"
# r = coderunner.code(source_code, language, output, path=False)
# r.api(key=API_KEY)
# r.run()
# self.assertEqual(r.getStatus(), "Wrong Answer", "Something Wrong")
# test to check invalid API url
class TestRunO(unittest.TestCase):
def test_run(self):
source_code = 'print("This will return Wrong Answer")'
language = "Python3"
output = "Wrong Answer"
r = coderunner.code(source_code, language, output, path=False)
with self.assertRaises(InvalidURL):
r.api(key="ABCHE", url="ghthth")
# test to check ValueTooLargeError for Flags
class TestRunP(unittest.TestCase):
def test_run(self):
source_code = 'print("This will return Wrong Answer")'
language = "Python3"
output = "Wrong Answer"
r = coderunner.code(source_code, language, output, path=False)
with self.assertRaises(ValueTooLargeError):
r.setFlags("qw"*70)
# test to check ValueTooLargeError for Arguments
class TestRunQ(unittest.TestCase):
def test_run(self):
source_code = 'print("This will return Wrong Answer")'
language = "Python3"
output = "Wrong Answer"
r = coderunner.code(source_code, language, output, path=False)
with self.assertRaises(ValueTooLargeError):
r.setArguments("qw"*70)
if __name__ == "__main__":
unittest.main()