Skip to content

Commit 4e845d5

Browse files
authored
tests: Support dashes in test suite names (#4740)
- actually support dashes in integration names in `tox.ini`/toxgen - make `split_tox_gh_actions.py` actually fail if it fails to parse `tox.ini` Context: `split_tox_gh_actions.py` was actually failing because it assumed there can't be dashes in test suite names, but since it was just printing the error instead of actually exiting with an error code, we didn't notice this in CI.
1 parent a6e3b50 commit 4e845d5

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

scripts/split_tox_gh_actions/split_tox_gh_actions.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import configparser
1919
import hashlib
20+
import re
2021
import sys
2122
from collections import defaultdict
2223
from functools import reduce
@@ -25,6 +26,18 @@
2526

2627
from jinja2 import Environment, FileSystemLoader
2728

29+
TOXENV_REGEX = re.compile(
30+
r"""
31+
{?(?P<py_versions>(py\d+\.\d+,?)+)}?
32+
-(?P<framework>[a-z](?:[a-z_]|-(?!v{?\d|latest))*[a-z0-9])
33+
(?:-(
34+
(v{?(?P<framework_versions>[0-9.]+[0-9a-z,.]*}?))
35+
|
36+
(?P<framework_versions_latest>latest)
37+
))?
38+
""",
39+
re.VERBOSE,
40+
)
2841

2942
OUT_DIR = Path(__file__).resolve().parent.parent.parent / ".github" / "workflows"
3043
TOX_FILE = Path(__file__).resolve().parent.parent.parent / "tox.ini"
@@ -202,29 +215,37 @@ def parse_tox():
202215
py_versions_pinned = defaultdict(set)
203216
py_versions_latest = defaultdict(set)
204217

218+
parsed_correctly = True
219+
205220
for line in lines:
206221
# normalize lines
207222
line = line.strip().lower()
208223

209224
try:
210225
# parse tox environment definition
211-
try:
212-
(raw_python_versions, framework, framework_versions) = line.split("-")
213-
except ValueError:
214-
(raw_python_versions, framework) = line.split("-")
215-
framework_versions = []
226+
parsed = TOXENV_REGEX.match(line)
227+
if not parsed:
228+
print(f"ERROR reading line {line}")
229+
raise ValueError("Failed to parse tox environment definition")
230+
231+
groups = parsed.groupdict()
232+
raw_python_versions = groups["py_versions"]
233+
framework = groups["framework"]
234+
framework_versions_latest = groups.get("framework_versions_latest") or False
216235

217236
# collect python versions to test the framework in
218-
raw_python_versions = set(
219-
raw_python_versions.replace("{", "").replace("}", "").split(",")
220-
)
221-
if "latest" in framework_versions:
237+
raw_python_versions = set(raw_python_versions.split(","))
238+
if framework_versions_latest:
222239
py_versions_latest[framework] |= raw_python_versions
223240
else:
224241
py_versions_pinned[framework] |= raw_python_versions
225242

226-
except ValueError:
243+
except Exception:
227244
print(f"ERROR reading line {line}")
245+
parsed_correctly = False
246+
247+
if not parsed_correctly:
248+
raise RuntimeError("Failed to parse tox.ini")
228249

229250
py_versions_pinned = _normalize_py_versions(py_versions_pinned)
230251
py_versions_latest = _normalize_py_versions(py_versions_latest)

0 commit comments

Comments
 (0)