Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Make several GUI/qtbot tests more reliable by increasing timeouts and tweaking the methods used #6714

Merged
merged 3 commits into from
Mar 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# -----------------------------------------------------------------------------

"""
Tests for the main window
Tests for the main window.
"""

# Standard library imports
Expand Down Expand Up @@ -216,12 +216,12 @@ def test_calltip(main_window, qtbot):
@pytest.mark.use_introspection
def test_get_help(main_window, qtbot):
"""
Test that Help is working when called from the Editor and the
IPython console.
Test that Help works when called from the Editor and the IPython console.
"""
shell = main_window.ipyconsole.get_current_shellwidget()
control = shell._control
qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT)
qtbot.waitUntil(lambda: shell._prompt_html is not None,
timeout=SHELL_TIMEOUT)

help_plugin = main_window.help
webview = help_plugin.rich_text.webview._webview
Expand All @@ -238,10 +238,10 @@ def test_get_help(main_window, qtbot):
control.inspect_current_object()

# Check that a expected text is part of the page
qtbot.waitUntil(lambda: check_text(webpage, "namespace"), timeout=4000)
qtbot.waitUntil(lambda: check_text(webpage, "namespace"), timeout=6000)

# --- From the editor ---
qtbot.wait(2000)
qtbot.wait(3000)
main_window.editor.new()
code_editor = main_window.editor.get_focus_widget()
editorstack = main_window.editor.get_current_editorstack()
Expand All @@ -254,7 +254,7 @@ def test_get_help(main_window, qtbot):
editorstack.inspect_current_object()

# Check that a expected text is part of the page
qtbot.waitUntil(lambda: check_text(webpage, "range"), timeout=4000)
qtbot.waitUntil(lambda: check_text(webpage, "range"), timeout=6000)


@pytest.mark.slow
Expand Down
37 changes: 23 additions & 14 deletions spyder/plugins/tests/test_ipythonconsole.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
# -*- coding: utf-8 -*-
#
# -----------------------------------------------------------------------------
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
#
# Licensed under the terms of the MIT License
# (see spyder/__init__.py for details)
# -----------------------------------------------------------------------------

"""
Tests for the IPython console plugin.
"""

# Standard library imports
import codecs
import os
import os.path as osp
import shutil
import tempfile
from textwrap import dedent

# Third party imports
import cloudpickle
from flaky import flaky
import ipykernel
Expand All @@ -20,6 +28,7 @@
from qtpy.QtCore import Qt
import zmq

# Local imports
from spyder.config.gui import get_color_scheme
from spyder.config.main import CONF
from spyder.py3compat import PY2, to_text_string
Expand All @@ -28,17 +37,17 @@
from spyder.utils.programs import TEMPDIR


#==============================================================================
# =============================================================================
# Constants
#==============================================================================
# =============================================================================
SHELL_TIMEOUT = 20000
TEMP_DIRECTORY = tempfile.gettempdir()
NON_ASCII_DIR = osp.join(TEMP_DIRECTORY, u'測試', u'اختبار')


#==============================================================================
# =============================================================================
# Utillity Functions
#==============================================================================
# =============================================================================
def get_console_font_color(syntax_style):
styles = create_style_class(syntax_style).styles
font_color = styles[Name]
Expand All @@ -51,9 +60,9 @@ def get_console_background_color(style_sheet):
return background_color


#==============================================================================
# =============================================================================
# Qt Test Fixtures
#==============================================================================
# =============================================================================
@pytest.fixture
def ipyconsole(qtbot, request):
"""IPython console fixture."""
Expand Down Expand Up @@ -97,9 +106,9 @@ def close_console():
return console


#==============================================================================
# =============================================================================
# Tests
#==============================================================================
# =============================================================================
@pytest.mark.slow
@flaky(max_runs=3)
@pytest.mark.auto_backend
Expand Down Expand Up @@ -824,25 +833,25 @@ def test_sys_argv_clear(ipyconsole, qtbot):
@pytest.mark.slow
@flaky(max_runs=3)
def test_set_elapsed_time(ipyconsole, qtbot):
"""Test timer."""
"""Test that the IPython console elapsed timer is set correctly."""
shell = ipyconsole.get_current_shellwidget()
client = ipyconsole.get_current_client()
qtbot.waitUntil(lambda: shell._prompt_html is not None,
timeout=SHELL_TIMEOUT)

# Set time to 2 minutes ago.
client.t0 -= 120
with qtbot.waitSignal(client.timer.timeout, timeout=3000):
with qtbot.waitSignal(client.timer.timeout, timeout=5000):
ipyconsole.set_elapsed_time(client)
assert '00:02:00' in client.time_label.text()

with qtbot.waitSignal(client.timer.timeout, timeout=3000):
with qtbot.waitSignal(client.timer.timeout, timeout=5000):
pass
assert '00:02:01' in client.time_label.text()

# Make previous time later than current time.
client.t0 += 2000
with qtbot.waitSignal(client.timer.timeout, timeout=3000):
with qtbot.waitSignal(client.timer.timeout, timeout=5000):
pass
assert '00:00:00' in client.time_label.text()

Expand Down
56 changes: 38 additions & 18 deletions spyder/widgets/variableexplorer/tests/test_arrayeditor.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# -*- coding: utf-8 -*-
#
# -----------------------------------------------------------------------------
# Copyright © Spyder Project Contributors
#
# Licensed under the terms of the MIT License
# (see spyder/__init__.py for details)
# -----------------------------------------------------------------------------

"""
Tests for arrayeditor.py
Tests for the array editor.
"""

# Standard library imports
Expand All @@ -26,28 +29,35 @@
from spyder.widgets.variableexplorer.arrayeditor import ArrayEditor, ArrayModel


# =============================================================================
# Utility functions
# =============================================================================
def launch_arrayeditor(data, title="", xlabels=None, ylabels=None):
"""Helper routine to launch an arrayeditor and return its result"""
"""Helper routine to launch an arrayeditor and return its result."""
dlg = ArrayEditor()
assert dlg.setup_and_check(data, title, xlabels=xlabels, ylabels=ylabels)
dlg.show()
dlg.accept() # trigger slot connected to OK button
return dlg.get_value()


def setup_arrayeditor(qbot, data, title="", xlabels=None, ylabels=None):
"""Setups an arrayeditor."""
dlg = ArrayEditor()
dlg.setup_and_check(data, title, xlabels=xlabels, ylabels=ylabels)
dlg.setup_and_check(data, title, xlabels=xlabels, ylabels=ylabels)
dlg.show()
qbot.addWidget(dlg)
return dlg

# --- Tests
# -----------------------------------------------------------------------------

# =============================================================================
# Tests
# =============================================================================
def test_type_errors(qtbot):
"""Verify that we don't get a TypeError for certain structured arrays.
"""
Verify that we don't get a TypeError for certain structured arrays.

Fixes issue 5254.
Fixes issue #5254.
"""
arr = np.ones(2, dtype=[('X', 'f8', (2,10)), ('S', 'S10')])
dlg = setup_arrayeditor(qtbot, arr)
Expand Down Expand Up @@ -186,7 +196,11 @@ def test_arrayeditor_edit_2d_array(qtbot):


def test_arraymodel_set_data_overflow(monkeypatch):
"""Unit test #6114: entry of an overflow int caught and handled properly"""
"""
Test that entry of an overflowing integer is caught and handled properly.

Unit regression test for #6114 .
"""
MockQMessageBox = Mock()
attr_to_patch = 'spyder.widgets.variableexplorer.arrayeditor.QMessageBox'
monkeypatch.setattr(attr_to_patch, MockQMessageBox)
Expand All @@ -210,7 +224,11 @@ def test_arraymodel_set_data_overflow(monkeypatch):

@flaky(max_runs=3)
def test_arrayeditor_edit_overflow(qtbot, monkeypatch):
"""Int. test #6114: entry of an overflow int caught and handled properly"""
"""
Test that entry of an overflowing integer is caught and handled properly.

Integration regression test for #6114 .
"""
MockQMessageBox = Mock()
attr_to_patch = 'spyder.widgets.variableexplorer.arrayeditor.QMessageBox'
monkeypatch.setattr(attr_to_patch, MockQMessageBox)
Expand All @@ -232,20 +250,22 @@ def test_arrayeditor_edit_overflow(qtbot, monkeypatch):
qtbot.waitForWindowShown(dialog)
view = dialog.arraywidget.view

qtbot.keyPress(view, Qt.Key_Down)
qtbot.keyPress(view, Qt.Key_Up)
qtbot.keyClick(view, Qt.Key_Down)
qtbot.keyClick(view, Qt.Key_Up)
qtbot.keyClicks(view, '5')
qtbot.keyPress(view, Qt.Key_Down)
qtbot.keyPress(view, Qt.Key_Space)
qtbot.keyClick(view, Qt.Key_Down)
qtbot.keyClick(view, Qt.Key_Space)
qtbot.keyClicks(view.focusWidget(), str(int(2 ** bit_exponent)))
qtbot.keyPress(view.focusWidget(), Qt.Key_Down)
qtbot.keyClick(view.focusWidget(), Qt.Key_Down)
MockQMessageBox.critical.assert_called_with(ANY, "Error", ANY)
assert MockQMessageBox.critical.call_count == idx
qtbot.keyClicks(view, '7')
qtbot.keyPress(view, Qt.Key_Up)
qtbot.keyClick(view, Qt.Key_Up)
qtbot.keyClicks(view, '6')
qtbot.keyPress(view, Qt.Key_Down)
qtbot.keyPress(view, Qt.Key_Return)
qtbot.keyClick(view, Qt.Key_Down)
qtbot.wait(200)
dialog.accept()
qtbot.wait(500)
assert np.sum(expected_array ==
dialog.get_value()) == len(expected_array)

Expand Down
Loading