From a3b88b54b4f4b2e4efb63db4e6822fba524a179f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 15 May 2026 07:08:12 +0000 Subject: [PATCH 1/2] chore: plan test coverage improvements Agent-Logs-Url: https://github.com/RaymondSu-Public-Base/Vibe-helloworld-python/sessions/e39aead5-89bc-4e34-8686-10324f3134e5 Co-authored-by: RaymondSu-Public-Base <29174601+RaymondSu-Public-Base@users.noreply.github.com> --- .coverage | Bin 0 -> 53248 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .coverage diff --git a/.coverage b/.coverage new file mode 100644 index 0000000000000000000000000000000000000000..1ce1281c866cd47cf9ce52ed8184d3f68eebf589 GIT binary patch literal 53248 zcmeI)$!{A~90%|j&)AL=I}<3Cl}05`NGMI4r4bdYN*f?5h)ShUDh{-hvHcPcwP(_q zah3yAE|m)Z1A;%IH=sA}960sFa)7E5R7muIf>eILS-hli)k?0~MBkB@S>Ai|-sf!| zPvQ?wpR@xhmRzrH1>yx|L{U}cxDbk>5zMNc;9UF}%!wVG3AR=+G5XO(>B zBgHsh*k?@Vm-BxQeU*PX_u-J8oyyJ70W1)J00bbgYXq97^V#C)sCxO+z$(>b;8|tq zMX!Z7-(Q$NvmnmQzj1OwMEk^nK|#y(w3rv3yCznoCzkA*6t+{b%T{1J%Oa@CBy_`< z6`r$bAI(}Ea3+k;Yo=YHSb~IKiAdWsM zJh>!2>6E1(<>G){nH-$_{L)~yxMz=gRfc7#^wj=VXDRP)+r%^8v`6rF~3Re!rh)x{1y<+x?8@O>{ zAGmI|smpeGyQ(uG=NgS-H5~h5L$)e^O0;86g~f2(DZz!H7V!K~rufPpRiRcX*Zqq% z`sid@jld1JO{#ozj$ZOto*Kv&$H&#H7sH0aJZ8xb{MJgYtI@P}_h>qNym!0dUeeu2 zxEIxG!d(ix496Bx@%|ohUIZb6K))ka{5?X8)ugCAWAj2)ZNy?7UN6mAT$;v z!Im0MnY)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1b4b6beb014c71dcdd03c69 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 15 May 2026 07:10:35 +0000 Subject: [PATCH 2/2] test: add comprehensive tests to achieve 100% coverage Agent-Logs-Url: https://github.com/RaymondSu-Public-Base/Vibe-helloworld-python/sessions/e39aead5-89bc-4e34-8686-10324f3134e5 Co-authored-by: RaymondSu-Public-Base <29174601+RaymondSu-Public-Base@users.noreply.github.com> --- .coverage | Bin 53248 -> 53248 bytes tests/test_build_class.py | 37 +++++++++++++++++++++++++++++++++++++ tests/test_codestyle.py | 29 +++++++++++++++++++++++++++++ tests/test_dunder_main.py | 17 +++++++++++++++++ tests/test_main.py | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 120 insertions(+) create mode 100644 tests/test_dunder_main.py diff --git a/.coverage b/.coverage index 1ce1281c866cd47cf9ce52ed8184d3f68eebf589..08b2420600b88843e3316449c7a4cf2be1f47b60 100644 GIT binary patch delta 164 zcmZozz}&Eac>_y>02}{q2L7M?ANlX|U*JE+zk9Qwz;gabPBs=sP7zkE_rJ|JSb?zq=3n#K3;@_< BEC>Jq delta 146 zcmZozz}&Eac>_xWA1nV62L7M?&-riipXWcaSx{gTzaJ+n3nQlptJeG9W*jU)rVx|X zW`7=LAWMqn)#k5udv|dPFadc=%&%_#-uwRY|Npy97+D!vI63*WxEL51So!ZW@c-t2 m#{Y%?E&qL>nP>T>*?{U9Sy{mp6APGPVFpvon}5w`GXMZ)9ww&% diff --git a/tests/test_build_class.py b/tests/test_build_class.py index 2408147..7d7d9bb 100644 --- a/tests/test_build_class.py +++ b/tests/test_build_class.py @@ -3,6 +3,8 @@ from __future__ import annotations import platform +import runpy +import shutil as shutil_module import subprocess from pathlib import Path from unittest.mock import patch @@ -147,6 +149,41 @@ def test_build_failure_raises( with pytest.raises(RuntimeError, match="Build failed with exit code 1"): builder.build() + @patch("hello_python.build.subprocess.run") + @patch("hello_python.build.shutil.which", return_value="/usr/bin/poetry") + @patch("hello_python.build.platform.system", return_value="Windows") + def test_build_windows_exe_path( + self, + _mock_sys: object, + _mock_which: object, + mock_run: object, + tmp_path: Path, + ) -> None: + mock_run.return_value = subprocess.CompletedProcess(args=[], returncode=0) + + builder = BuildExecutable(root_dir=tmp_path) + result = builder.build() + + assert result.name == "hello-python-windows.exe" + assert result == builder.dist_path / "hello-python-windows.exe" + + +class TestBuildExecutableDunderMain: + """Test the ``if __name__ == '__main__'`` guard in build.py.""" + + def test_build_dunder_main(self, monkeypatch: pytest.MonkeyPatch) -> None: + """Running build.py as __main__ creates a BuildExecutable and calls build.""" + monkeypatch.setattr(shutil_module, "which", lambda x: "/usr/bin/poetry") + monkeypatch.setattr( + subprocess, + "run", + lambda *a, **kw: subprocess.CompletedProcess(args=[], returncode=0), + ) + + runpy.run_path( + str(ROOT_DIR / "src" / "hello_python" / "build.py"), run_name="__main__" + ) + @pytest.mark.slow class TestBuildExecutableIntegration: diff --git a/tests/test_codestyle.py b/tests/test_codestyle.py index b854406..566160b 100644 --- a/tests/test_codestyle.py +++ b/tests/test_codestyle.py @@ -2,7 +2,10 @@ from __future__ import annotations +import runpy +import shutil as shutil_module import subprocess +import sys from pathlib import Path from unittest.mock import call, patch @@ -138,3 +141,29 @@ def test_check_raises_on_failure( style = CodeStyle(root_dir=tmp_path) with pytest.raises(subprocess.CalledProcessError): style.check() + + +class TestCodeStyleDunderMain: + """Test the ``if __name__ == '__main__'`` guard in codestyle.py.""" + + def _run_script(self, monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setattr(shutil_module, "which", lambda x: "/usr/bin/poetry") + monkeypatch.setattr( + subprocess, + "run", + lambda *a, **kw: subprocess.CompletedProcess(args=[], returncode=0), + ) + runpy.run_path( + str(ROOT_DIR / "src" / "hello_python" / "codestyle.py"), + run_name="__main__", + ) + + def test_dunder_main_format_mode(self, monkeypatch: pytest.MonkeyPatch) -> None: + """No 'check' argument → format() branch is executed.""" + monkeypatch.setattr(sys, "argv", ["codestyle.py"]) + self._run_script(monkeypatch) # Should complete without error + + def test_dunder_main_check_mode(self, monkeypatch: pytest.MonkeyPatch) -> None: + """'check' argument → check() branch is executed.""" + monkeypatch.setattr(sys, "argv", ["codestyle.py", "check"]) + self._run_script(monkeypatch) # Should complete without error diff --git a/tests/test_dunder_main.py b/tests/test_dunder_main.py new file mode 100644 index 0000000..cfa72b4 --- /dev/null +++ b/tests/test_dunder_main.py @@ -0,0 +1,17 @@ +"""Tests for hello_python/__main__.py entry point.""" + +from __future__ import annotations + +import runpy + +import pytest + + +def test_dunder_main_calls_main(monkeypatch: pytest.MonkeyPatch) -> None: + """Cover ``__main__.py``: importing main and calling it when run as __main__.""" + called: list[bool] = [] + monkeypatch.setattr("hello_python.main.main", lambda: called.append(True)) + + runpy.run_module("hello_python", run_name="__main__", alter_sys=False) + + assert called == [True] diff --git a/tests/test_main.py b/tests/test_main.py index 784c6ee..62fd3b8 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,10 +1,16 @@ +import runpy +from pathlib import Path + import pytest +from PyQt5 import QtWidgets from PyQt5.QtWidgets import QApplication import hello_python.main as main_module from hello_python.main import get_hello_message from hello_python.window import HelloWindow +ROOT_DIR = Path(__file__).resolve().parent.parent + def test_get_hello_message() -> None: assert get_hello_message() == "Hello, world!" @@ -72,3 +78,34 @@ def show(self) -> None: assert captured["resize"] == (320, 120) assert captured["show_called"] is True assert captured["exec_called"] is True + + +def test_main_py_name_guard(monkeypatch: pytest.MonkeyPatch) -> None: + """Cover the ``if __name__ == '__main__': main()`` guard in main.py.""" + executed: list[str] = [] + + class FakeApp: + def __init__(self, args: list[str]) -> None: + pass + + def exec(self) -> None: + executed.append("exec") + + class FakeWindow: + def __init__(self) -> None: + pass + + def resize(self, width: int, height: int) -> None: + pass + + def show(self) -> None: + pass + + monkeypatch.setattr(QtWidgets, "QApplication", FakeApp) + monkeypatch.setattr("hello_python.window.HelloWindow", FakeWindow) + + runpy.run_path( + str(ROOT_DIR / "src" / "hello_python" / "main.py"), run_name="__main__" + ) + + assert "exec" in executed