-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
43 lines (37 loc) · 1.1 KB
/
test.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
from csvparser import CsvParser
import csv
import os
def runTestCase():
testfiles = os.listdir("./testcase/")
print "Testing testcases : Total %d" % len(testfiles)
for filename in testfiles:
f = open("./testcase/" + filename, "rb")
plain = f.read()
f.seek(0)
lib_csv_reader = csv.reader(f)
parser = CsvParser()
lib_parsed_csv = [x for x in lib_csv_reader]
my_parsed_csv = parser.parse(plain)
f.close()
test_result = True
for rowi in range(len(lib_parsed_csv)):
row = lib_parsed_csv[rowi]
for coli in range(len(row)):
if my_parsed_csv[rowi][coli] != row[coli]:
test_result = False
break
print "%s : %s" % (filename, test_result)
def runErrorCase():
import subprocess
testfiles = os.listdir("./errorcase/")
print "Testing errorcases : Total %d" % len(testfiles)
for filename in testfiles:
return_code = subprocess.call(["python", "./main.py", "./errorcase/" + filename, "1"])
if return_code == 1:
print "%s : Pass" % (filename)
else:
print "%s : Failed" % (filename)
if __name__ == "__main__":
runTestCase()
print "----------------------------"
runErrorCase()