50 lines · python
1import os2import configparser3 4import lit.formats5import lit.Test6 7 8class DummyFormat(lit.formats.FileBasedTest):9 def execute(self, test, lit_config):10 # In this dummy format, expect that each test file is actually just a11 # .ini format dump of the results to report.12 13 source_path = test.getSourcePath()14 15 cfg = configparser.ConfigParser()16 cfg.read(source_path)17 18 # Create the basic test result.19 result_code = cfg.get("global", "result_code")20 result_output = cfg.get("global", "result_output")21 result = lit.Test.Result(getattr(lit.Test, result_code), result_output)22 23 # Load additional metrics.24 for key, value_str in cfg.items("results"):25 value = eval(value_str)26 if isinstance(value, int):27 metric = lit.Test.IntMetricValue(value)28 elif isinstance(value, float):29 metric = lit.Test.RealMetricValue(value)30 else:31 raise RuntimeError("unsupported result type")32 result.addMetric(key, metric)33 34 # Create micro test results35 for key, micro_name in cfg.items("micro-tests"):36 micro_result = lit.Test.Result(getattr(lit.Test, result_code, ""))37 # Load micro test additional metrics38 for key, value_str in cfg.items("micro-results"):39 value = eval(value_str)40 if isinstance(value, int):41 metric = lit.Test.IntMetricValue(value)42 elif isinstance(value, float):43 metric = lit.Test.RealMetricValue(value)44 else:45 raise RuntimeError("unsupported result type")46 micro_result.addMetric(key, metric)47 result.addMicroResult(micro_name, micro_result)48 49 return result50