Private
Public Access
Per post_module_taxonomy_de_cruft_20260627 Phase 2 (FR7 continued).
The previous migration commit (8f11340b) handled the
'from src.models import X' pattern (85 sites). This commit handles
the 'models.<moved_class>' attribute access pattern (44 sites in 20
files), which the __getattr__ shim previously supported.
The migration was performed by the one-time script
scripts/tier2/artifacts/post_module_taxonomy_de_cruft_20260627/migrate_models_attr.py
which:
1. For each 'models.<moved_class>' reference, replaces it with the
bare class name (e.g., 'models.MCPConfiguration' -> 'MCPConfiguration')
2. Adds the import 'from src.<destination> import <moved_class>' at
the top of the file (deduplicated if the import already exists)
3. Skips moved classes that the file already imports directly
The migration script inserts the import after the 'from __future__
import annotations' line if present; otherwise it adds the import
to the destination module's existing import block. Two files
required manual fixes because the script's regex didn't handle them:
- src/rag_engine.py: uses 'from src import models' (not 'from
src.models import X'); the class is accessed
via 'models.RAGConfig'. Replaced with a
direct 'from src.mcp_client import RAGConfig'
import and removed the 'from src import models'.
- tests/test_project_context_20260627.py: uses the parens-style
multi-line 'from src.models import (X, Y, Z)'.
Replaced with the parens-style direct import.
After this commit:
- 'models.MCPConfiguration', 'models.FileItem', 'models.Ticket', etc.
no longer work in src/ and tests/ (the AttributeError raises
because models.py no longer has the __getattr__ entries for
moved classes)
- All consumer files have direct imports of the moved classes
Total: 44 'models.<moved_class>' references rewritten across 20 files.
68 lines
2.6 KiB
Python
68 lines
2.6 KiB
Python
import unittest.mock
|
|
from unittest.mock import MagicMock, patch
|
|
from src.gui_2 import App, render_ast_inspector_modal
|
|
from src import models
|
|
|
|
def test_ast_inspector_line_range_parsing():
|
|
# 1. Setup mock App instance
|
|
app = MagicMock(spec=App)
|
|
app._show_ast_inspector = True
|
|
app.show_structural_editor_modal = True
|
|
app.ui_inspecting_ast_file = FileItem(path="test.py")
|
|
app.ui_editing_slices_file = app.ui_inspecting_ast_file
|
|
app._cached_ast_file_path = ""
|
|
app._cached_ast_nodes = []
|
|
app._cached_ast_file_lines = []
|
|
app.text_viewer_content = ""
|
|
|
|
# Setup mock controller
|
|
app.controller = MagicMock()
|
|
app.controller.active_project_path = "C:/projects/test/manual_slop.toml"
|
|
app.controller.project = {"context_tags": ["auto-ast", "bug"]}
|
|
|
|
# 2. Define mock outline string with line ranges
|
|
mock_outline = "[Func] foo (Lines 10-20)\n [Class] Bar (Lines 30-50)"
|
|
|
|
# 3. Patch imgui and mcp_client
|
|
with patch("src.gui_2.imgui") as mock_imgui, \
|
|
patch("src.gui_2.imscope") as mock_imscope, \
|
|
patch("src.gui_2.mcp_client.py_get_code_outline", return_value=mock_outline), \
|
|
patch("src.gui_2.mcp_client.read_file", return_value="test content"):
|
|
|
|
# begin_popup_modal needs to return (expanded, opened)
|
|
mock_imgui.begin_popup_modal.return_value = (True, True)
|
|
# begin_child returns True usually
|
|
mock_imgui.begin_child.return_value = True
|
|
# radio_button returns (changed, active)
|
|
mock_imgui.radio_button.return_value = (False, False)
|
|
mock_imgui.get_content_region_avail.return_value.y = 800.0
|
|
mock_imgui.get_frame_height_with_spacing.return_value = 24.0
|
|
mock_imgui.get_style.return_value.window_padding = mock_imgui.ImVec2(8,8)
|
|
|
|
# Setup imscope mocks
|
|
mock_imscope.window.return_value.__enter__.return_value = (True, True)
|
|
mock_imscope.child.return_value.__enter__.return_value = True
|
|
mock_imscope.table.return_value.__enter__.return_value = True
|
|
mock_imscope.tree_node_ex.return_value.__enter__.return_value = True
|
|
mock_imscope.tab_item.return_value.__enter__.return_value = (True, True)
|
|
mock_imscope.style_color.return_value.__enter__.return_value = None
|
|
mock_imscope.style_var.return_value.__enter__.return_value = None
|
|
|
|
# 4. Call the method
|
|
render_ast_inspector_modal(app)
|
|
|
|
# 5. Assertions
|
|
assert len(app._cached_ast_nodes) == 2
|
|
|
|
node1 = app._cached_ast_nodes[0]
|
|
assert node1['name'] == "foo"
|
|
assert node1['kind'] == "Func"
|
|
assert node1['start_line'] == 10
|
|
assert node1['end_line'] == 20
|
|
|
|
node2 = app._cached_ast_nodes[1]
|
|
assert node2['name'] == "Bar"
|
|
assert node2['kind'] == "Class"
|
|
assert node2['start_line'] == 30
|
|
assert node2['end_line'] == 50
|