diff --git a/spyder_unittest/backend/runnerbase.py b/spyder_unittest/backend/runnerbase.py index 13c815e5..d946e18a 100644 --- a/spyder_unittest/backend/runnerbase.py +++ b/spyder_unittest/backend/runnerbase.py @@ -10,14 +10,9 @@ import tempfile # Third party imports +from importlib.util import find_spec as find_spec_or_loader from qtpy.QtCore import (QObject, QProcess, QProcessEnvironment, QTextCodec, Signal) -from spyder.py3compat import to_text_string - -try: - from importlib.util import find_spec as find_spec_or_loader -except ImportError: # Python 2 - from pkgutil import find_loader as find_spec_or_loader # if generating coverage report, use this name for the TestResult @@ -244,7 +239,7 @@ def read_all_process_output(self): """Read and return all output from `self.process` as unicode.""" qbytearray = self.process.readAllStandardOutput() locale_codec = QTextCodec.codecForLocale() - return to_text_string(locale_codec.toUnicode(qbytearray.data())) + return locale_codec.toUnicode(qbytearray.data()) def stop_if_running(self): """Stop testing process if it is running.""" diff --git a/spyder_unittest/backend/tests/test_pytestrunner.py b/spyder_unittest/backend/tests/test_pytestrunner.py index c5d9aad5..19804ff4 100644 --- a/spyder_unittest/backend/tests/test_pytestrunner.py +++ b/spyder_unittest/backend/tests/test_pytestrunner.py @@ -9,6 +9,7 @@ import os import os.path as osp import sys +from unittest.mock import Mock # Third party imports import pytest @@ -20,11 +21,6 @@ COV_TEST_NAME) from spyder_unittest.widgets.configdialog import Config -try: - from unittest.mock import Mock -except ImportError: - from mock import Mock # Python 2 - def test_pytestrunner_is_installed(): assert PyTestRunner(None).is_installed() diff --git a/spyder_unittest/backend/tests/test_pytestworker.py b/spyder_unittest/backend/tests/test_pytestworker.py index 0446db0e..978e1401 100644 --- a/spyder_unittest/backend/tests/test_pytestworker.py +++ b/spyder_unittest/backend/tests/test_pytestworker.py @@ -7,6 +7,7 @@ # Standard library imports import os +from unittest.mock import call, create_autospec, MagicMock, Mock # Third party imports import pytest @@ -15,11 +16,6 @@ from spyder_unittest.backend.pytestworker import SpyderPlugin, main from spyder_unittest.backend.zmqstream import ZmqStreamWriter -try: - from unittest.mock import call, create_autospec, MagicMock, Mock -except ImportError: - from mock import call, create_autospec, MagicMock, Mock # Python 2 - class EmptyClass: pass diff --git a/spyder_unittest/backend/tests/test_runnerbase.py b/spyder_unittest/backend/tests/test_runnerbase.py index 4443f794..3e121691 100644 --- a/spyder_unittest/backend/tests/test_runnerbase.py +++ b/spyder_unittest/backend/tests/test_runnerbase.py @@ -7,6 +7,7 @@ # Standard library imports import os +from unittest.mock import Mock # Third party imports import pytest @@ -15,11 +16,6 @@ from spyder_unittest.backend.runnerbase import RunnerBase from spyder_unittest.widgets.configdialog import Config -try: - from unittest.mock import Mock -except ImportError: - from mock import Mock # Python 2 - def test_runnerbase_with_nonexisting_module(): class FooRunner(RunnerBase): diff --git a/spyder_unittest/backend/zmqstream.py b/spyder_unittest/backend/zmqstream.py index a764440f..d394476e 100644 --- a/spyder_unittest/backend/zmqstream.py +++ b/spyder_unittest/backend/zmqstream.py @@ -11,8 +11,6 @@ process can then use the stream to send its result to the reader. """ -from __future__ import print_function - # Standard library imports import sys @@ -68,7 +66,7 @@ class ZmqStreamReader(QObject): def __init__(self): """Constructor; also constructs ZMQ stream.""" - super(QObject, self).__init__() + super().__init__() self.context = zmq.Context() self.socket = self.context.socket(zmq.PAIR) self.port = self.socket.bind_to_random_port('tcp://*') diff --git a/spyder_unittest/tests/test_unittestplugin.py b/spyder_unittest/tests/test_unittestplugin.py index 9201bd36..b73e369c 100644 --- a/spyder_unittest/tests/test_unittestplugin.py +++ b/spyder_unittest/tests/test_unittestplugin.py @@ -8,16 +8,12 @@ # Third party imports import pytest from spyder.plugins.projects.api import EmptyProject +from unittest.mock import MagicMock # Local imports from spyder_unittest.unittestplugin import UnitTestPlugin from spyder_unittest.widgets.configdialog import Config -try: - from unittest.mock import MagicMock -except ImportError: - from mock import MagicMock # Python 2 - class PluginForTesting(UnitTestPlugin): CONF_FILE = False diff --git a/spyder_unittest/unittestplugin.py b/spyder_unittest/unittestplugin.py index de6389b6..43a72969 100644 --- a/spyder_unittest/unittestplugin.py +++ b/spyder_unittest/unittestplugin.py @@ -6,6 +6,7 @@ """Unit testing Plugin.""" # Standard library imports +from os import getcwd import os.path as osp # Third party imports @@ -14,7 +15,6 @@ from spyder.config.base import get_translation from spyder.config.gui import is_dark_interface from spyder.plugins.mainmenu.api import ApplicationMenus -from spyder.py3compat import PY2, getcwd # Local imports from spyder_unittest.widgets.configdialog import Config @@ -98,30 +98,6 @@ def on_initialize(self): register_shortcut=True) # TODO: shortcut="Shift+Alt+F11" - # --- Optional SpyderDockablePlugin methods ------------------------------- - - @staticmethod - def check_compatibility(): - """ - Check compatibility of the plugin. - - This checks that the plugin is not run under Python 2. - - Returns - ------- - (bool, str) - The first value tells Spyder if the plugin has passed the - compatibility test defined in this method. The second value - is a message that must explain users why the plugin was - found to be incompatible (e.g. 'This plugin does not work - with PyQt4'). It will be shown at startup in a QMessageBox. - """ - if PY2: - msg = _('The unittest plugin does not work with Python 2.') - return (False, msg) - else: - return (True, '') - # ----- Set up interactions with other plugins ---------------------------- @on_plugin_available(plugin=Plugins.Editor) diff --git a/spyder_unittest/widgets/configdialog.py b/spyder_unittest/widgets/configdialog.py index 8b0575c7..7c40be5d 100644 --- a/spyder_unittest/widgets/configdialog.py +++ b/spyder_unittest/widgets/configdialog.py @@ -11,6 +11,8 @@ # Standard library imports from collections import namedtuple +from os import getcwd +from pkgutil import find_loader as find_spec_or_loader import os.path as osp # Third party imports @@ -20,13 +22,8 @@ QHBoxLayout, QLabel, QLineEdit, QPushButton, QVBoxLayout, QCheckBox) from spyder.config.base import get_translation -from spyder.py3compat import getcwd, to_text_string from spyder.utils import icon_manager as ima -try: - from importlib.util import find_spec as find_spec_or_loader -except ImportError: # Python 2 - from pkgutil import find_loader as find_spec_or_loader try: _ = get_translation('spyder_unittest') @@ -62,7 +59,7 @@ def __init__(self, frameworks, config, parent=None): Initial configuration parent : QWidget """ - super(ConfigDialog, self).__init__(parent) + super().__init__(parent) self.setWindowTitle(_('Configure tests')) layout = QVBoxLayout(self) @@ -145,7 +142,7 @@ def framework_changed(self, index): def select_directory(self): """Display dialog for user to select working directory.""" - basedir = to_text_string(self.wdir_lineedit.text()) + basedir = self.wdir_lineedit.text() if not osp.isdir(basedir): basedir = getcwd() title = _("Select directory") diff --git a/spyder_unittest/widgets/tests/test_datatree.py b/spyder_unittest/widgets/tests/test_datatree.py index a080788c..fc42f470 100644 --- a/spyder_unittest/widgets/tests/test_datatree.py +++ b/spyder_unittest/widgets/tests/test_datatree.py @@ -8,6 +8,7 @@ # Third party imports from qtpy.QtCore import QModelIndex, QPoint, Qt from qtpy.QtGui import QContextMenuEvent +from unittest.mock import Mock import pytest # Local imports @@ -15,11 +16,6 @@ from spyder_unittest.widgets.datatree import (COLORS, COLORS_DARK, TestDataModel, TestDataView) -try: - from unittest.mock import Mock -except ImportError: - from mock import Mock # Python 2 - @pytest.fixture def view_and_model(qtbot): diff --git a/spyder_unittest/widgets/tests/test_unittestgui.py b/spyder_unittest/widgets/tests/test_unittestgui.py index 78ec7c5a..57d38dbf 100644 --- a/spyder_unittest/widgets/tests/test_unittestgui.py +++ b/spyder_unittest/widgets/tests/test_unittestgui.py @@ -8,6 +8,7 @@ # Standard library imports import os import sys +from unittest.mock import Mock # Third party imports from qtpy.QtCore import Qt, QProcess @@ -19,11 +20,6 @@ from spyder_unittest.widgets.configdialog import Config from spyder_unittest.widgets.unittestgui import UnitTestWidget -try: - from unittest.mock import Mock -except ImportError: - from mock import Mock # Python 2 - @pytest.fixture def widget(qtbot): diff --git a/spyder_unittest/widgets/unittestgui.py b/spyder_unittest/widgets/unittestgui.py index fceea8b9..f5155f6b 100644 --- a/spyder_unittest/widgets/unittestgui.py +++ b/spyder_unittest/widgets/unittestgui.py @@ -5,8 +5,6 @@ # (see LICENSE.txt for details) """Unit Testing widget.""" -from __future__ import with_statement - # Standard library imports import copy import os.path as osp @@ -19,22 +17,16 @@ from spyder.config.base import get_conf_path, get_translation from spyder.utils import icon_manager as ima from spyder.plugins.variableexplorer.widgets.texteditor import TextEditor -from spyder.py3compat import PY3 # Local imports from spyder_unittest.backend.frameworkregistry import FrameworkRegistry from spyder_unittest.backend.noserunner import NoseRunner +from spyder_unittest.backend.pytestrunner import PyTestRunner from spyder_unittest.backend.runnerbase import Category, TestResult from spyder_unittest.backend.unittestrunner import UnittestRunner from spyder_unittest.widgets.configdialog import Config, ask_for_config from spyder_unittest.widgets.datatree import TestDataModel, TestDataView -# This import uses Python 3 syntax, so importing it under Python 2 throws -# a SyntaxError which means that the plugin's check_compatibility method -# will never run. -if PY3: - from spyder_unittest.backend.pytestrunner import PyTestRunner - # This is needed for testing this module as a stand alone script try: _ = get_translation('spyder_unittest') @@ -42,11 +34,8 @@ import gettext _ = gettext.gettext -# Supported testing framework -if PY3: - FRAMEWORKS = {NoseRunner, PyTestRunner, UnittestRunner} -else: - FRAMEWORKS = {NoseRunner, UnittestRunner} +# Supported testing frameworks +FRAMEWORKS = {NoseRunner, PyTestRunner, UnittestRunner} class UnitTestWidgetActions: