Skip to content

Commit e70e404

Browse files
committed
refactor: replace hand-rolled yaml parser with PyYAML
1 parent f480d60 commit e70e404

File tree

2 files changed

+17
-46
lines changed

2 files changed

+17
-46
lines changed

.github/actions/test_compat_fuse/action.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ runs:
1010

1111
- name: Test compatibility
1212
shell: bash
13-
run: python3 ./tests/compat_fuse/test_compat_fuse.py --run-all
13+
run: |
14+
pip install pyyaml -q
15+
python3 ./tests/compat_fuse/test_compat_fuse.py --run-all
1416
- name: Upload failure
1517
if: failure()
1618
uses: ./.github/actions/artifact_failure

tests/compat_fuse/test_compat_fuse.py

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import argparse
99
import os
1010
import platform
11-
import re
1211
import shutil
1312
import socket
1413
import subprocess
@@ -18,52 +17,22 @@
1817
import urllib.request
1918
from pathlib import Path
2019

20+
import yaml
2121

22-
def load_test_cases(path: Path) -> list[dict]:
23-
"""Parse the minimal yaml subset used by test_cases.yaml.
2422

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"])
6736
return cases
6837

6938

0 commit comments

Comments
 (0)