The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
ctest_measurements_reporter Namespace Reference

Functions

 sanitize_for_xml (data)
 
 pytest_report_header (config, start_path, startdir)
 
 pytest_runtest_logreport (report)
 
 pytest_sessionfinish (session, exitstatus)
 

Variables

dict results = {}
 

Function Documentation

◆ pytest_report_header()

ctest_measurements_reporter.pytest_report_header ( config,
start_path,
startdir )

Definition at line 38 of file ctest_measurements_reporter.py.

38def pytest_report_header(config, start_path, startdir):
39 # make sure CTest does not drop output lines on successful tests
40 return "CTEST_FULL_OUTPUT"
41
42

◆ pytest_runtest_logreport()

ctest_measurements_reporter.pytest_runtest_logreport ( report)

Definition at line 43 of file ctest_measurements_reporter.py.

43def pytest_runtest_logreport(report):
44 # collect user properties
45 head_line = report.head_line
46 results.update(
47 {
48 f"{head_line}.{k}": v
49 for k, v in report.user_properties
50 if f"{head_line}.{k}" not in results
51 }
52 )
53
54 # collect test outcome
55 if not report.passed:
56 results[f"{report.head_line}.outcome"] = report.outcome
57 else:
58 results.setdefault(f"{report.head_line}.outcome", "passed")
59
60 # collect test duration
61 if report.when == "call":
62 results[f"{report.head_line}.duration"] = round(report.duration, 2)
63
64

◆ pytest_sessionfinish()

ctest_measurements_reporter.pytest_sessionfinish ( session,
exitstatus )

Definition at line 65 of file ctest_measurements_reporter.py.

65def pytest_sessionfinish(session, exitstatus):
66 if not hasattr(session, "items"):
67 # no test run, nothing to report
68 return
69 if os.environ.get("DISABLE_CTEST_MEASUREMENTS") == "1":
70 # user requested to disable CTest measurements printouts
71 return
72
73 outcomes = defaultdict(list)
74 for key in results:
75 if key.endswith(".outcome"):
76 outcomes[results[key]].append(key[:-8])
77 results.update(
78 (f"outcome.{outcome}", sorted(tests)) for outcome, tests in outcomes.items()
79 )
80
81 ignore_keys = {"test_fixture_setup.completed_process"}
82 template = (
83 '<DartMeasurement type="text/string" name="{name}">{value}</DartMeasurement>'
84 )
85
86 to_print = [
87 (key, value)
88 for key, value in results.items()
89 if not any(key.endswith(ignore_key) for ignore_key in ignore_keys) and value
90 ]
91 to_print.sort()
92 for key, value in to_print:
93 sanitized_value = XSS.escape(sanitize_for_xml(str(value)))
94 # workaround for a limitation of CTestXML2HTML
95 key = key.replace("/", "_")
96 print(template.format(name=key, value=sanitized_value), end="")

◆ sanitize_for_xml()

ctest_measurements_reporter.sanitize_for_xml ( data)

Definition at line 28 of file ctest_measurements_reporter.py.

28def sanitize_for_xml(data):
29 bad_chars = re.compile("[\x00-\x08\x0b\x0c\x0e-\x1f\ud800-\udfff\ufffe\uffff]")
30
31 def quote(match):
32 "helper function"
33 return "".join("[NON-XML-CHAR-0x%2X]" % ord(c) for c in match.group())
34
35 return bad_chars.sub(quote, data)
36
37

Variable Documentation

◆ results

dict ctest_measurements_reporter.results = {}

Definition at line 25 of file ctest_measurements_reporter.py.