forked from dodoyoon/CTG-Randoop-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandoop2json.py
76 lines (55 loc) · 1.65 KB
/
randoop2json.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
import json, copy, sys
from json2html import *
filename = sys.argv[1]
inf = open(filename, "r")
file = inf.readlines()
final_dict = {}
l_cnt = 0
last_elem_cnt = 0
descriptions=[]
one_description={}
result_dict={}
loc_list=[]
is_exception = False
exception_list = []
for line in file:
if line == '\n' or not line :
continue
line = line.strip()
if line.split(' ', 1)[0] == 'at':
one_description['exception'] = copy.deepcopy(exception_list)
is_exception = False
if line[0].isdigit() and 'test' in line:
if loc_list:
one_description['location'] = loc_list
descriptions.append(copy.deepcopy(one_description))
loc_list.clear()
one_description.clear()
exception_list.clear()
one_description['id'] = line
else:
one_description['id'] = line
is_exception = True
# exception
elif is_exception:
exception_list.append(copy.deepcopy(line))
# location
elif line.split(' ', 1)[0] == 'at':
loc_list.append(copy.deepcopy(line))
# results
elif line[0] == 'F':
result_dict['word'] = line
if last_elem_cnt == 0:
one_description['location'] = loc_list
descriptions.append(copy.deepcopy(one_description))
last_elem_cnt = last_elem_cnt + 1
elif line.split(' ', 1)[0] == 'Tests':
result_dict['result'] = line
else:
continue
final_dict['descriptions'] = descriptions
final_dict['summary'] = result_dict
out_file_name = filename + '.json'
out_file = open(out_file_name, "w")
json.dump(final_dict, out_file, indent=4)
out_file.close()