Skip to content

Commit

Permalink
More tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dalthviz committed Feb 24, 2017
1 parent 963f65f commit 2388b21
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 51 deletions.
44 changes: 0 additions & 44 deletions spyder/utils/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@

# Third party imports
import pytest
from qtpy.QtWidgets import QMainWindow

# Local imports
from spyder.widgets.explorer import FileExplorerTest, ProjectExplorerTest
from spyder.widgets.editor import EditorStack
from spyder.widgets.findreplace import FindReplace
from spyder.widgets.pathmanager import PathManager
from spyder.widgets.browser import WebBrowser
from spyder.config.user import UserConfig
from spyder.config.main import CONF_VERSION, DEFAULTS

Expand Down Expand Up @@ -70,43 +66,3 @@ def setup_editor(qtbot):
finfo = editorStack.new('foo.py', 'utf-8', text)
qtbot.addWidget(editorStack)
return editorStack, finfo.editor

@pytest.fixture
def setup_browser(qtbot):
"""Set up WebBrowser."""
widget = WebBrowser()
qtbot.addWidget(widget)
return widget

@pytest.fixture
def setup_file_explorer(qtbot):
"""Set up FileExplorerTest."""
widget = FileExplorerTest()
qtbot.addWidget(widget)
return widget

@pytest.fixture
def setup_project_explorer(qtbot):
"""Set up FileExplorerTest."""
widget = ProjectExplorerTest()
qtbot.addWidget(widget)
return widget

@pytest.fixture
def setup_pathmanager(qtbot, parent=None, pathlist=None, ro_pathlist=None,
sync=True):
"""Set up PathManager."""
widget = PathManager(None, pathlist=pathlist, ro_pathlist=ro_pathlist)
qtbot.addWidget(widget)
return widget

@pytest.fixture
def setup_status_bar(qtbot):
"""Set up StatusBarWidget."""
win = QMainWindow()
win.setWindowTitle("Status widgets test")
win.resize(900, 300)
statusbar = win.statusBar()
qtbot.addWidget(win)
return (win, statusbar)

4 changes: 2 additions & 2 deletions spyder/widgets/projects/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def delete_project(self):
#==============================================================================
# Tests
#==============================================================================
class Test(QWidget):
class ProjectExplorerTest(QWidget):
def __init__(self):
QWidget.__init__(self)
vlayout = QVBoxLayout()
Expand Down Expand Up @@ -293,7 +293,7 @@ def __init__(self):
def test():
from spyder.utils.qthelpers import qapplication
app = qapplication()
test = Test()
test = ProjectExplorerTest()
test.resize(250, 480)
test.show()
app.exec_()
Expand Down
40 changes: 40 additions & 0 deletions spyder/widgets/projects/tests/test_configdialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
#

"""
Tests for configdialog.py
"""

# Standard librery imports
import os.path as osp
import tempfile

# Test library imports
import pytest

# Local imports
from spyder.widgets.projects.configdialog import (EmptyProject,
ProjectPreferences)

@pytest.fixture
def setup_projects_preferences(qtbot):
"""Set up ProjectPreferences."""
project_dir = tempfile.mkdtemp() + osp.sep + '.spyproject'
project = EmptyProject(project_dir)
project_preferences = ProjectPreferences(None, project)
qtbot.addWidget(project_preferences)
return (project, project_preferences)

def test_projects_preferences(qtbot):
"""Run Project Preferences."""
project, preferences = setup_projects_preferences(qtbot)
preferences.resize(250, 480)
preferences.show()
assert preferences


if __name__ == "__main__":
pytest.main()
33 changes: 33 additions & 0 deletions spyder/widgets/projects/tests/test_project_explorer.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 explorer.py
"""

# Test library imports
import pytest

# Local imports
from spyder.widgets.projects.explorer import ProjectExplorerTest

@pytest.fixture
def setup_projects_explorer(qtbot):
"""Set up ProjectExplorerWidgetTest."""
project_explorer = ProjectExplorerTest()
qtbot.addWidget(project_explorer)
return project_explorer

def test_project_explorer(qtbot):
"""Run project explorer."""
project_explorer = setup_projects_explorer(qtbot)
project_explorer.resize(250, 480)
project_explorer.show()
assert project_explorer


if __name__ == "__main__":
pytest.main()
32 changes: 32 additions & 0 deletions spyder/widgets/projects/tests/test_projectdialog.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 projectdialog.py
"""

# Test library imports
import pytest

# Local imports
from spyder.widgets.projects.projectdialog import ProjectDialog

@pytest.fixture
def setup_projects_dialog(qtbot):
"""Set up ProjectDialog."""
dlg = ProjectDialog(None)
qtbot.addWidget(dlg)
return dlg

def test_project_dialog(qtbot):
"""Run project dialog."""
dlg = setup_projects_dialog(qtbot)
dlg.show()
assert dlg


if __name__ == "__main__":
pytest.main()
11 changes: 9 additions & 2 deletions spyder/widgets/tests/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@
import pytest

# Local imports
from spyder.utils.fixtures import setup_browser
from spyder.widgets.browser import WebBrowser

@pytest.fixture
def setup_browser(qtbot):
"""Set up WebBrowser."""
widget = WebBrowser()
qtbot.addWidget(widget)
return widget

def test_browser(qtbot):
"""Run web browser"""
"""Run web browser."""
browser = setup_browser(qtbot)
browser.set_home_url('http://www.google.com/')
browser.go_home()
Expand Down
16 changes: 15 additions & 1 deletion spyder/widgets/tests/test_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,21 @@
import pytest

# Local imports
from spyder.utils.fixtures import setup_file_explorer, setup_project_explorer
from spyder.widgets.explorer import FileExplorerTest, ProjectExplorerTest

@pytest.fixture
def setup_file_explorer(qtbot):
"""Set up FileExplorerTest."""
widget = FileExplorerTest()
qtbot.addWidget(widget)
return widget

@pytest.fixture
def setup_project_explorer(qtbot):
"""Set up FileExplorerTest."""
widget = ProjectExplorerTest()
qtbot.addWidget(widget)
return widget

def test_file_explorer(qtbot):
"""Run FileExplorerTest."""
Expand Down
10 changes: 9 additions & 1 deletion spyder/widgets/tests/test_pathmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@
import pytest

# Local imports
from spyder.utils.fixtures import setup_pathmanager
from spyder.widgets.pathmanager import PathManager

@pytest.fixture
def setup_pathmanager(qtbot, parent=None, pathlist=None, ro_pathlist=None,
sync=True):
"""Set up PathManager."""
widget = PathManager(None, pathlist=pathlist, ro_pathlist=ro_pathlist)
qtbot.addWidget(widget)
return widget

def test_pathmanager(qtbot):
"""Run PathManager test"""
Expand Down
14 changes: 13 additions & 1 deletion spyder/widgets/tests/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,24 @@
# Test library imports
import pytest

# Thrid party imports
from qtpy.QtWidgets import QMainWindow

# Local imports
from spyder.utils.fixtures import setup_status_bar
from spyder.widgets.status import (ReadWriteStatus, EOLStatus, EncodingStatus,
CursorPositionStatus, MemoryStatus,
CPUStatus)

@pytest.fixture
def setup_status_bar(qtbot):
"""Set up StatusBarWidget."""
win = QMainWindow()
win.setWindowTitle("Status widgets test")
win.resize(900, 300)
statusbar = win.statusBar()
qtbot.addWidget(win)
return (win, statusbar)

def test_status_bar(qtbot):
"""Run StatusBarWidget."""
win, statusbar = setup_status_bar(qtbot)
Expand Down
33 changes: 33 additions & 0 deletions spyder/widgets/variableexplorer/tests/test_importwizard.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 importwizard.py
"""

# Test library imports
import pytest

# Local imports
from spyder.widgets.variableexplorer.importwizard import ImportWizard

@pytest.fixture
def setup_importwizard(qtbot, text):
"""Set up ImportWizard."""
importwizard = ImportWizard(None, text)
qtbot.addWidget(importwizard)
return importwizard

def test_importwizard(qtbot):
"""Run ImportWizard dialog."""
text = u"17/11/1976\t1.34\n14/05/09\t3.14"
importwizard = setup_importwizard(qtbot, text)
importwizard.show()
assert importwizard


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

"""
Tests for texteditor.py
"""

# Test library imports
import pytest

# Local imports
from spyder.widgets.variableexplorer.texteditor import TextEditor

@pytest.fixture
def setup_texteditor(qtbot, text):
"""Set up TextEditor."""
texteditor = TextEditor(text)
qtbot.addWidget(texteditor)
return texteditor

def test_texteditor(qtbot):
"""Run TextEditor dialog."""
text = """01234567890123456789012345678901234567890123456789012345678901234567890123456789
dedekdh elkd ezd ekjd lekdj elkdfjelfjk e"""
texteditor = setup_texteditor(qtbot, text)
texteditor.show()
assert texteditor
dlg_text = texteditor.get_value()
assert text == dlg_text


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

0 comments on commit 2388b21

Please sign in to comment.