-
-
Notifications
You must be signed in to change notification settings - Fork 0
chore: strip defensive getattrs from production, seed bypassed-init tests #81
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,42 @@ | ||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||
| Shared test helpers for bypassed-`__init__` widgets / managers. | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| Many tests use `Widget.__new__(Widget)` and `patch.object(Widget, "__init__")` | ||||||||||||||||||||||||||||
| to test individual methods without spinning up the full Qt object graph. | ||||||||||||||||||||||||||||
| That path skips attribute initialization, so any production code that | ||||||||||||||||||||||||||||
| references `self._x` on a bypassed instance raises `AttributeError`. | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| Rather than litter production code with `getattr(self, "_x", default)` | ||||||||||||||||||||||||||||
| to paper over the test pattern, these helpers seed the minimum state | ||||||||||||||||||||||||||||
| each method under test needs. Production code stays clean; tests own | ||||||||||||||||||||||||||||
| their own setup. | ||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| from __future__ import annotations | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| from collections import deque | ||||||||||||||||||||||||||||
| from unittest.mock import MagicMock | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def seed_preview_widget(widget) -> None: | ||||||||||||||||||||||||||||
| """Initialize the v3.2.0 attributes a bypassed-init WindowPreviewWidget | ||||||||||||||||||||||||||||
| needs to survive update_frame, paintEvent, and threat-state methods.""" | ||||||||||||||||||||||||||||
| widget._replay_buffer = deque(maxlen=6) | ||||||||||||||||||||||||||||
| widget._replay_last_sample_ms = 0 | ||||||||||||||||||||||||||||
| widget._replay_strip = None | ||||||||||||||||||||||||||||
| widget._replay_view_index = None | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def seed_main_tab(tab) -> None: | ||||||||||||||||||||||||||||
| """Seed bypassed-init MainTab attributes needed by _on_window_removed | ||||||||||||||||||||||||||||
| and other lifecycle methods.""" | ||||||||||||||||||||||||||||
| tab._focus_window_id = None | ||||||||||||||||||||||||||||
| tab.status_dock = MagicMock() | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def seed_window_manager(manager) -> None: | ||||||||||||||||||||||||||||
| """Seed bypassed-init WindowManager attributes needed by | ||||||||||||||||||||||||||||
| apply_threat_state and the smart fan-out / jumps-from filter.""" | ||||||||||||||||||||||||||||
| manager._character_systems = {} | ||||||||||||||||||||||||||||
| manager._jump_calculator = None | ||||||||||||||||||||||||||||
| manager._jump_max = 0 | ||||||||||||||||||||||||||||
|
Comment on lines
+37
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||||||||||||
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.
The
seed_preview_widgethelper is missing several attributes required bypaintEventandset_threat_state, which the docstring explicitly claims it supports. Since the production code now uses direct attribute access (removinggetattrguards), calling these methods on a seeded widget will raiseAttributeError.Missing attributes include:
_accent_color,_threat_level,_flash_color,_threat_alpha,_threat_distance,_pulse_phase,_positions_locked,_show_activity_indicator, and the variousQTimerinstances (_threat_decay_timer,_pulse_timer,_flash_timer). Also, it is better to use theREPLAY_BUFFER_SIZEconstant instead of hardcoding6.