Skip to content

Commit 4b2df4b

Browse files
committed
Testing: Check that own classes can be viewed in the Variable Explorer
1 parent 08579f4 commit 4b2df4b

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

spyder/app/tests/own_class/mod/__init__.py

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class MyClass:
2+
3+
def __init__(self):
4+
self.var = 123
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from pathlib import Path
2+
import sys
3+
4+
_file_path = Path(__file__)
5+
_mod_path = str(_file_path.parents[1])
6+
sys.path.append(_mod_path)
7+
8+
from mod import myclass
9+
10+
mc_instance = myclass.MyClass()

spyder/app/tests/test_mainwindow.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7754,5 +7754,49 @@ def test_kernel_call_handlers_after_restart(main_window, qtbot):
77547754
assert handlers_before_restart == handlers_after_restart
77557755

77567756

7757+
@flaky(max_runs=5)
7758+
def test_view_own_class_in_variable_explorer(main_window, qtbot):
7759+
"""
7760+
Test that own classes can be viewed in the Variable Explorer if the path
7761+
for the parent of the module that contains them is added to the Pythonpath
7762+
manager.
7763+
7764+
Regression test for spyder-ide/spyder#15998.
7765+
"""
7766+
ipyconsole = main_window.get_plugin(Plugins.IPythonConsole)
7767+
ppm = main_window.get_plugin(Plugins.PythonpathManager)
7768+
7769+
# Wait until the kernel is ready
7770+
shell = ipyconsole.get_current_shellwidget()
7771+
qtbot.waitUntil(
7772+
lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT
7773+
)
7774+
7775+
# Run test file
7776+
test_file = osp.join(LOCATION, "own_class", "script", "script.py").replace(
7777+
"\\", "/"
7778+
)
7779+
with qtbot.waitSignal(shell.executed):
7780+
shell.execute(f"%runfile {test_file}")
7781+
7782+
# Trying to get the value for the own class instance should fail at this
7783+
# point
7784+
with pytest.raises(ValueError):
7785+
shell.get_value('mc_instance')
7786+
7787+
# Add own_class directory to the Pythonpath manager
7788+
ppm.show_path_manager()
7789+
qtbot.wait(500)
7790+
7791+
ppm.path_manager_dialog.add_path(directory=osp.join(LOCATION, "own_class"))
7792+
7793+
with qtbot.waitSignal(ppm.sig_pythonpath_changed, timeout=1000):
7794+
ppm.path_manager_dialog.accept()
7795+
7796+
# Getting the instance should work now
7797+
instance_value = shell.get_value('mc_instance')
7798+
assert instance_value.var == 123
7799+
7800+
77577801
if __name__ == "__main__":
77587802
pytest.main()

0 commit comments

Comments
 (0)