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: Move all tests to be pytest's #4199

Merged
merged 22 commits into from
Mar 13, 2017
Merged
Show file tree
Hide file tree
Changes from 19 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
32 changes: 32 additions & 0 deletions spyder/app/tests/test_tour.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
#

"""
Tests for tour.py
"""

# Test library imports
import pytest

# Local imports
from spyder.app.tour import TourTestWindow

@pytest.fixture
def setup_tour(qtbot):
"Setup the QMainWindow for the tour."
tour = TourTestWindow()
qtbot.addWidget(tour)
return tour

def test_tour(qtbot):
"""Test tour."""
tour = setup_tour(qtbot)
tour.show()
assert tour


if __name__ == "__main__":
pytest.main()
8 changes: 4 additions & 4 deletions spyder/app/tour.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,13 +1271,13 @@ def any_has_focus(self):
# Used for testing the functionality


class TestWindow(QMainWindow):
class TourTestWindow(QMainWindow):
""" """
sig_resized = Signal("QResizeEvent")
sig_moved = Signal("QMoveEvent")

def __init__(self):
super(TestWindow, self).__init__()
super(TourTestWindow, self).__init__()
self.setGeometry(300, 100, 400, 600)
self.setWindowTitle('Exploring QMainWindow')

Expand All @@ -1301,7 +1301,7 @@ def __init__(self):

effect = QGraphicsOpacityEffect(self.button2)
self.button2.setGraphicsEffect(effect)
self.anim = QPropertyAnimation(effect, "opacity")
self.anim = QPropertyAnimation(effect, to_binary_string("opacity"))
self.anim.setStartValue(0.01)
self.anim.setEndValue(1.0)
self.anim.setDuration(500)
Expand Down Expand Up @@ -1346,7 +1346,7 @@ def moveEvent(self, event):
def test():
""" """
app = QApplication([])
win = TestWindow()
win = TourTestWindow()
win.show()
app.exec_()

Expand Down
13 changes: 3 additions & 10 deletions spyder/plugins/tests/test_ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
from flaky import flaky
import pytest
from qtpy.QtCore import Qt, QTimer
from qtpy.QtWidgets import QApplication, QMessageBox
from qtpy.QtWidgets import QApplication

from spyder.plugins.ipythonconsole import (IPythonConsole,
KernelConnectionDialog)

from spyder.utils.tests import close_message_box

#==============================================================================
# Constants
Expand All @@ -35,13 +35,6 @@ def open_client_from_connection_info(connection_info, qtbot):
qtbot.keyClick(w, Qt.Key_Enter)


def restart_kernel(qtbot):
top_level_widgets = QApplication.topLevelWidgets()
for w in top_level_widgets:
if isinstance(w, QMessageBox):
qtbot.keyClick(w, Qt.Key_Enter)


#==============================================================================
# Qt Test Fixtures
#==============================================================================
Expand Down Expand Up @@ -104,7 +97,7 @@ def test_restart_kernel(ipyconsole, qtbot):

# Restart kernel and wait until it's up again
shell._prompt_html = None
QTimer.singleShot(1000, lambda: restart_kernel(qtbot))
QTimer.singleShot(1000, lambda: close_message_box(qtbot))
client.restart_kernel()
qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT)

Expand Down
50 changes: 50 additions & 0 deletions spyder/plugins/tests/test_layoutdialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
#

"""
Tests for layoutdialog.py
"""

# Test library imports
import pytest

# Local imports
from spyder.plugins.layoutdialog import LayoutSettingsDialog, LayoutSaveDialog

@pytest.fixture
def setup_layout_settings_dialog(qtbot, parent, names, order, active):
"""Set up LayoutSettingsDialog."""
widget = LayoutSettingsDialog(parent, names, order, active)
qtbot.addWidget(widget)
return widget

@pytest.fixture
def setup_layout_save_dialog(qtbot, parent, order):
"""Set up LayoutSaveDialog."""
widget = LayoutSaveDialog(parent, order)
qtbot.addWidget(widget)
return widget

def test_layout_settings_dialog(qtbot):
"""Run layout settings dialog."""
names = ['test', 'tester', '20', '30', '40']
order = ['test', 'tester', '20', '30', '40']
active = ['test', 'tester']
layout_settings_dlg = setup_layout_settings_dialog(qtbot, None, names,
order, active)
layout_settings_dlg.show()
assert layout_settings_dlg

def test_layout_save_dialog(qtbot):
"""Run layout save dialog."""
order = ['test', 'tester', '20', '30', '40']
layout_save_dlg = setup_layout_save_dialog(qtbot, None, order)
layout_save_dlg.show()
assert layout_save_dlg


if __name__ == "__main__":
pytest.main()
33 changes: 33 additions & 0 deletions spyder/plugins/tests/test_shorcuts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
#

"""
Tests for shortcuts.py
"""

# Test library imports
import pytest

# Local imports
from spyder.plugins.shortcuts import ShortcutsTable

@pytest.fixture
def setup_shorcuts(qtbot):
"""Set up shortcuts."""
widget = ShortcutsTable()
qtbot.addWidget(widget)
return widget

def test_shortcuts(qtbot):
"""Run shortcuts table."""
shortcuts = setup_shorcuts(qtbot)
shortcuts.show()
shortcuts.check_shortcuts()
assert shortcuts


if __name__ == "__main__":
pytest.main()
1 change: 0 additions & 1 deletion spyder/utils/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# Third party imports
import pytest

# Local imports
# Local imports
from spyder.widgets.editor import EditorStack
from spyder.widgets.findreplace import FindReplace
Expand Down
92 changes: 0 additions & 92 deletions spyder/utils/introspection/fallback_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,95 +305,3 @@ def _complete_path(path=None):
return [p for p in _listdir(path)]
# exact file match terminates this completion
return [path + ' ']


if __name__ == '__main__':
from spyder.utils.introspection.manager import CodeInfo

p = FallbackPlugin()

with open(__file__, 'rb') as fid:
code = fid.read().decode('utf-8')
code += '\nlog_dt'

path, line = p.get_definition(CodeInfo('definition', code, len(code),
__file__, is_python_like=True))
assert path.endswith('fallback_plugin.py')

code += '\np.get_completions'
path, line = p.get_definition(CodeInfo('definition', code, len(code),
'dummy.py', is_python_like=True))
assert path == 'dummy.py'
assert 'def get_completions(' in code.splitlines()[line - 1]

code += '\npython_like_mod_finder'
path, line = p.get_definition(CodeInfo('definition', code, len(code),
'dummy.py', is_python_like=True))
assert path == 'dummy.py'
# FIXME: we need to prioritize def over =
assert 'def python_like_mod_finder' in code.splitlines()[line - 1]

code += 'python_like_mod_finder'
resp = p.get_definition(CodeInfo('definition', code, len(code),
'dummy.py'))
assert resp is None

code = """
class Test(object):
def __init__(self):
self.foo = bar

t = Test()
t.foo"""
path, line = p.get_definition(CodeInfo('definition', code, len(code),
'dummy.py', is_python_like=True))
assert line == 4

ext = python_like_exts()
assert '.py' in ext and '.pyx' in ext

ext = all_editable_exts()
assert '.cpp' in ext and '.html' in ext

path = get_parent_until(os.path.abspath(__file__))
assert path == 'spyder.utils.introspection.fallback_plugin'

line = 'from spyder.widgets.sourcecode.codeeditor import CodeEditor'
path = python_like_mod_finder(line)
assert path.endswith('codeeditor.py')
path = python_like_mod_finder(line, stop_token='sourcecode')
assert path.endswith('__init__.py') and 'sourcecode' in path

path = osp.expanduser(r'~/.spyder2/temp.py')
if os.path.exists(path):
path = get_parent_until(path)
assert path == '.spyder2.temp', path

code = 'import re\n\nre'
path, line = p.get_definition(CodeInfo('definition', code, len(code),
'dummy.py', is_python_like=True))
assert path == 'dummy.py' and line == 1

code = 'self.proxy.widget; self.p'
comp = p.get_completions(CodeInfo('completions', code, len(code), 'dummy.py'))
assert ('proxy', '') in comp, comp

code = 'self.sigMessageReady.emit; self.s'
comp = p.get_completions(CodeInfo('completions', code, len(code), 'dummy.py'))
assert ('sigMessageReady', '') in comp

code = 'bob = 1; bo'
comp = p.get_completions(CodeInfo('completions', code, len(code), 'dummy.m'))
assert ('bob', '') in comp

code = 'functi'
comp = p.get_completions(CodeInfo('completions', code, len(code), 'dummy.sh'))
assert ('function', '') in comp, comp

code = '''
def test(a, b):
pass
test(1,'''
path, line = p.get_definition(CodeInfo('definition', code, len(code),
'dummy.py', is_python_like=True))
assert line == 2
39 changes: 0 additions & 39 deletions spyder/utils/introspection/module_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,42 +293,3 @@ def get_preferred_submodules():

modules_db['submodules'] = submodules
return submodules

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

if __name__ == "__main__":
# Some simple tests.
# Sort operations are done by the completion widget, so we have to
# replicate them here.
# We've chosen to use xml on most tests because it's on the standard
# library. This way we can ensure they work on all plataforms.

assert sorted(module_completion('import xml.')) == \
['xml.dom', 'xml.etree', 'xml.parsers', 'xml.sax']

assert sorted(module_completion('import xml.d')) == ['xml.dom']

assert module_completion('from xml.etree ') == ['import ']

assert sorted(module_completion('from xml.etree import '), key=str.lower) ==\
['cElementTree', 'ElementInclude', 'ElementPath', 'ElementTree']

assert module_completion('import sys, zl') == ['zlib']

s = 'from xml.etree.ElementTree import '
assert module_completion(s + 'V') == ['VERSION']

if PY3:
assert sorted(module_completion(s + 'VERSION, XM')) == \
['XML', 'XMLID', 'XMLParser', 'XMLPullParser']
else:
assert sorted(module_completion(s + 'VERSION, XM')) == \
['XML', 'XMLID', 'XMLParser', 'XMLTreeBuilder']

assert module_completion(s + '(dum') == ['dump']

assert module_completion(s + '(dump, Su') == ['SubElement']

assert 'os.path' in get_preferred_submodules()
Loading