[NFC][Py Reformat] Reformat python files in llvm
[llvm-project.git] / llvm / utils / lit / tests / Inputs / xunit-output / dummy_format.py
blobefac0b561c44b339656824029f065b814bb4e4f7
1 import os
3 try:
4 import ConfigParser
5 except ImportError:
6 import configparser as ConfigParser
8 import lit.formats
9 import lit.Test
12 class DummyFormat(lit.formats.FileBasedTest):
13 def execute(self, test, lit_config):
14 # In this dummy format, expect that each test file is actually just a
15 # .ini format dump of the results to report.
17 source_path = test.getSourcePath()
19 cfg = ConfigParser.ConfigParser()
20 cfg.read(source_path)
22 # Create the basic test result.
23 result_code = cfg.get("global", "result_code")
24 result_output = cfg.get("global", "result_output")
25 result = lit.Test.Result(getattr(lit.Test, result_code), result_output)
27 if cfg.has_option("global", "required_feature"):
28 required_feature = cfg.get("global", "required_feature")
29 if required_feature:
30 test.requires.append(required_feature)
32 # Load additional metrics.
33 for key, value_str in cfg.items("results"):
34 value = eval(value_str)
35 if isinstance(value, int):
36 metric = lit.Test.IntMetricValue(value)
37 elif isinstance(value, float):
38 metric = lit.Test.RealMetricValue(value)
39 else:
40 raise RuntimeError("unsupported result type")
41 result.addMetric(key, metric)
43 return result