Skip to content

test: achieve 100% test coverage across all source modules - #10

Draft
RaymondSu-Public-Base with Copilot wants to merge 2 commits into
mainfrom
copilot/analyze-test-coverage
Draft

RaymondSu-Public-Base with Copilot wants to merge 2 commits into
mainfrom
copilot/analyze-test-coverage

Conversation

Copilot AI commented Sep 5, 2026

Copy link
Copy Markdown

Summary

Coverage was at 91% with several untested execution paths. This PR adds targeted tests for the __main__ guard blocks and the Windows exe-path branch in BuildExecutable.build(), bringing all source modules to 100%.

Related Issue

Type Of Change

  • feat: new feature
  • fix: bug fix
  • docs: documentation only
  • test: tests added or updated
  • chore: maintenance/refactor/build/ci updates

What Changed

  • tests/test_dunder_main.py (new): Exercises __main__.py via runpy.run_module("hello_python", run_name="__main__") with hello_python.main.main mocked — the only approach that registers coverage for the entry-point module.
  • tests/test_main.py: test_main_py_name_guard — runs main.py as __main__ via runpy.run_path, patching QtWidgets.QApplication at the module level so the if __name__ == "__main__": main() line is covered without spawning a real Qt app.
  • tests/test_build_class.py: test_build_windows_exe_path — triple-patches platform.system → "Windows" during build() to cover the .exe path branch (line 72); TestBuildExecutableDunderMain.test_build_dunder_main — patches shutil.which + subprocess.run globally before runpy.run_path so the __main__ guard executes cleanly.
  • tests/test_codestyle.py: TestCodeStyleDunderMain — two tests cover the format branch (sys.argv = ["codestyle.py"]) and check branch (sys.argv = ["codestyle.py", "check"]) of codestyle's __main__ guard.

How To Test

# Fast suite with coverage
PYTHONPATH=src QT_QPA_PLATFORM=offscreen pytest -m "not slow" --cov=hello_python --cov-report=term-missing -v

# Via Poetry
poetry run pytest -m "not slow" -v
poetry run python -m hello_python.codestyle check

Checklist

  • Pre-commit hooks pass (poetry run pre-commit run --all-files)
  • Lint passes (poetry run ruff check .)
  • Format passes (poetry run ruff format --check .)
  • Tests pass (poetry run pytest -m "not slow")
  • Build succeeds (poetry run python -m hello_python.build) (if applicable)
  • CI pipeline passes on this branch

Validation Evidence

Name                            Stmts   Miss  Cover   Missing
-------------------------------------------------------------
src/hello_python/__init__.py        2      0   100%
src/hello_python/__main__.py        3      0   100%
src/hello_python/build.py          43      0   100%
src/hello_python/codestyle.py      33      0   100%
src/hello_python/main.py           14      0   100%
src/hello_python/window.py         21      0   100%
-------------------------------------------------------------
TOTAL                             116      0   100%
===================================== 35 passed, 2 skipped, 3 deselected in 0.17s ======================================

UI/UX Changes (if applicable)

  • No UI changes
  • UI updated (attach screenshots)
  • Docs updated (README.md or docs/*)

Before/After screenshots or links:

  • Before:
  • After:

CI Checklist

  • Workflow changes reviewed (.github/workflows/*)
  • poetry.lock updated when dependencies changed
  • Headless test requirements handled (QT_QPA_PLATFORM=offscreen when needed)

Risk And Rollback

  • Risk level: Low — test-only changes, no production code modified.
  • Rollback plan: Revert this PR; no production behaviour changes.

Reviewer Checklist

  • Scope is clear and focused
  • Code/docs are understandable
  • Tests are sufficient for changed behavior
  • No obvious regressions

Copilot AI and others added 2 commits May 15, 2026 07:08
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>
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants