Skip to content

Commit

Permalink
Merge from 5.x: PR #21481
Browse files Browse the repository at this point in the history
Fixes #21456
  • Loading branch information
dalthviz committed Nov 3, 2023
2 parents 467cf7a + f487984 commit b0b1a01
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
31 changes: 31 additions & 0 deletions spyder/plugins/outlineexplorer/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,37 @@ def test_go_to_last_item(create_outlineexplorer, qtbot):
assert outlineexplorer.treewidget.currentItem().text(0) == 'method1'


@flaky(max_runs=10)
def test_display_variables(create_outlineexplorer, qtbot):
"""
Test that clicking on the 'Display variables and attributes' button located in the
toolbar of the outline explorer is working as expected by updating the tree widget.
Regression test for spyder-ide/spyder#21456.
"""
outlineexplorer, _ = create_outlineexplorer('text')

editor = outlineexplorer.treewidget.current_editor
state = outlineexplorer.treewidget.display_variables

editor_id = editor.get_id()

initial_tree = outlineexplorer.treewidget.editor_tree_cache[editor_id]

outlineexplorer.treewidget.toggle_variables(not state)

first_toggle_tree = outlineexplorer.treewidget.editor_tree_cache[editor_id]

assert first_toggle_tree != initial_tree

outlineexplorer.treewidget.toggle_variables(state)

second_toggle_tree = outlineexplorer.treewidget.editor_tree_cache[editor_id]

assert (second_toggle_tree != first_toggle_tree) and (
second_toggle_tree == initial_tree)


if __name__ == "__main__":
import os
pytest.main(['-x', os.path.basename(__file__), '-v', '-rw'])
3 changes: 1 addition & 2 deletions spyder/plugins/outlineexplorer/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,7 @@ def update_tree(self, items, editor):
if not must_update:
# Compare with current tree to check if it's necessary to update
# it.
changes = tree - current_tree
if tree and len(changes) == 0:
if tree == current_tree:
logger.debug(
f"Current and new trees for file {editor.fname} are the "
f"same, so no update is necessary"
Expand Down

0 comments on commit b0b1a01

Please sign in to comment.