/
Comparator.py
70 lines (59 loc) · 1.72 KB
/
Comparator.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
#coding: utf-8
import CONSTS
from Parser import Parser
class Comparator:
p1 = None
p2 = None
methods1 = None
methods2 = None
same_method = None
def __init__(self, orig, dev):
self.p1 = Parser(orig)
self.p2 = Parser(dev)
self.methods1 = []
self.methods2 = []
self.same_method = []
def __del__(self):
pass
def compare(self):
self.methods1 = self.p1.find_methods()
self.methods2 = self.p2.find_methods()
def dump_method_name(self):
print "print original methods name below"
for method in self.methods1:
print "\t" + method['name']
print "print develop methods name below"
for method in self.methods2:
print "\t" + method['name']
def dump_method_content(self):
print "print original methods content below"
for method in self.methods1:
print "\t" + method['content']
print "print develop methods content below"
for method in self.methods2:
print "\t" + method['content']
def pick_same_method_name(self):
self.same_method = []
for orig_method in self.methods1:
dev_same_method = [item for item in self.methods2 if item['name'] == orig_method['name']]
if 0 < len(dev_same_method):
self.same_method.append(orig_method['name'])
return self.same_method
def get_modified_method(self):
self.pick_same_method_name()
modified = []
for method_name in self.same_method:
o = [item for item in self.methods1 if item['name'] == method_name][0]
d = [item for item in self.methods2 if item['name'] == method_name][0]
if o['content'] != d['content']:
modified.append(o['name'])
return modified
if __name__ == '__main__':
c = Comparator(
CONSTS.TESTFILE1,
CONSTS.TESTFILE2
)
c.compare()
c.dump_method_name()
#c.dump_method_content()
#c.pick_same_method_name()