From d909bee211a1a7d0d6b7b77fcb3840b870b41efc Mon Sep 17 00:00:00 2001 From: A5rocks Date: Thu, 15 May 2025 08:17:41 +0900 Subject: [PATCH 1/2] Add a missing test case and make coverage ignore scripts --- pyproject.toml | 3 ++- src/trio/_tests/tools/test_sync_requirements.py | 1 + src/trio/_tools/sync_requirements.py | 10 ++-------- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ba2c4387d6..d7076de7bf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -332,7 +332,8 @@ exclude_also = [ 'class .*\bProtocol\b.*\):', "raise NotImplementedError", '.*if "sphinx" in sys.modules:', - 'TODO: test this line' + 'TODO: test this line', + 'if __name__ == "__main__":', ] partial_branches = [ "pragma: no branch", diff --git a/src/trio/_tests/tools/test_sync_requirements.py b/src/trio/_tests/tools/test_sync_requirements.py index 83ae21be65..db64d36eaa 100644 --- a/src/trio/_tests/tools/test_sync_requirements.py +++ b/src/trio/_tests/tools/test_sync_requirements.py @@ -27,6 +27,7 @@ def test_yield_pre_commit_version_data() -> None: rev: v0.11.0 - repo: https://github.com/psf/black-pre-commit-mirror rev: 25.1.0 + - bad: data """ results = tuple(yield_pre_commit_version_data(text)) assert results == ( diff --git a/src/trio/_tools/sync_requirements.py b/src/trio/_tools/sync_requirements.py index f4ca481faf..43337e29dc 100755 --- a/src/trio/_tools/sync_requirements.py +++ b/src/trio/_tools/sync_requirements.py @@ -78,9 +78,7 @@ def update_requirements( return changed -def main() -> int: - """Run program.""" - +if __name__ == "__main__": source_root = Path.cwd().absolute() # Double-check we found the right directory @@ -97,8 +95,4 @@ def main() -> int: for name, version in yield_pre_commit_version_data(pre_commit_text) } changed = update_requirements(test_requirements, pre_commit_versions) - return int(changed) - - -if __name__ == "__main__": - sys.exit(main()) + sys.exit(int(changed)) From b29f2701f715a753c4f08eba64735a9ce6eb89cd Mon Sep 17 00:00:00 2001 From: A5rocks Date: Thu, 15 May 2025 09:40:25 -0400 Subject: [PATCH 2/2] Remove now unnecessary pragmas --- src/trio/_tools/gen_exports.py | 2 +- src/trio/_tools/mypy_annotate.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/trio/_tools/gen_exports.py b/src/trio/_tools/gen_exports.py index 5b1affe24a..101e0e4912 100755 --- a/src/trio/_tools/gen_exports.py +++ b/src/trio/_tools/gen_exports.py @@ -399,5 +399,5 @@ def main() -> None: # pragma: no cover """ -if __name__ == "__main__": # pragma: no cover +if __name__ == "__main__": main() diff --git a/src/trio/_tools/mypy_annotate.py b/src/trio/_tools/mypy_annotate.py index 5acb9b993c..1d625ad7ae 100644 --- a/src/trio/_tools/mypy_annotate.py +++ b/src/trio/_tools/mypy_annotate.py @@ -122,5 +122,5 @@ def main(argv: list[str]) -> None: pickle.dump(results, f) -if __name__ == "__main__": # pragma: no cover +if __name__ == "__main__": main(sys.argv[1:])