Repository navigation
test(phase4): TUI coverage + restore 85% gate #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| """ | ||
| Deep TUI tests for MaximizerApp via Textual's headless run_test(). | ||
|
|
||
| These exercise the real widget tree (compose, input, button handler, | ||
| solver integration) so tui/app.py coverage moves from a surface-level | ||
| import check to the actual interactive logic. | ||
| """ | ||
|
|
||
| import asyncio | ||
|
|
||
| import pytest | ||
|
|
||
| from package_maximizer.tui.app import MaximizerApp | ||
|
|
||
|
|
||
| def _run_app(packages: str, solver: str = "greedy"): | ||
| """Mount the app, set inputs, press Run, return rendered result text.""" | ||
|
|
||
| async def _drive(): | ||
| app = MaximizerApp() | ||
| async with app.run_test() as pilot: | ||
| await pilot.pause() | ||
| inp = app.query_one("#packages") | ||
| inp.value = packages | ||
| sel = app.query_one("#solver") | ||
| sel.value = solver | ||
| await pilot.pause() | ||
| btn = app.query_one("#run") | ||
| btn.press() | ||
| await pilot.pause() | ||
| result = app.query_one("#result_text") | ||
| return str(result.render()) | ||
|
|
||
| return asyncio.run(_drive()) | ||
|
|
||
|
|
||
| def test_app_compose_widgets_present(): | ||
| """compose() builds the expected widget tree.""" | ||
| app = MaximizerApp() | ||
| async_context = None | ||
|
|
||
| async def _check(): | ||
| nonlocal async_context | ||
| async with app.run_test() as pilot: | ||
| await pilot.pause() | ||
| assert app.query_one("#packages") is not None | ||
| assert app.query_one("#solver") is not None | ||
| assert app.query_one("#run") is not None | ||
| assert app.query_one("#result_text") is not None | ||
| assert app.query_one("#log_output") is not None | ||
| async_context = "ok" | ||
|
|
||
| asyncio.run(_check()) | ||
| assert async_context == "ok" | ||
|
|
||
|
|
||
| def test_button_run_with_packages(): | ||
| """Pressing Run with valid packages updates result_text.""" | ||
| out = _run_app("vim,nano,emacs", "greedy") | ||
| assert "Selected" in out or "No selection" in out | ||
| assert "Results will appear here." not in out | ||
|
|
||
|
|
||
| def test_button_run_empty_packages(): | ||
| """Empty input writes a log line and does not crash.""" | ||
| out = _run_app("", "greedy") | ||
| # No selection path: result stays default or shows No selection | ||
| assert isinstance(out, str) | ||
|
|
||
|
|
||
| def test_button_run_with_solver_z3(): | ||
| """Solver selection is honoured (z3 path executes).""" | ||
| out = _run_app("a,b,c", "z3") | ||
| assert "Selected" in out or "No selection" in out | ||
|
|
||
|
|
||
| def test_non_run_button_ignored(): | ||
| """Buttons other than #run do not trigger solving.""" | ||
| async def _drive(): | ||
| app = MaximizerApp() | ||
| async with app.run_test() as pilot: | ||
| await pilot.pause() | ||
| # There is only one button (#run); just ensure no crash on idle | ||
| await pilot.pause() | ||
| return app.query_one("#result_text").render() | ||
|
|
||
| out = asyncio.run(_drive()) | ||
| assert isinstance(str(out), str) | ||
|
|
||
|
|
||
| def test_run_tui_callable(): | ||
| """run_tui() is callable (does not actually start the loop).""" | ||
| from package_maximizer.tui.app import run_tui | ||
|
|
||
| assert callable(run_tui) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Make these tests exercise and observe the behavior they claim.
test_button_run_empty_packagesonly checks that the result is a string. It does not verify"No packages provided."in#log_output.test_button_run_with_solver_z3does not prove that"z3"reachesPackageMaximizer; always using"greedy"could still pass.test_non_run_button_ignorednever dispatches a non-runbutton event, so the guard at Line 56 inpackage_maximizer/tui/app.pyremains untested.Expose the log output, assert the selected solver, and dispatch a non-
runevent before relying on these coverage claims.Also applies to: 71-74, 77-85
🤖 Prompt for AI Agents