| 1 |
import os |
| 2 |
import configparser |
| 3 |
|
| 4 |
import lit.formats |
| 5 |
import lit.Test |
| 6 |
|
| 7 |
|
| 8 |
class DummyFormat(lit.formats.FileBasedTest): |
| 9 |
def execute(self, test, lit_config): |
| 10 |
# In this dummy format, expect that each test file is actually just a |
| 11 |
# .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 |
metric = lit.Test.toMetricValue(value) |
| 27 |
if isinstance(value, int): |
| 28 |
assert isinstance(metric, lit.Test.IntMetricValue) |
| 29 |
assert metric.format() == lit.Test.IntMetricValue(value).format() |
| 30 |
elif isinstance(value, float): |
| 31 |
assert isinstance(metric, lit.Test.RealMetricValue) |
| 32 |
assert metric.format() == lit.Test.RealMetricValue(value).format() |
| 33 |
elif isinstance(value, str): |
| 34 |
assert isinstance(metric, lit.Test.JSONMetricValue) |
| 35 |
assert metric.format() == lit.Test.JSONMetricValue(value).format() |
| 36 |
else: |
| 37 |
raise RuntimeError("unsupported result type") |
| 38 |
result.addMetric(key, metric) |
| 39 |
|
| 40 |
return result |