MCPcopy Create free account
hub / github.com/apache/impala / parse_test_file_text

Function parse_test_file_text

tests/util/test_file_parser.py:200–311  ·  view source on GitHub ↗
(text, valid_section_names, skip_unknown_sections=True)

Source from the content-addressed store, hash-verified

198
199
200def parse_test_file_text(text, valid_section_names, skip_unknown_sections=True):
201 sections = list()
202 section_start_regex = re.compile(r'(?m)^%s' % SECTION_DELIMITER)
203 match = section_start_regex.search(text)
204 if match is not None:
205 # Assume anything before the first section (==== tag) is a header and ignore it. To
206 # ensure that test will not be skipped unintentionally we reject headers that start
207 # with what looks like a subsection.
208 header = text[:match.start()]
209 if re.match(r'^%s' % SUBSECTION_DELIMITER, header):
210 raise RuntimeError(dedent("""
211 Header must not start with '%s'. Everything before the first line matching '%s'
212 is considered header information and will be ignored. However a header must not
213 start with '%s' to prevent test cases from accidentally being ignored.""" %
214 (SUBSECTION_DELIMITER, SECTION_DELIMITER, SUBSECTION_DELIMITER)))
215 text = text[match.start():]
216
217 # Split the test file up into sections. For each section, parse all subsections.
218 for section in section_start_regex.split(text):
219 parsed_sections = collections.defaultdict(str)
220 for sub_section in re.split(r'(?m)^%s' % SUBSECTION_DELIMITER, section[1:]):
221 # Skip empty subsections
222 if not sub_section.strip():
223 continue
224
225 lines = sub_section.split('\n')
226 subsection_name = lines[0].strip()
227 subsection_comment = None
228
229 subsection_info = [s.strip() for s in subsection_name.split(':')]
230 if len(subsection_info) == 2:
231 subsection_name, subsection_comment = subsection_info
232 if subsection_comment == "":
233 # ignore empty subsection_comment
234 subsection_comment = None
235
236 lines_content = lines[1:-1]
237
238 subsection_str = '\n'.join([line for line in lines_content])
239 if len(lines_content) != 0:
240 # Add trailing newline to last line if present. This disambiguates between the
241 # case of no lines versus a single line with no text.
242 # This extra newline is needed only for the verification of the subsections of
243 # RESULTS, DML_RESULTS and ERRORS and will be removed in write_test_file()
244 # when '--update_results' is added to output the updated golden file.
245 subsection_str += "\n"
246
247 if subsection_name not in valid_section_names:
248 if skip_unknown_sections or not subsection_name:
249 print(sub_section)
250 print('Unknown section \'%s\'' % subsection_name)
251 continue
252 else:
253 raise RuntimeError('Unknown subsection: %s' % subsection_name)
254
255 if subsection_name == 'QUERY' and subsection_comment:
256 parsed_sections['QUERY_NAME'] = subsection_comment
257

Callers 5

test_valid_parseMethod · 0.90
test_invalid_sectionMethod · 0.90
test_parse_query_nameMethod · 0.90
parse_test_fileFunction · 0.85

Calls 7

RuntimeErrorFunction · 0.85
matchMethod · 0.80
startMethod · 0.65
searchMethod · 0.45
joinMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected