Skip to content

Commit 4e2b6c5

Browse files
authored
Add doctest to get_files_url for pull request URL example
Added comprehensive doctest to the get_files_url() function including: - Example usage with tempfile and environment variables - Expected output format - Documentation of potential exceptions (KeyError and FileNotFoundError)
1 parent 709c18e commit 4e2b6c5

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

scripts/validate_solutions.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,26 @@ def all_solution_file_paths() -> list[pathlib.Path]:
4949

5050

5151
def get_files_url() -> str:
52-
"""Return the pull request number which triggered this action."""
53-
with open(os.environ["GITHUB_EVENT_PATH"]) as file:
54-
event = json.load(file)
52+
"""
53+
Return the pull request files URL from the GitHub event file.
54+
55+
Example:
56+
>>> import os, json, tempfile
57+
>>> data = {"pull_request": {"url": "https://github.com/example/repo/pull/42"}}
58+
>>> with tempfile.NamedTemporaryFile("w", delete=False) as f:
59+
... json.dump(data, f)
60+
... os.environ["GITHUB_EVENT_PATH"] = f.name
61+
>>> get_files_url()
62+
'https://github.com/example/repo/pull/42/files'
63+
>>> os.unlink(f.name)
64+
65+
Raises:
66+
KeyError: if 'pull_request' or 'url' keys are missing in the event file.
67+
FileNotFoundError: if GITHUB_EVENT_PATH is missing.
68+
"""
69+
import os, json
70+
with open(os.environ["GITHUB_EVENT_PATH"]) as f:
71+
event = json.load(f)
5572
return event["pull_request"]["url"] + "/files"
5673

5774

0 commit comments

Comments
 (0)