|
12 | 12 |
|
13 | 13 | import tkinter as tk
|
14 | 14 | from argparse import ArgumentParser
|
| 15 | +from collections.abc import Generator |
15 | 16 | from tkinter import ttk
|
16 | 17 | from typing import Union, get_args, get_origin
|
17 | 18 | from unittest.mock import MagicMock, patch
|
|
34 | 35 | # pylint: disable=protected-access, too-many-lines, redefined-outer-name, unused-argument, too-few-public-methods
|
35 | 36 |
|
36 | 37 |
|
37 |
| -def setup_common_editor_mocks(editor) -> ComponentEditorWindowBase: |
| 38 | +def setup_common_editor_mocks(editor, root=None) -> ComponentEditorWindowBase: |
38 | 39 | """Set up common mock attributes and methods for editor fixtures."""
|
39 | 40 | # Set up all required attributes manually
|
40 |
| - editor.root = MagicMock() |
41 |
| - editor.main_frame = MagicMock() |
| 41 | + editor.root = root if root is not None else MagicMock() |
| 42 | + editor.main_frame = ttk.Frame(editor.root) if root is not None else MagicMock() |
42 | 43 | editor.scroll_frame = MagicMock()
|
43 |
| - editor.scroll_frame.view_port = MagicMock() |
| 44 | + editor.scroll_frame.view_port = ttk.Frame(editor.root) if root is not None else MagicMock() |
44 | 45 | editor.version = "1.0.0"
|
45 | 46 |
|
46 | 47 | # Mock filesystem and methods with proper schema loading
|
@@ -125,14 +126,14 @@ def test_argument_parser_with_skip_component_editor(self) -> None:
|
125 | 126 |
|
126 | 127 |
|
127 | 128 | @pytest.fixture
|
128 |
| -def editor_with_mocked_root() -> ComponentEditorWindowBase: |
| 129 | +def editor_with_mocked_root(root) -> Generator[ComponentEditorWindowBase, None, None]: |
129 | 130 | """Create a mock ComponentEditorWindowBase for testing."""
|
130 | 131 | # Create the class without initialization
|
131 | 132 | with patch.object(ComponentEditorWindowBase, "__init__", return_value=None):
|
132 | 133 | editor = ComponentEditorWindowBase() # pylint: disable=no-value-for-parameter
|
133 | 134 |
|
134 |
| - # Set up common mocks and helper methods |
135 |
| - setup_common_editor_mocks(editor) |
| 135 | + # Set up common mocks and helper methods with real root |
| 136 | + setup_common_editor_mocks(editor, root) |
136 | 137 | add_editor_helper_methods(editor)
|
137 | 138 |
|
138 | 139 | yield editor
|
@@ -1046,7 +1047,6 @@ def test_user_sees_introduction_frame_with_explanations(
|
1046 | 1047 | mock_intro_frame = MagicMock()
|
1047 | 1048 | mock_frame_class.return_value = mock_intro_frame
|
1048 | 1049 |
|
1049 |
| - # Mock the methods that would be called |
1050 | 1050 | editor_for_ui_tests._add_explanation_text = MagicMock()
|
1051 | 1051 | editor_for_ui_tests._add_vehicle_image = MagicMock()
|
1052 | 1052 |
|
|
0 commit comments