Files
scheduler/backend/test_runtime_overrides.py
T

62 lines
2.0 KiB
Python
Raw Normal View History

from __future__ import annotations
import csv
from pathlib import Path
import sys
from tempfile import TemporaryDirectory
import unittest
sys.path.append(str(Path(__file__).resolve().parent))
from db import DEVICE_DUT, DEVICE_REF
from parser import P2P_COE_REQUIRED_COLUMNS, parse_target_csv
def _write_p2p_csv(directory: str, test_id: str = "P2PRXAX001") -> Path:
path = Path(directory) / "runtime-overrides.csv"
row = {column: "" for column in P2P_COE_REQUIRED_COLUMNS}
row["Priority"] = "1"
row["Index"] = "1"
row["TC ID"] = test_id
with path.open("w", encoding="utf-8", newline="") as handle:
writer = csv.DictWriter(handle, fieldnames=P2P_COE_REQUIRED_COLUMNS)
writer.writeheader()
writer.writerow(row)
return path
class RuntimeOverridesParseTests(unittest.TestCase):
def test_parse_target_csv_applies_device_specific_runtime_overrides(self) -> None:
with TemporaryDirectory() as tmpdir:
csv_path = _write_p2p_csv(tmpdir)
parsed = parse_target_csv(
csv_path,
runtime_overrides={
DEVICE_DUT: {"P2P": 91},
DEVICE_REF: {"P2P": 123},
},
)
by_device = {record.device: record for record in parsed.tests}
self.assertEqual(by_device[DEVICE_DUT].estimated_minutes, 91)
self.assertEqual(by_device[DEVICE_REF].estimated_minutes, 123)
def test_parse_target_csv_keeps_legacy_runtime_override_for_both_devices(self) -> None:
with TemporaryDirectory() as tmpdir:
csv_path = _write_p2p_csv(tmpdir)
parsed = parse_target_csv(
csv_path,
runtime_overrides={"P2P": 88},
)
by_device = {record.device: record for record in parsed.tests}
self.assertEqual(by_device[DEVICE_DUT].estimated_minutes, 88)
self.assertEqual(by_device[DEVICE_REF].estimated_minutes, 88)
if __name__ == "__main__":
unittest.main()