MCPcopy Create free account
hub / github.com/comaps/comaps / Parser

Class Parser

tools/python/testlog_to_xml_converter.py:108–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106
107
108class Parser:
109
110 def __init__(self, logfile, xml_file):
111 self.logfile = logfile
112 self.xml_file = xml_file
113 self.current_exe = None
114 self.test_info = TestInfo()
115 self.var_should_pass = False
116 self.root = ElementTree.Element("testsuite")
117
118
119 def write_xml_file(self):
120 ElementTree.ElementTree(self.root).write(self.xml_file, encoding="UTF-8")
121
122
123 def parse_log_file(self):
124 with open(self.logfile) as f:
125
126 PipeEach(f.readlines()).through_functions(
127 self.check_for_exe_boundaries,
128 self.check_for_testcase_boundaries,
129 self.check_test_result,
130 self.should_pass,
131 self.append_to_comment
132 )
133
134
135 def should_pass(self, line):
136 return self.var_should_pass
137
138
139 def check_for_exe_boundaries(self, line):
140 if line.startswith(PrefixesInLog.BEGIN):
141 if self.current_exe: #if we never had an End to a Beginning
142 self.test_info = TestInfo()
143 self.append_to_xml()
144 self.var_should_pass = False
145
146 self.current_exe = string_after_prefix(line, PrefixesInLog.BEGIN)
147 return True
148
149 elif line.startswith(PrefixesInLog.END):
150 self.var_should_pass = False
151 parts = line.split(" | ")
152 end_exe = string_after_prefix(parts[0], PrefixesInLog.END)
153 result = int(string_after_prefix(parts[1], PrefixesInLog.RESULT))
154
155 if result != 0:
156 if not self.test_info:
157 self.test_info = TestInfo()
158 self.test_info.set_exe_name(end_exe)
159 self.test_info.set_name("SOME_TESTS_FAILED")
160 self.test_info.set_test_result(TestInfo.FAILED)
161
162 self.append_to_xml()
163
164 self.current_exe = None
165 return True

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by 1

mainFunction · 0.68