+
+
+def write_exceptions_map_to_file(testname, filename, mode="a+"):
+ """
+ Write the exceptions map to a file under the testname header. The output
+ will include all lines in the exception itself as well as any previous
+ contextual warning or error lines. The output will be appended or overwritten
+ depending on the mode parameter. It is assumed that the caller has called
+ verify_exceptions() earlier to populate the exceptions map, otherwise only
+ the testname and header will be printed to the file.
+
+ :param str testname: The name of the test
+ :param str filename: The file to open for writing
+ :param str mode: Append (a+) or overwrite (w+)
+ """
+ try:
+ os.makedirs(os.path.dirname(filename))
+ except OSError as exception:
+ if exception.errno != errno.EEXIST:
+ raise
+
+ with open(filename, mode) as fp:
+ fp.write("{}\n".format("=" * 60))
+ fp.write("Starting test: {}\n".format(testname))
+ for ex_idx, ex in _ex_map.items():
+ fp.write("{}\n".format("-" * 40))
+ if "issue" in ex:
+ fp.write("Exception was matched to: {}\n".format(ex.get("issue")))
+ else:
+ fp.write("Exception is new\n")
+ for exwe_index in ex.get("warnerr_list")[:-1]:
+ for line in _ts_list[exwe_index]:
+ fp.write("{}\n".format(line))
+ fp.writelines(ex.get("lines"))
+ fp.write("\n")