fix(review): address Copilot review findings from PRs #1391, #1387#1397
fix(review): address Copilot review findings from PRs #1391, #1387#1397yashhzd wants to merge 2 commits intoArduPilot:masterfrom
Conversation
…rduPilot#1387 - Use self.center_window_on_screen() instead of BaseWindow.center_window_on_screen() for proper polymorphism and easier mocking (8 files) - Make test match assertions locale-independent by matching on repr(value) instead of translated message strings - Remove unused _() import from test_data_model_par_dict.py - Reset mocks after __init__ in progress window test to properly isolate the update_progress_bar centering path - Add test for rendered-size path in center_window_on_screen (winfo_width > 1) Signed-off-by: Yash Goel <yashhzd@users.noreply.github.com> Signed-off-by: YASH GOEL <yashhzd@YASHs-Mac-Studio.local>
There was a problem hiding this comment.
Pull request overview
Follow-up changes to address prior Copilot review findings by improving Tkinter window-centering polymorphism and strengthening/isolating tests (locale-safe assertions and more precise centering behavior verification).
Changes:
- Switched window-centering calls from
BaseWindow.center_window_on_screen(...)toself.center_window_on_screen(...)to enable subclass overrides/mocking. - Updated tests to be locale-independent by matching on
repr(value)-style fragments rather than translated strings. - Improved progress window test isolation and added test coverage for mapped-window rendered-size centering.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| ardupilot_methodic_configurator/frontend_tkinter_template_overview.py | Uses instance dispatch for centering to support overrides/mocking. |
| ardupilot_methodic_configurator/frontend_tkinter_software_update.py | Uses instance dispatch for centering to support overrides/mocking. |
| ardupilot_methodic_configurator/frontend_tkinter_project_opener.py | Uses instance dispatch for centering to support overrides/mocking. |
| ardupilot_methodic_configurator/frontend_tkinter_project_creator.py | Uses instance dispatch for centering to support overrides/mocking. |
| ardupilot_methodic_configurator/frontend_tkinter_parameter_editor.py | Uses instance dispatch for centering to support overrides/mocking. |
| ardupilot_methodic_configurator/frontend_tkinter_flightcontroller_info.py | Uses instance dispatch for centering to support overrides/mocking. |
| ardupilot_methodic_configurator/frontend_tkinter_connection_selection.py | Uses instance dispatch for centering to support overrides/mocking. |
| ardupilot_methodic_configurator/frontend_tkinter_component_editor_base.py | Uses instance dispatch for centering to support overrides/mocking. |
| tests/test_data_model_par_dict.py | Makes exception message matching locale-safe and removes translation dependency. |
| tests/test_frontend_tkinter_progress_window.py | Resets mocks post-__init__ to verify update path behavior. |
| tests/test_frontend_tkinter_base_window.py | Adds coverage for using rendered size when window is mapped. |
| # Reset mocks after __init__ to isolate the update_progress_bar path | ||
| mock_center_screen.reset_mock() | ||
| mock_center_parent.reset_mock() |
There was a problem hiding this comment.
assert_called_once() makes this test more brittle than the previous call_count >= 1 assertion. If update_progress_bar() legitimately re-centers more than once (e.g., due to internal layout/geometry adjustments), this will fail even though behavior is correct. Consider asserting the expected relationship (e.g., “screen centering was used at least once and parent-centering was never used”) by checking mock_center_screen.assert_called() or call_count >= 1, while keeping mock_center_parent.assert_not_called() for the key behavior.
|
|
||
| # Screen centering should be used, not parent-relative | ||
| assert mock_center_screen.call_count >= 1 | ||
| mock_center_screen.assert_called_once() |
There was a problem hiding this comment.
assert_called_once() makes this test more brittle than the previous call_count >= 1 assertion. If update_progress_bar() legitimately re-centers more than once (e.g., due to internal layout/geometry adjustments), this will fail even though behavior is correct. Consider asserting the expected relationship (e.g., “screen centering was used at least once and parent-centering was never used”) by checking mock_center_screen.assert_called() or call_count >= 1, while keeping mock_center_parent.assert_not_called() for the key behavior.
| mock_center_screen.assert_called_once() | |
| mock_center_screen.assert_called() |
tests/test_data_model_par_dict.py
Outdated
| try: | ||
| # Act & Assert: Invalid values rejected | ||
| with pytest.raises(SystemExit, match=_("Invalid parameter value {value!r}").format(value="not_a_number")): | ||
| with pytest.raises(SystemExit, match=r"'not_a_number'"): |
There was a problem hiding this comment.
This hardcoded regex is inconsistent with the next test’s approach (re.escape(repr(bad_value))) and is less systematic. For consistency and to avoid regex pitfalls if the matched value ever changes, prefer match=re.escape(repr("not_a_number")) (or a shared helper) here as well.
| with pytest.raises(SystemExit, match=r"'not_a_number'"): | |
| with pytest.raises(SystemExit, match=re.escape(repr("not_a_number"))): |
|
Some of these are already fixed in #1394 |
- Use assert_called() instead of assert_called_once() for screen centering check — less brittle if internal layout triggers extra calls - Use re.escape(repr(...)) consistently in both test assertions Signed-off-by: Yash Goel <yashhzd@users.noreply.github.com>
|
Fixed both Copilot findings:
Pushed in 3b53294. |
|
You could try to rebase this on master to see if something was missed there. |
Summary
Follow-up PR addressing Copilot bot review findings from #1391 and #1387.
Changes
Polymorphism fix (8 files):
BaseWindow.center_window_on_screen(self.root)→self.center_window_on_screen(self.root)in all 8 window classes that inherit fromBaseWindowLocale-safe test assertions (PR #1391 finding):
match=patterns now userepr(value)instead of_("translated message"), so they won't break under non-English locales_()import fromtest_data_model_par_dict.pyProgress window test isolation (PR #1387 finding):
ProgressWindow.__init__()before callingupdate_progress_bar()so the test actually verifies the update path, not just initNew test coverage (PR #1387 finding):
test_uses_rendered_size_when_window_is_mapped— verifiescenter_window_on_screen()useswinfo_width/height(rendered size) instead ofwinfo_reqwidth/heightwhen the window is already mappedFiles changed
frontend_tkinter_*.pyfilesBaseWindow.center_window_on_screen()→self.center_window_on_screen()tests/test_data_model_par_dict.pytests/test_frontend_tkinter_progress_window.pytests/test_frontend_tkinter_base_window.pySigned-off-by: Yash Goel yashhzd@users.noreply.github.com