LLVM now requires Python >= 3.8, and ConfigParser was renamed to configparser in 3.0: https://docs.python.org/3/whatsnew/3.0.html#library-changes A few places imported it under the Python2 name even for Python3, I have swapped those to the Python3 name. This was reported by https://pypi.org/project/vermin/ as the file having incompatible versions. Since once import is 2.x and one is 3.x.
41 lines
1.5 KiB
Python
41 lines
1.5 KiB
Python
import os
|
|
import configparser
|
|
|
|
import lit.formats
|
|
import lit.Test
|
|
|
|
|
|
class DummyFormat(lit.formats.FileBasedTest):
|
|
def execute(self, test, lit_config):
|
|
# In this dummy format, expect that each test file is actually just a
|
|
# .ini format dump of the results to report.
|
|
|
|
source_path = test.getSourcePath()
|
|
|
|
cfg = configparser.ConfigParser()
|
|
cfg.read(source_path)
|
|
|
|
# Create the basic test result.
|
|
result_code = cfg.get("global", "result_code")
|
|
result_output = cfg.get("global", "result_output")
|
|
result = lit.Test.Result(getattr(lit.Test, result_code), result_output)
|
|
|
|
# Load additional metrics.
|
|
for key, value_str in cfg.items("results"):
|
|
value = eval(value_str)
|
|
metric = lit.Test.toMetricValue(value)
|
|
if isinstance(value, int):
|
|
assert isinstance(metric, lit.Test.IntMetricValue)
|
|
assert metric.format() == lit.Test.IntMetricValue(value).format()
|
|
elif isinstance(value, float):
|
|
assert isinstance(metric, lit.Test.RealMetricValue)
|
|
assert metric.format() == lit.Test.RealMetricValue(value).format()
|
|
elif isinstance(value, str):
|
|
assert isinstance(metric, lit.Test.JSONMetricValue)
|
|
assert metric.format() == lit.Test.JSONMetricValue(value).format()
|
|
else:
|
|
raise RuntimeError("unsupported result type")
|
|
result.addMetric(key, metric)
|
|
|
|
return result
|