Skip to content

Commit f4d791d

Browse files
committed
Format and fix tests
1 parent e31155c commit f4d791d

2 files changed

Lines changed: 27 additions & 29 deletions

File tree

ops/__tests__/test_parse_sdk_branch.py

100644100755
Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env python3
22

3-
import sys
43
import os
4+
import sys
5+
56
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
67

78
from parse_sdk_branch import parse_sdk_branch
@@ -14,9 +15,9 @@ def test_parse_sdk_branch():
1415
("TESTING_SDK_BRANCH: feature/test", "feature/test"),
1516
("TESTING_SDK_BRANCH=feature/test", "feature/test"),
1617
("testing_sdk_branch: feature/test", "feature/test"),
17-
1818
# Complex PR body with backticks and contractions
19-
("""Updated the script to safely parse the testing SDK branch from the PR body, handling case insensitivity and whitespace.
19+
(
20+
"""Updated the script to safely parse the testing SDK branch from the PR body, handling case insensitivity and whitespace.
2021
2122
The goal here is to fix the usage of backticks such as in `foo`, and contractions that we've been using such as `we've`
2223
@@ -26,11 +27,13 @@ def test_parse_sdk_branch():
2627
2728
TESTING_SDK_BRANCH = main
2829
29-
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.""", "main"),
30-
30+
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.""",
31+
"main",
32+
),
3133
# Edge cases with markdown and special characters
32-
("""# PR Title
33-
34+
(
35+
"""# PR Title
36+
3437
Some `code` and we've got contractions here.
3538
3639
```python
@@ -40,41 +43,39 @@ def test():
4043
4144
TESTING_SDK_BRANCH: feature/fix-backticks
4245
43-
More text with `inline code` and don't forget contractions.""", "feature/fix-backticks"),
44-
46+
More text with `inline code` and don't forget contractions.""",
47+
"feature/fix-backticks",
48+
),
4549
# Multiple occurrences (should take first)
46-
("""TESTING_SDK_BRANCH = first-branch
47-
50+
(
51+
"""TESTING_SDK_BRANCH = first-branch
52+
4853
Some text here.
4954
50-
TESTING_SDK_BRANCH = second-branch""", "first-branch"),
51-
55+
TESTING_SDK_BRANCH = second-branch""",
56+
"first-branch",
57+
),
5258
# Whitespace variations
5359
(" TESTING_SDK_BRANCH = feature/spaces ", "feature/spaces"),
5460
("TESTING_SDK_BRANCH:feature/no-space", "feature/no-space"),
55-
5661
# Default cases
5762
("No branch specified", "main"),
5863
("", "main"),
5964
("Just some random text", "main"),
60-
6165
# Case with backticks in branch name
6266
("TESTING_SDK_BRANCH = feature/fix-`backticks`", "feature/fix-`backticks`"),
63-
6467
# Case with contractions in surrounding text
65-
("We've updated this and TESTING_SDK_BRANCH = feature/test and we're done", "feature/test"),
68+
(
69+
"We've updated this and TESTING_SDK_BRANCH = feature/test and we're done",
70+
"feature/test",
71+
),
6672
]
67-
68-
for i, (input_text, expected) in enumerate(test_cases):
73+
74+
for input_text, expected in test_cases:
6975
result = parse_sdk_branch(input_text)
7076
if result != expected:
71-
print(f"FAIL Test {i+1}: Expected '{expected}', got '{result}'")
72-
print(f"Input: {repr(input_text[:100])}...")
7377
return False
74-
else:
75-
print(f"PASS Test {i+1}: {expected}")
76-
77-
print(f"\nAll {len(test_cases)} tests passed!")
78+
7879
return True
7980

8081

ops/parse_sdk_branch.py

100644100755
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
import re
55

66

7-
87
def parse_sdk_branch(pr_body: str, default_ref: str = "main") -> str:
98
"""Parse PR body for TESTING_SDK_BRANCH and return the branch reference."""
10-
pattern = re.compile(r"(?i)TESTING_SDK_BRANCH\s*[:=]\s*(.+)$", re.MULTILINE)
9+
pattern = re.compile(r"(?i)TESTING_SDK_BRANCH\s*[:=]\s*(\S+)", re.MULTILINE)
1110

1211
match = pattern.search(pr_body)
1312
if match:
@@ -27,8 +26,6 @@ def main():
2726
with open(github_output, "a", encoding="utf-8") as f:
2827
f.write(f"testing_ref={ref}\n")
2928

30-
print(f"Using testing SDK branch: {ref}")
31-
3229

3330
if __name__ == "__main__":
3431
main()

0 commit comments

Comments
 (0)