-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
test_pydocgui.py
73 lines (58 loc) · 1.77 KB
/
test_pydocgui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
#
"""
Tests for pydocgui.py
"""
# Standard library imports
import sys
from unittest.mock import MagicMock
# Test library imports
import pytest
from flaky import flaky
# Local imports
from spyder.plugins.onlinehelp.widgets import PydocBrowser
@pytest.fixture
def pydocbrowser(qtbot):
"""Set up pydocbrowser."""
plugin_mock = MagicMock()
plugin_mock.CONF_SECTION = 'onlinehelp'
widget = PydocBrowser(parent=None, plugin=plugin_mock, name='pydoc')
widget._setup()
widget.setup()
with qtbot.waitSignal(widget.sig_load_finished, timeout=6000):
widget.initialize()
qtbot.addWidget(widget)
return qtbot, widget
@pytest.mark.skipif(
sys.platform == 'darwin', reason="Does not work on Mac")
def test_pydocbrowser(pydocbrowser):
"""Run Pydoc Browser."""
qtbot, browser = pydocbrowser
assert browser
@flaky(max_runs=5)
@pytest.mark.parametrize(
"lib", [('str', 'class str', 1),
('numpy.compat', 'numpy.compat', 2)
])
@pytest.mark.skipif(
sys.platform == 'darwin', reason="Does not work on Mac")
def test_get_pydoc(pydocbrowser, lib):
"""
Go to the documentation by url.
Regression test for spyder-ide/spyder#10740
"""
qtbot, browser = pydocbrowser
element, doc, matches = lib
webview = browser.webview
element_url = browser.text_to_url(element)
with qtbot.waitSignal(webview.loadFinished):
browser.set_url(element_url)
# Check number of matches. In Python 2 are 3 matches instead
# of 2 for numpy.compat
qtbot.waitUntil(
lambda: webview.get_number_matches(doc) in [matches, matches + 1])
if __name__ == "__main__":
pytest.main()