Skip to content

Commit 5dc5887

Browse files
TEST: system tests for extension and version managers (#6833)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 3241dff commit 5dc5887

File tree

4 files changed

+660
-2
lines changed

4 files changed

+660
-2
lines changed

doc/changelog.d/6833.test.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
System tests for extension and version managers

src/ansys/aedt/core/extensions/installer/version_manager.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ def __init__(self, ui, desktop):
130130
self.pyedb_branch_name = tkinter.StringVar()
131131
self.pyedb_branch_name.set("main")
132132

133-
self.ini_file_path = os.path.join(os.path.dirname(__file__), "settings.ini")
134-
135133
# Prepare subprocess environment so the venv is effectively activated for all runs
136134
self.activated_env = None
137135
self.activate_venv()
Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates.
4+
# SPDX-License-Identifier: MIT
5+
#
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
25+
import pytest
26+
27+
from ansys.aedt.core import Hfss
28+
from ansys.aedt.core.extensions.customize_automation_tab import AEDT_APPLICATIONS
29+
from ansys.aedt.core.extensions.installer.extension_manager import ExtensionManager
30+
31+
32+
@pytest.fixture(autouse=True)
33+
def disable_pyaedt_update_check(monkeypatch):
34+
"""Prevent ExtensionManager from starting the update-check thread during tests."""
35+
monkeypatch.setattr(
36+
"ansys.aedt.core.extensions.installer.extension_manager.ExtensionManager.check_for_pyaedt_update_on_startup",
37+
lambda self: None,
38+
)
39+
yield
40+
41+
42+
def test_extension_manager_initialization(add_app):
43+
"""Test that ExtensionManager initializes correctly in a real AEDT environment."""
44+
# Create HFSS application for testing environment
45+
aedtapp = add_app(
46+
application=Hfss,
47+
project_name="test_extension_manager",
48+
design_name="test_design",
49+
)
50+
51+
# Create extension manager with withdraw=True to avoid showing window
52+
extension = ExtensionManager(withdraw=True)
53+
54+
try:
55+
# Verify basic initialization
56+
assert extension.root is not None
57+
assert extension.root.title() == "Extension Manager"
58+
assert extension.toolkits is not None
59+
assert extension.current_category is not None
60+
assert extension.python_interpreter is not None
61+
assert extension.right_panel is not None
62+
63+
# Verify theme initialization
64+
assert extension.theme is not None
65+
66+
# Verify log variables
67+
assert isinstance(extension.full_log_buffer, list)
68+
assert extension.logs_window is None
69+
assert extension.logs_text_widget is None
70+
71+
finally:
72+
extension.root.destroy()
73+
aedtapp.close_project(aedtapp.project_name)
74+
75+
76+
def test_extension_manager_load_extensions(add_app):
77+
"""Test loading extensions for different categories."""
78+
# Create HFSS application for testing environment
79+
aedtapp = add_app(
80+
application=Hfss,
81+
project_name="test_load_extensions",
82+
design_name="test_design",
83+
)
84+
85+
extension = ExtensionManager(withdraw=True)
86+
87+
try:
88+
# Test loading extensions for different categories
89+
test_categories = ["Common", "HFSS", "Maxwell3D", "Circuit"]
90+
91+
for category in test_categories:
92+
extension.load_extensions(category)
93+
94+
# Verify current category is set
95+
expected_category = AEDT_APPLICATIONS.get(category.lower(), category)
96+
assert extension.current_category == expected_category
97+
98+
# Verify right panel has content
99+
assert extension.right_panel is not None
100+
101+
finally:
102+
extension.root.destroy()
103+
aedtapp.close_project(aedtapp.project_name)
104+
105+
106+
def test_extension_manager_log_buffer(add_app):
107+
"""Test log buffer functionality."""
108+
# Create HFSS application for testing environment
109+
aedtapp = add_app(
110+
application=Hfss,
111+
project_name="test_log_buffer",
112+
design_name="test_design",
113+
)
114+
115+
extension = ExtensionManager(withdraw=True)
116+
117+
try:
118+
# Test appending to log buffer
119+
test_message = "Test log message"
120+
test_tag = "info"
121+
122+
extension._append_full_log(test_message, test_tag)
123+
124+
# Verify log was appended
125+
assert len(extension.full_log_buffer) > 0
126+
assert (test_message, test_tag) in extension.full_log_buffer
127+
128+
# Test clearing logs
129+
extension._clear_logs()
130+
assert len(extension.full_log_buffer) == 0
131+
132+
finally:
133+
extension.root.destroy()
134+
aedtapp.close_project(aedtapp.project_name)
135+
136+
137+
def test_extension_manager_check_extension_pinned(add_app):
138+
"""Test checking if extension is pinned."""
139+
# Create HFSS application for testing environment
140+
aedtapp = add_app(
141+
application=Hfss,
142+
project_name="test_check_pinned",
143+
design_name="test_design",
144+
)
145+
146+
extension = ExtensionManager(withdraw=True)
147+
148+
try:
149+
# Test with a common extension category
150+
category = "HFSS"
151+
option = "test_extension"
152+
153+
# This should not raise an error
154+
is_pinned = extension.check_extension_pinned(category, option)
155+
156+
# Result should be boolean
157+
assert isinstance(is_pinned, bool)
158+
159+
finally:
160+
extension.root.destroy()
161+
aedtapp.close_project(aedtapp.project_name)
162+
163+
164+
def test_extension_manager_window_geometry(add_app):
165+
"""Test window dimensions and geometry settings."""
166+
# Create HFSS application for testing environment
167+
aedtapp = add_app(
168+
application=Hfss,
169+
project_name="test_geometry",
170+
design_name="test_design",
171+
)
172+
173+
extension = ExtensionManager(withdraw=True)
174+
175+
try:
176+
# Force geometry update
177+
extension.root.update()
178+
179+
# Get window dimensions
180+
geometry = extension.root.geometry()
181+
182+
# Verify geometry string is properly formatted
183+
assert "x" in geometry
184+
assert "+" in geometry or "-" in geometry
185+
186+
finally:
187+
extension.root.destroy()
188+
aedtapp.close_project(aedtapp.project_name)
189+
190+
191+
def test_extension_manager_multiple_categories(add_app):
192+
"""Test switching between multiple extension categories."""
193+
# Create HFSS application for testing environment
194+
aedtapp = add_app(
195+
application=Hfss,
196+
project_name="test_multiple_categories",
197+
design_name="test_design",
198+
)
199+
200+
extension = ExtensionManager(withdraw=True)
201+
202+
try:
203+
# Test loading multiple categories in sequence
204+
categories = ["Common", "HFSS", "Circuit", "Common"]
205+
206+
for category in categories:
207+
extension.load_extensions(category)
208+
expected = AEDT_APPLICATIONS.get(category.lower(), category)
209+
assert extension.current_category == expected
210+
211+
finally:
212+
extension.root.destroy()
213+
aedtapp.close_project(aedtapp.project_name)
214+
215+
216+
def test_extension_manager_canvas_theme_application(add_app):
217+
"""Test that canvas theme is properly applied."""
218+
# Create HFSS application for testing environment
219+
aedtapp = add_app(
220+
application=Hfss,
221+
project_name="test_canvas_theme",
222+
design_name="test_design",
223+
)
224+
225+
extension = ExtensionManager(withdraw=True)
226+
227+
try:
228+
import tkinter
229+
230+
with pytest.raises(tkinter.TclError):
231+
# Create a test canvas
232+
test_canvas = tkinter.Canvas(extension.root)
233+
234+
# Apply theme to canvas
235+
extension.apply_canvas_theme(test_canvas)
236+
237+
# Verify canvas has background color set
238+
bg_color = test_canvas.cget("bg")
239+
assert bg_color is not None
240+
241+
# Clean up test canvas
242+
test_canvas.destroy()
243+
raise tkinter.TclError("Force error to exit cleanly")
244+
245+
finally:
246+
extension.root.destroy()
247+
aedtapp.close_project(aedtapp.project_name)
248+
249+
250+
def test_extension_manager_toolkits_loaded(add_app):
251+
"""Test that toolkits are properly loaded on initialization."""
252+
# Create HFSS application for testing environment
253+
aedtapp = add_app(
254+
application=Hfss,
255+
project_name="test_toolkits",
256+
design_name="test_design",
257+
)
258+
259+
extension = ExtensionManager(withdraw=True)
260+
261+
try:
262+
# Verify toolkits are loaded
263+
assert extension.toolkits is not None
264+
assert isinstance(extension.toolkits, dict)
265+
266+
# Toolkits should contain at least some categories
267+
assert len(extension.toolkits) > 0
268+
269+
finally:
270+
extension.root.destroy()
271+
aedtapp.close_project(aedtapp.project_name)
272+
273+
274+
def test_extension_manager_default_category(add_app):
275+
"""Test that default category is properly set."""
276+
# Create HFSS application for testing environment
277+
aedtapp = add_app(
278+
application=Hfss,
279+
project_name="test_default_category",
280+
design_name="test_design",
281+
)
282+
283+
extension = ExtensionManager(withdraw=True)
284+
285+
try:
286+
# Verify default category is set
287+
assert extension.current_category is not None
288+
assert extension.current_category == "Common"
289+
290+
finally:
291+
extension.root.destroy()
292+
aedtapp.close_project(aedtapp.project_name)

0 commit comments

Comments
 (0)