46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
import unittest.mock
|
|
from unittest.mock import MagicMock, patch
|
|
from src.gui_2 import App
|
|
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.ui_inspecting_ast_file = models.FileItem(path="test.py")
|
|
app._cached_ast_file_path = ""
|
|
app._cached_ast_nodes = []
|
|
|
|
# 2. Define mock outline string with line ranges
|
|
# Note: outline_tool uses 2 spaces for indent
|
|
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.mcp_client.py_get_code_outline", return_value=mock_outline):
|
|
|
|
# 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)
|
|
|
|
# 4. Call the method
|
|
App._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
|