Skip to content

Commit

Permalink
Add unit test for spyder-ide#6317 , ensuring help is shown with tut; …
Browse files Browse the repository at this point in the history
…cleanup
  • Loading branch information
CAM-Gerlach committed Jan 31, 2018
1 parent e73c222 commit fe7ca1a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ def test_troubleshooting_menu_item_and_url(monkeypatch):

@flaky(max_runs=3)
@pytest.mark.slow
def test_help_opens_when_show_tutorial(main_window, qtbot):
def test_help_opens_when_show_tutorial_full(main_window, qtbot):
"""Test fix for #6317 : 'Show tutorial' opens the help plugin if closed."""
HELP_STR = "Help"

Expand Down
45 changes: 44 additions & 1 deletion spyder/plugins/tests/test_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
# Licensed under the terms of the MIT License
# (see spyder/__init__.py for details)
# -----------------------------------------------------------------------------

"""
Tests for the Spyder `help` plugn, `help.py`.
"""

# Standard library imports
try:
from unittest.mock import Mock, MagicMock
except ImportError:
from mock import Mock, MagicMock # Python 2

# Third party imports
from qtpy.QtWebEngineWidgets import WEBENGINE
import pytest
Expand Down Expand Up @@ -38,7 +45,7 @@ def help_plugin(qtbot):


# =============================================================================
# Tests
# Utility functions
# =============================================================================
def check_text(widget, text):
"""Check if some text is present in a widget."""
Expand All @@ -55,6 +62,9 @@ def callback(data):
return text in widget.toHtml()


# =============================================================================
# Tests
# =============================================================================
@flaky(max_runs=3)
def test_no_docs_message(help_plugin, qtbot):
"""
Expand Down Expand Up @@ -83,5 +93,38 @@ def test_no_further_docs_message(help_plugin, qtbot):
timeout=3000)


def test_help_opens_when_show_tutorial_unit(help_plugin, qtbot,):
"""Test fix for #6317 : 'Show tutorial' opens the help plugin if closed."""
MockDockwidget = MagicMock()
MockDockwidget.return_value.isVisible.return_value = False
mockDockwidget_instance = MockDockwidget()

MockAction = Mock()
mock_toggle_view_action = MockAction()
mock_show_rich_text = Mock()

help_plugin.dockwidget = mockDockwidget_instance
help_plugin.toggle_view_action = mock_toggle_view_action
help_plugin.show_rich_text = mock_show_rich_text

help_plugin.show_tutorial()
qtbot.wait(100)

assert mockDockwidget_instance.show.call_count == 1
assert mock_toggle_view_action.setChecked.call_count == 1
mock_toggle_view_action.setChecked.assert_called_once_with(True)
assert mock_show_rich_text.call_count == 1

MockDockwidget.return_value.isVisible.return_value = True
mockDockwidget_instance = MockDockwidget()
help_plugin.dockwidget = mockDockwidget_instance

help_plugin.show_tutorial()
qtbot.wait(100)
assert mockDockwidget_instance.show.call_count == 1
assert mock_toggle_view_action.setChecked.call_count == 1
assert mock_show_rich_text.call_count == 2


if __name__ == "__main__":
pytest.main()

0 comments on commit fe7ca1a

Please sign in to comment.