|
8 | 8 | import argparse |
9 | 9 | import os |
10 | 10 | import platform |
11 | | -import re |
12 | 11 | import shutil |
13 | 12 | import socket |
14 | 13 | import subprocess |
|
18 | 17 | import urllib.request |
19 | 18 | from pathlib import Path |
20 | 19 |
|
| 20 | +import yaml |
21 | 21 |
|
22 | | -def load_test_cases(path: Path) -> list[dict]: |
23 | | - """Parse the minimal yaml subset used by test_cases.yaml. |
24 | 22 |
|
25 | | - Handles lines of the form: |
26 | | - - { key: val, key: "val", key: [v1, v2, v3] } |
27 | | - Skips blank lines and # comments. |
28 | | - """ |
29 | | - cases = [] |
30 | | - for line in path.read_text().splitlines(): |
31 | | - line = line.strip() |
32 | | - if not line or line.startswith("#"): |
33 | | - continue |
34 | | - # Strip leading "- {" and trailing "}" |
35 | | - m = re.match(r"^-\s*\{(.+)\}\s*$", line) |
36 | | - if not m: |
37 | | - raise ValueError(f"Cannot parse line: {line}") |
38 | | - body = m.group(1) |
39 | | - entry = {} |
40 | | - # Split on commas followed by a key name, but only outside brackets |
41 | | - pairs = [] |
42 | | - depth = 0 |
43 | | - current = [] |
44 | | - for ch in body + ",": |
45 | | - if ch == "[": |
46 | | - depth += 1 |
47 | | - elif ch == "]": |
48 | | - depth -= 1 |
49 | | - if ch == "," and depth == 0: |
50 | | - pairs.append("".join(current).strip()) |
51 | | - current = [] |
52 | | - else: |
53 | | - current.append(ch) |
54 | | - for pair in pairs: |
55 | | - if not pair: |
56 | | - continue |
57 | | - k, v = pair.split(":", 1) |
58 | | - k = k.strip() |
59 | | - v = v.strip() |
60 | | - if v.startswith("["): |
61 | | - # list value: [a, b, c] |
62 | | - inner = v.strip("[] ") |
63 | | - entry[k] = [x.strip().strip('"') for x in inner.split(",")] |
64 | | - else: |
65 | | - entry[k] = v.strip('"') |
66 | | - cases.append(entry) |
| 23 | +def load_test_cases(path: Path) -> list[dict]: |
| 24 | + """Load test cases from a YAML file.""" |
| 25 | + with open(path) as f: |
| 26 | + cases = yaml.safe_load(f) |
| 27 | + # Ensure all values in meta lists are strings (yaml may parse "1.2.527" as float) |
| 28 | + for case in cases: |
| 29 | + case["meta"] = [str(v) for v in case["meta"]] |
| 30 | + if "writer" in case: |
| 31 | + case["writer"] = str(case["writer"]) |
| 32 | + if "reader" in case: |
| 33 | + case["reader"] = str(case["reader"]) |
| 34 | + if "suite" in case: |
| 35 | + case["suite"] = str(case["suite"]) |
67 | 36 | return cases |
68 | 37 |
|
69 | 38 |
|
|
0 commit comments