Skip to content

Commit 35b196f

Browse files
committed
Fix broken uppercase capture group test
Important: Python regex flags such as multiline need to be specified in the compiled regex and not afterwards.
1 parent 0cb018a commit 35b196f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

tests/test_capture_group_case.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
# https://github.com/google/textfsm/wiki/TextFSM#value-definitions
1111
OPTION_KEYWORDS = ["Filldown", "Key", "Required", "List", "Fillup"]
12-
RE_CAPGRP = re.compile(rf"^Value\s+(?:(?:(?:{'|'.join(OPTION_KEYWORDS)}),?)+\s+)?(\S+)") # noqa: E231
12+
RE_CAPGRP = re.compile(rf"^Value\s+(?:(?:(?:{'|'.join(OPTION_KEYWORDS)}),?)+\s+)?(\S+)", re.MULTILINE) # noqa: E231
1313

1414

1515
def return_template_files():
@@ -27,12 +27,15 @@ def return_template_capture_groups(template_file):
2727
"""Return a list of capture groups in a template."""
2828
with open(template_file, encoding="utf-8") as fh:
2929
file = fh.read()
30-
return RE_CAPGRP.findall(file, re.MULTILINE)
30+
return RE_CAPGRP.findall(file)
3131

3232

3333
def test_uppercase_capture_group(load_template_files):
3434
"""Test that the capture groups are uppercase."""
3535
capture_groups = return_template_capture_groups(load_template_files)
3636

37+
# catch non-functional regexes and re function syntax which match nothing
38+
assert capture_groups != [], 'No capture groups were matched, check regex function syntax/usage'
39+
3740
for group in capture_groups:
3841
assert group.isupper()

0 commit comments

Comments
 (0)