-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmonkey-to-junit.py
More file actions
executable file
·61 lines (44 loc) · 1.69 KB
/
Copy pathmonkey-to-junit.py
File metadata and controls
executable file
·61 lines (44 loc) · 1.69 KB
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
#!/usr/bin/env python
import re
import sys
from junit_xml import TestSuite, TestCase
class MonkeyParser:
def __init__(self, file):
self.monkey_log = file
self.event_count = 0
self.failure_msg = ""
self.is_success = False
self.parse(self.monkey_log)
def parse(self, file):
with open(file, 'r') as f:
for line in f:
# parse event count
match = re.match('^Events injected\:\s', line)
if(match):
self.event_count = line[match.end():]
# parse failure message
match = re.search('System appears to have crashed at event', line)
if(match):
self.failure_msg = line.rstrip()
# parse test status
match = re.search('Monkey finished', line)
if(match):
self.is_success = True
def show(self):
measurement_data = "<measurement><name>Events</name><value>%s</value></measurement>" % (self.event_count)
monkey_test = TestCase('monkey', stdout=measurement_data)
# handle failure msg
if(self.is_success is False):
monkey_test.add_failure_info(self.failure_msg)
ts = TestSuite("com.skysoft.kkbox.android", [monkey_test])
# pretty printing is on by default but can be disabled using prettyprint=False
junit_data = TestSuite.to_xml_string([ts])
print(junit_data)
def main():
if len(sys.argv) > 1:
monkey_log = sys.argv[1]
MonkeyParser(monkey_log).show()
else:
print 'usage: $ python ' + sys.argv[0] + ' monkey.log'
if __name__ == '__main__':
main()