Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 0 Fork 324

arthur/Python

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (95)
master
delete-requirements.txt
pre-commit-ci-update-config
Python-3.14
uv-again
Sphinx-runs-on-ubuntu-24.04-arm
dependabot/github_actions/astral-sh/setup-uv-5
Shebang-python-for-Windows
gh-pages
Test-on-Python-3.13-beta
cclauss-patch-2
Keep-GitHub-Actions-up-to-date-with-Dependabot
Fewer-forward-propogations-to-speed-tests
cclauss-patch-1
Add-dataclasses-to-binary_search_tree.py
Simplify-is_bst.py
test-cov-gh-action
dhruv/remove
Remove-backslashes-from-is_palindrome.py
fuzzy_operations.py-on-Python-3.12
master
Branches (95)
master
delete-requirements.txt
pre-commit-ci-update-config
Python-3.14
uv-again
Sphinx-runs-on-ubuntu-24.04-arm
dependabot/github_actions/astral-sh/setup-uv-5
Shebang-python-for-Windows
gh-pages
Test-on-Python-3.13-beta
cclauss-patch-2
Keep-GitHub-Actions-up-to-date-with-Dependabot
Fewer-forward-propogations-to-speed-tests
cclauss-patch-1
Add-dataclasses-to-binary_search_tree.py
Simplify-is_bst.py
test-cov-gh-action
dhruv/remove
Remove-backslashes-from-is_palindrome.py
fuzzy_operations.py-on-Python-3.12
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (95)
master
delete-requirements.txt
pre-commit-ci-update-config
Python-3.14
uv-again
Sphinx-runs-on-ubuntu-24.04-arm
dependabot/github_actions/astral-sh/setup-uv-5
Shebang-python-for-Windows
gh-pages
Test-on-Python-3.13-beta
cclauss-patch-2
Keep-GitHub-Actions-up-to-date-with-Dependabot
Fewer-forward-propogations-to-speed-tests
cclauss-patch-1
Add-dataclasses-to-binary_search_tree.py
Simplify-is_bst.py
test-cov-gh-action
dhruv/remove
Remove-backslashes-from-is_palindrome.py
fuzzy_operations.py-on-Python-3.12
Python
/
scripts
/
validate_solutions.py
Python
/
scripts
/
validate_solutions.py
validate_solutions.py 3.54 KB
Copy Edit Raw Blame History
#!/usr/bin/env python3
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "httpx",
# "pytest",
# ]
# ///
import hashlib
import importlib.util
import json
import os
import pathlib
from types import ModuleType
import httpx
import pytest
PROJECT_EULER_DIR_PATH = pathlib.Path.cwd().joinpath("project_euler")
PROJECT_EULER_ANSWERS_PATH = pathlib.Path.cwd().joinpath(
"scripts", "project_euler_answers.json"
)
with open(PROJECT_EULER_ANSWERS_PATH) as file_handle:
PROBLEM_ANSWERS: dict[str, str] = json.load(file_handle)
def convert_path_to_module(file_path: pathlib.Path) -> ModuleType:
"""Converts a file path to a Python module"""
spec = importlib.util.spec_from_file_location(file_path.name, str(file_path))
module = importlib.util.module_from_spec(spec) # type: ignore[arg-type]
spec.loader.exec_module(module) # type: ignore[union-attr]
return module
def all_solution_file_paths() -> list[pathlib.Path]:
"""Collects all the solution file path in the Project Euler directory"""
solution_file_paths = []
for problem_dir_path in PROJECT_EULER_DIR_PATH.iterdir():
if problem_dir_path.is_file() or problem_dir_path.name.startswith("_"):
continue
for file_path in problem_dir_path.iterdir():
if file_path.suffix != ".py" or file_path.name.startswith(("_", "test")):
continue
solution_file_paths.append(file_path)
return solution_file_paths
def get_files_url() -> str:
"""Return the pull request number which triggered this action."""
with open(os.environ["GITHUB_EVENT_PATH"]) as file:
event = json.load(file)
return event["pull_request"]["url"] + "/files"
def added_solution_file_path() -> list[pathlib.Path]:
"""Collects only the solution file path which got added in the current
pull request.
This will only be triggered if the script is ran from GitHub Actions.
"""
solution_file_paths = []
headers = {
"Accept": "application/vnd.github.v3+json",
"Authorization": "token " + os.environ["GITHUB_TOKEN"],
}
files = httpx.get(get_files_url(), headers=headers, timeout=10).json()
for file in files:
filepath = pathlib.Path.cwd().joinpath(file["filename"])
if (
filepath.suffix != ".py"
or filepath.name.startswith(("_", "test"))
or not filepath.name.startswith("sol")
):
continue
solution_file_paths.append(filepath)
return solution_file_paths
def collect_solution_file_paths() -> list[pathlib.Path]:
# Return only if there are any, otherwise default to all solutions
if (
os.environ.get("CI")
and os.environ.get("GITHUB_EVENT_NAME") == "pull_request"
and (filepaths := added_solution_file_path())
):
return filepaths
return all_solution_file_paths()
@pytest.mark.parametrize(
"solution_path",
collect_solution_file_paths(),
ids=lambda path: f"{path.parent.name}/{path.name}",
)
def test_project_euler(solution_path: pathlib.Path) -> None:
"""Testing for all Project Euler solutions"""
# problem_[extract this part] and pad it with zeroes for width 3
problem_number: str = solution_path.parent.name[8:].zfill(3)
expected: str = PROBLEM_ANSWERS[problem_number]
solution_module = convert_path_to_module(solution_path)
answer = str(solution_module.solution())
answer = hashlib.sha256(answer.encode()).hexdigest()
assert answer == expected, (
f"Expected solution to {problem_number} to have hash {expected}, got {answer}"
)
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

Python 算法集
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/neckli/Python.git
git@gitee.com:neckli/Python.git
neckli
Python
Python
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /