-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv_compare.py
80 lines (67 loc) · 2.75 KB
/
csv_compare.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
import csv
import json
#Json Validation
def is_json(myjson):
try:
json_object = json.loads(myjson)
except ValueError as e:
return False
return True
#CSV data
class csvdata():
def __init__(self, filename):
with open(filename, "r") as f_input:
csv_input = csv.reader(f_input)
self.details = list(csv_input)
def get_col_row(self, col, row):
return self.details[col][row]
expected = csvdata("expected.csv")
testcase = csvdata("testcase0.csv")
#p = expected.get_col_row(1,1)
#print "%s" % p
#json check
#print is_json(expected.get_col_row(7,1))
#a = expected.get_col_row(7,1)
#b = testcase.get_col_row(7,1)
#x = json.loads(a)
#y = json.loads(b)
#if x==y:
# print("True")
print("-------------------------------------------------------------------")
print("JSON Validation")
for i in range(8):
if is_json(expected.get_col_row(i,1)) == True and expected.get_col_row(i,1)[0] == '{':
print("For Expected: Json Data is Valid in " + str(i) + " , 1 ")
for j in range(8):
if is_json(testcase.get_col_row(j,1)) == True and testcase.get_col_row(j,1)[0] == '{':
print("For Testcase: Json Data is Valid in " + str(j) + " , 1 ")
count = 0
print("-------------------------------------------------------------------")
print("JSON Data Check")
for i in range(8):
for j in range(8):
if is_json(expected.get_col_row(i,1)) == True and is_json(testcase.get_col_row(j,1)) == True:
if expected.get_col_row(i,1)[0] == '{' and testcase.get_col_row(j,1)[0] == '{':
a = expected.get_col_row(i,1)
b = testcase.get_col_row(j,1)
x = json.loads(a)
y = json.loads(b)
if x==y:
print("For Expected: Json data is in " + str(i) + " , 1 ")
print("For Testcase: Json data is in " + str(j) + " , 1 ")
count = count + 1
if count > 0:
print("Json in both .csv files are true and has same value which is:")
for i in range(8):
if is_json(expected.get_col_row(i,1)) == True and expected.get_col_row(i,1)[0] == '{':
print(expected.get_col_row(i,1))
else:
print("Json data in both the files are not same.")
print("-------------------------------------------------------------------")
print("CSV Data Check")
for i in range(8):
for j in range(8):
if expected.get_col_row(i,0) == testcase.get_col_row(j,0):
if expected.get_col_row(i,1) == testcase.get_col_row(j,1):
print("Variable "+ expected.get_col_row(i,0) + " has same value which is " + expected.get_col_row(i,1) + " in both .csv files.")
#written by Girish aka '@gk2savage'