diff --git a/Framework/PythonInterface/test/python/mantid/api/AnalysisDataServiceObserverTest.py b/Framework/PythonInterface/test/python/mantid/api/AnalysisDataServiceObserverTest.py index 2a7cba7cf4bd18ed4128ec0d0eede570249863db..07e6e022a3271a60182cf5fb5368fc44d44a4f08 100644 --- a/Framework/PythonInterface/test/python/mantid/api/AnalysisDataServiceObserverTest.py +++ b/Framework/PythonInterface/test/python/mantid/api/AnalysisDataServiceObserverTest.py @@ -9,17 +9,10 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) import unittest -import sys from mantid.api import AnalysisDataService as ADS, AnalysisDataServiceObserver from mantid.simpleapi import CreateSampleWorkspace, RenameWorkspace, GroupWorkspaces, UnGroupWorkspace, DeleteWorkspace - -if sys.version_info.major >= 3: - # Python 3 and above - from unittest import mock -else: - # Python 2 - import mock +from mantid.py3compat import mock class FakeADSObserver(AnalysisDataServiceObserver): diff --git a/Framework/PythonInterface/test/python/mantid/kernel/ConfigObserverTest.py b/Framework/PythonInterface/test/python/mantid/kernel/ConfigObserverTest.py index 9060ccdb147feabf589a0aae3c3fb54bc8a202ab..6fa2304492e756980acb734003aa7c7220b49f14 100644 --- a/Framework/PythonInterface/test/python/mantid/kernel/ConfigObserverTest.py +++ b/Framework/PythonInterface/test/python/mantid/kernel/ConfigObserverTest.py @@ -5,13 +5,9 @@ # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + import unittest -import sys -from mantid.kernel import ConfigService, ConfigObserver -if sys.version_info.major == 2: - import mock -else: - from unittest import mock +from mantid.kernel import ConfigService, ConfigObserver +from mantid.py3compat import mock class ConfigObserverTest(unittest.TestCase): diff --git a/Framework/PythonInterface/test/python/mantid/kernel/ConfigPropertyObserverTest.py b/Framework/PythonInterface/test/python/mantid/kernel/ConfigPropertyObserverTest.py index 8ef3d840a37e2acd46d3b74f7aaeb2843115bd3c..771035fc2a236e19e2242b3e58e83544ebb1037a 100644 --- a/Framework/PythonInterface/test/python/mantid/kernel/ConfigPropertyObserverTest.py +++ b/Framework/PythonInterface/test/python/mantid/kernel/ConfigPropertyObserverTest.py @@ -5,13 +5,9 @@ # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + import unittest -import sys -from mantid.kernel import ConfigService, ConfigPropertyObserver -if sys.version_info.major == 2: - import mock -else: - from unittest import mock +from mantid.kernel import ConfigService, ConfigPropertyObserver +from mantid.py3compat import mock class ConfigObserverTest(unittest.TestCase): diff --git a/Framework/PythonInterface/test/python/mantid/plots/helperfunctionsTest.py b/Framework/PythonInterface/test/python/mantid/plots/helperfunctionsTest.py index 70c5a734e7fe088a597dbedf92ae308cca6631a8..e137df92f23448d73661154c558cd70265a2ae39 100644 --- a/Framework/PythonInterface/test/python/mantid/plots/helperfunctionsTest.py +++ b/Framework/PythonInterface/test/python/mantid/plots/helperfunctionsTest.py @@ -12,10 +12,10 @@ import unittest import matplotlib import numpy as np -from mock import Mock import mantid.api import mantid.plots.helperfunctions as funcs +from mantid.py3compat.mock import Mock from mantid.kernel import config from mantid.plots.utility import MantidAxType from mantid.simpleapi import AddTimeSeriesLog, ConjoinWorkspaces, CreateMDHistoWorkspace, CreateSampleWorkspace, \ diff --git a/Testing/SystemTests/tests/analysis/ErrorReporterServerTest.py b/Testing/SystemTests/tests/analysis/ErrorReporterServerTest.py index fd54cd1b95f3a993b0e1026a56488d4d7726e097..6a9ab9e04f4d7646534a87d0778605cef8c44f55 100644 --- a/Testing/SystemTests/tests/analysis/ErrorReporterServerTest.py +++ b/Testing/SystemTests/tests/analysis/ErrorReporterServerTest.py @@ -4,16 +4,10 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + - -import sys +from mantid.py3compat import mock import systemtesting from ErrorReporter.error_report_presenter import ErrorReporterPresenter # noqa -if sys.version_info.major < 3: - import mock -else: - from unittest import mock - class ErrorReportServerTests(systemtesting.MantidSystemTest): def setUp(self): diff --git a/dev-docs/source/MVPTutorial/Mocking.rst b/dev-docs/source/MVPTutorial/Mocking.rst index 30d902219d33b74a43699d1ee9447a13bd17612c..3079097546039c75235816bd96efec0c0fd85a20 100644 --- a/dev-docs/source/MVPTutorial/Mocking.rst +++ b/dev-docs/source/MVPTutorial/Mocking.rst @@ -22,10 +22,7 @@ First are the import statements import view import unittest - if sys.version_info.major == 3: - from unittest import mock - else: - import mock + from mantid.py3compat import mock A different import is used for ``mock``, depending on whether we're using Python 2 or 3. diff --git a/dev-docs/source/MVPTutorial/MockingExerciseSolution.rst b/dev-docs/source/MVPTutorial/MockingExerciseSolution.rst index 36edb80de469c222f8d44c4792be91a5e0b4c010..1c6a2a4467496d090de7f82ba22d20ae3a2c2677 100644 --- a/dev-docs/source/MVPTutorial/MockingExerciseSolution.rst +++ b/dev-docs/source/MVPTutorial/MockingExerciseSolution.rst @@ -13,10 +13,7 @@ Mocking Exercise Solution import view import unittest - if sys.version_info.major == 3: - from unittest import mock - else: - import mock + from mantid.py3compat import mock class presenterTest(unittest.TestCase): def setUp(self): diff --git a/qt/applications/workbench/workbench/plotting/test/test_globalfiguremanager.py b/qt/applications/workbench/workbench/plotting/test/test_globalfiguremanager.py index f8f36b6e324845f206314d58f2937795b9d8ad20..bcc501286c05617573302b14585de963eb9426c5 100644 --- a/qt/applications/workbench/workbench/plotting/test/test_globalfiguremanager.py +++ b/qt/applications/workbench/workbench/plotting/test/test_globalfiguremanager.py @@ -1,26 +1,24 @@ import unittest -try: - from unittest import Mock, call, patch -except ImportError: - from mock import Mock, call, patch +from mantid.py3compat import mock +from mock import call, patch from workbench.plotting.globalfiguremanager import FigureAction, GlobalFigureManager, GlobalFigureManagerObserver from workbench.plotting.observabledictionary import DictionaryAction class MockGlobalFigureManager: def __init__(self): - self.notify_observers = Mock() + self.notify_observers = mock.Mock() self.mock_figs = {} - self.figs = Mock() - self.figs.keys = Mock(return_value=self.mock_figs) + self.figs = mock.Mock() + self.figs.keys = mock.Mock(return_value=self.mock_figs) class MockCanvas: def __init__(self): - self.mpl_disconnect = Mock() + self.mpl_disconnect = mock.Mock() self.figure = None - self.draw_idle = Mock() + self.draw_idle = mock.Mock() class MockFigureManager: @@ -28,7 +26,7 @@ class MockFigureManager: self.num = num self.canvas = MockCanvas() self._cidgcf = -1231231 - self.destroy = Mock() + self.destroy = mock.Mock() class TestGlobalFigureManagerObserver(unittest.TestCase): @@ -92,7 +90,7 @@ class TestGlobalFigureManager(unittest.TestCase): def add_manager(self, num=0): mock_manager = MockFigureManager(num) - mock_fig = Mock() + mock_fig = mock.Mock() mock_manager.canvas.figure = mock_fig GlobalFigureManager.set_active(mock_manager) return mock_manager, mock_fig @@ -171,7 +169,7 @@ class TestGlobalFigureManager(unittest.TestCase): num = 0 self.add_manager(num) - other_mock_fig = Mock() + other_mock_fig = mock.Mock() other_mock_manager = MockFigureManager(num + 1) other_mock_manager.canvas.figure = other_mock_fig GlobalFigureManager.set_active(other_mock_manager) @@ -261,8 +259,8 @@ class TestGlobalFigureManager(unittest.TestCase): self.assertEqual({0: 4, 1: 3, 2: 2, 3: 1}, last_active_values) def test_add_observer(self): - good_observer = Mock() - good_observer.notify = Mock() + good_observer = mock.Mock() + good_observer.notify = mock.Mock() self.assertTrue(1, len(GlobalFigureManager.observers)) def test_fail_adding_bad_observer(self): @@ -277,8 +275,8 @@ class TestGlobalFigureManager(unittest.TestCase): num = 10 mock_observers = [] for i in range(num): - good_observer = Mock() - good_observer.notify = Mock() + good_observer = mock.Mock() + good_observer.notify = mock.Mock() GlobalFigureManager.add_observer(good_observer) mock_observers.append(good_observer) diff --git a/qt/applications/workbench/workbench/plugins/test/test_editor.py b/qt/applications/workbench/workbench/plugins/test/test_editor.py index ca2184c0097589c97e833aa1556646839d1615d9..558e61257e5392951c3e1a29c196fa6698eef7fd 100644 --- a/qt/applications/workbench/workbench/plugins/test/test_editor.py +++ b/qt/applications/workbench/workbench/plugins/test/test_editor.py @@ -7,16 +7,11 @@ # This file is part of the mantid workbench. # # - import os -import unittest - -try: - from unittest import mock -except ImportError: - import mock from qtpy.QtWidgets import QMainWindow +import unittest +from mantid.py3compat import mock from mantidqt.utils.qt.testing import GuiTest from workbench.plugins.editor import MultiFileEditor diff --git a/qt/applications/workbench/workbench/plugins/test/test_workspacewidget.py b/qt/applications/workbench/workbench/plugins/test/test_workspacewidget.py index 811eb53103127267b3112bba0a640ecf3bf7f09d..ddbc804c286e5185254579f826e631afc5391c9e 100644 --- a/qt/applications/workbench/workbench/plugins/test/test_workspacewidget.py +++ b/qt/applications/workbench/workbench/plugins/test/test_workspacewidget.py @@ -9,15 +9,12 @@ # import unittest -try: - import mock -except ImportError: - from unittest import mock from qtpy.QtWidgets import QMainWindow, QApplication from mantid.simpleapi import (CreateEmptyTableWorkspace, CreateWorkspace, GroupWorkspaces) +from mantid.py3compat import mock from mantidqt.utils.qt.testing import GuiTest from mantidqt.utils.qt.testing.qt_widget_finder import QtWidgetFinder import matplotlib as mpl diff --git a/qt/applications/workbench/workbench/projectrecovery/recoverygui/test/test_projectrecoverymodel.py b/qt/applications/workbench/workbench/projectrecovery/recoverygui/test/test_projectrecoverymodel.py index 0f6ae566d5d6505e758b44a3dee63c2140cc8391..08903139496d16566ebd273c2d54fc7b7d8d56c5 100644 --- a/qt/applications/workbench/workbench/projectrecovery/recoverygui/test/test_projectrecoverymodel.py +++ b/qt/applications/workbench/workbench/projectrecovery/recoverygui/test/test_projectrecoverymodel.py @@ -11,21 +11,16 @@ from __future__ import (absolute_import, unicode_literals) import os import shutil -import sys import time import unittest from mantid.api import AnalysisDataService as ADS from mantid.kernel import ConfigService from mantid.simpleapi import CreateSampleWorkspace +from mantid.py3compat import mock from workbench.projectrecovery.projectrecovery import ProjectRecovery, NO_OF_CHECKPOINTS_KEY from workbench.projectrecovery.recoverygui.projectrecoverymodel import ProjectRecoveryModel -if sys.version_info.major >= 3: - from unittest import mock -else: - import mock - class ProjectRecoveryModelTest(unittest.TestCase): def setUp(self): diff --git a/qt/applications/workbench/workbench/projectrecovery/recoverygui/test/test_projectrecoverypresenter.py b/qt/applications/workbench/workbench/projectrecovery/recoverygui/test/test_projectrecoverypresenter.py index 970dc987738c88c73e517f01cb8203b7fa5fc73b..f7a3f471ccef5fe680c8b488a404fa7df07d97af 100644 --- a/qt/applications/workbench/workbench/projectrecovery/recoverygui/test/test_projectrecoverypresenter.py +++ b/qt/applications/workbench/workbench/projectrecovery/recoverygui/test/test_projectrecoverypresenter.py @@ -9,16 +9,11 @@ from __future__ import (absolute_import, unicode_literals) -import sys import unittest +from mantid.py3compat import mock from workbench.projectrecovery.recoverygui.projectrecoverypresenter import ProjectRecoveryPresenter -if sys.version_info.major >= 3: - from unittest import mock -else: - import mock - PATCH_PROJECT_RECOVERY_VIEW = 'workbench.projectrecovery.recoverygui.projectrecoverypresenter.ProjectRecoveryWidgetView' PATCH_PROJECT_RECOVERY_MODEL = 'workbench.projectrecovery.recoverygui.projectrecoverypresenter.ProjectRecoveryModel' diff --git a/qt/applications/workbench/workbench/projectrecovery/recoverygui/test/test_projectrecoverywidgetview.py b/qt/applications/workbench/workbench/projectrecovery/recoverygui/test/test_projectrecoverywidgetview.py index 7774101d5957d6a08fd9f304343069e5638136b3..e1da87747cf00eb5b90d32a99541bda8c2e0dea8 100644 --- a/qt/applications/workbench/workbench/projectrecovery/recoverygui/test/test_projectrecoverywidgetview.py +++ b/qt/applications/workbench/workbench/projectrecovery/recoverygui/test/test_projectrecoverywidgetview.py @@ -9,15 +9,9 @@ from __future__ import (absolute_import, unicode_literals) -import sys - -from workbench.projectrecovery.recoverygui.projectrecoverywidgetview import ProjectRecoveryWidgetView +from mantid.py3compat import mock from mantidqt.utils.qt.testing import GuiTest - -if sys.version_info.major >= 3: - from unittest import mock -else: - import mock +from workbench.projectrecovery.recoverygui.projectrecoverywidgetview import ProjectRecoveryWidgetView class ProjectRecoveryWidgetViewTest(GuiTest): diff --git a/qt/applications/workbench/workbench/projectrecovery/recoverygui/test/test_recoveryfailureview.py b/qt/applications/workbench/workbench/projectrecovery/recoverygui/test/test_recoveryfailureview.py index 5f9e89cfc1692d65f11c4b3b29ad83dc9643336f..f565c3d7d5780499b559803913223723cc185a16 100644 --- a/qt/applications/workbench/workbench/projectrecovery/recoverygui/test/test_recoveryfailureview.py +++ b/qt/applications/workbench/workbench/projectrecovery/recoverygui/test/test_recoveryfailureview.py @@ -9,16 +9,11 @@ from __future__ import (absolute_import, unicode_literals) -import sys from qtpy.QtWidgets import QTableWidgetItem -from workbench.projectrecovery.recoverygui.recoveryfailureview import RecoveryFailureView +from mantid.py3compat import mock from mantidqt.utils.qt.testing import GuiTest - -if sys.version_info.major >= 3: - from unittest import mock -else: - import mock +from workbench.projectrecovery.recoverygui.recoveryfailureview import RecoveryFailureView class RecoveryFailureViewTest(GuiTest): diff --git a/qt/applications/workbench/workbench/projectrecovery/test/test_projectrecovery.py b/qt/applications/workbench/workbench/projectrecovery/test/test_projectrecovery.py index 683ea79e623bc571748250861cd6a8624d0b2636..fc1935a8f4d4b86d87672b3ddeb001e73dcd30d3 100644 --- a/qt/applications/workbench/workbench/projectrecovery/test/test_projectrecovery.py +++ b/qt/applications/workbench/workbench/projectrecovery/test/test_projectrecovery.py @@ -19,14 +19,12 @@ import unittest from mantid.api import AnalysisDataService as ADS from mantid.kernel import ConfigService +from mantid.py3compat import mock from workbench.projectrecovery.projectrecovery import ProjectRecovery, SAVING_TIME_KEY, NO_OF_CHECKPOINTS_KEY, \ RECOVERY_ENABLED_KEY if sys.version_info.major >= 3: - from unittest import mock unicode = str -else: - import mock def is_macOS(): diff --git a/qt/applications/workbench/workbench/projectrecovery/test/test_projectrecoveryloader.py b/qt/applications/workbench/workbench/projectrecovery/test/test_projectrecoveryloader.py index 1e7bbc0f3f12ebaf8d5f3b895d9242d985ea4f58..ba96cff5017b60263bb24a3262453dd5c7d82fe3 100644 --- a/qt/applications/workbench/workbench/projectrecovery/test/test_projectrecoveryloader.py +++ b/qt/applications/workbench/workbench/projectrecovery/test/test_projectrecoveryloader.py @@ -17,13 +17,11 @@ import unittest from mantid.api import AnalysisDataService as ADS from mantid.simpleapi import CreateSampleWorkspace +from mantid.py3compat import mock from workbench.projectrecovery.projectrecovery import ProjectRecovery if sys.version_info.major >= 3: - from unittest import mock unicode = str -else: - import mock class ProjectRecoveryLoaderTest(unittest.TestCase): diff --git a/qt/applications/workbench/workbench/projectrecovery/test/test_projectrecoverysaver.py b/qt/applications/workbench/workbench/projectrecovery/test/test_projectrecoverysaver.py index de2db551c7f05ac7c88110d1feda4c0499d75577..1fdabdd9955bb4e482484d0f4736e29a7c29e144 100644 --- a/qt/applications/workbench/workbench/projectrecovery/test/test_projectrecoverysaver.py +++ b/qt/applications/workbench/workbench/projectrecovery/test/test_projectrecoverysaver.py @@ -18,13 +18,11 @@ import unittest from mantid.api import AnalysisDataService as ADS from mantid.simpleapi import CreateSampleWorkspace, GroupWorkspaces +from mantid.py3compat import mock from workbench.projectrecovery.projectrecovery import ProjectRecovery if sys.version_info.major >= 3: - from unittest import mock unicode = str -else: - import mock class FakeEncoder(object): diff --git a/qt/applications/workbench/workbench/widgets/plotselector/test/test_plotselector_model.py b/qt/applications/workbench/workbench/widgets/plotselector/test/test_plotselector_model.py index 03ec4a69f6fe8c7a8552e77fa8ed202d0b159370..1ead7243d3496bfa6192c377e2057c88678e28c3 100644 --- a/qt/applications/workbench/workbench/widgets/plotselector/test/test_plotselector_model.py +++ b/qt/applications/workbench/workbench/widgets/plotselector/test/test_plotselector_model.py @@ -9,17 +9,13 @@ # from __future__ import absolute_import, division, print_function -from workbench.plotting.globalfiguremanager import FigureAction +import unittest +from mantid.py3compat import mock +from workbench.plotting.globalfiguremanager import FigureAction from workbench.widgets.plotselector.model import PlotSelectorModel from workbench.widgets.plotselector.presenter import PlotSelectorPresenter -import unittest -try: - from unittest import mock -except ImportError: - import mock - class PlotSelectorModelTest(unittest.TestCase): diff --git a/qt/applications/workbench/workbench/widgets/plotselector/test/test_plotselector_presenter.py b/qt/applications/workbench/workbench/widgets/plotselector/test/test_plotselector_presenter.py index d3eb7af89e1377367b5c14e4ae6feacf513571ab..9689178fb44ba7c750343f73ec1a70cd419d5093 100644 --- a/qt/applications/workbench/workbench/widgets/plotselector/test/test_plotselector_presenter.py +++ b/qt/applications/workbench/workbench/widgets/plotselector/test/test_plotselector_presenter.py @@ -9,18 +9,14 @@ # from __future__ import absolute_import, division, print_function +import os +import unittest + +from mantid.py3compat import mock from workbench.widgets.plotselector.model import PlotSelectorModel from workbench.widgets.plotselector.presenter import PlotSelectorPresenter from workbench.widgets.plotselector.view import PlotSelectorView, Column -import os - -import unittest -try: - from unittest import mock -except ImportError: - import mock - class PlotSelectorPresenterTest(unittest.TestCase): diff --git a/qt/applications/workbench/workbench/widgets/plotselector/test/test_plotselector_view.py b/qt/applications/workbench/workbench/widgets/plotselector/test/test_plotselector_view.py index 89bc1825669ef913dd221f6894b641f473edfa13..b11b29dd60eabfdac185f3a52c5c5b23297fcab9 100644 --- a/qt/applications/workbench/workbench/widgets/plotselector/test/test_plotselector_view.py +++ b/qt/applications/workbench/workbench/widgets/plotselector/test/test_plotselector_view.py @@ -9,20 +9,16 @@ # from __future__ import absolute_import, division, print_function -from mantidqt.utils.qt.testing import GuiTest from qtpy.QtCore import Qt from qtpy.QtGui import QIcon from qtpy.QtTest import QTest +import unittest +from mantid.py3compat import mock +from mantidqt.utils.qt.testing import GuiTest from workbench.widgets.plotselector.presenter import PlotSelectorPresenter from workbench.widgets.plotselector.view import EXPORT_TYPES, PlotSelectorView, Column -import unittest -try: - from unittest import mock -except ImportError: - import mock - class PlotSelectorWidgetTest(GuiTest): diff --git a/qt/applications/workbench/workbench/widgets/settings/test/test_settings_view.py b/qt/applications/workbench/workbench/widgets/settings/test/test_settings_view.py index b56bd9d8dc247dbef58d6000ca660cad7d082a57..bfb0dcdb4b2df01ccfa46204d96dd9c8f7cf2e8e 100644 --- a/qt/applications/workbench/workbench/widgets/settings/test/test_settings_view.py +++ b/qt/applications/workbench/workbench/widgets/settings/test/test_settings_view.py @@ -7,9 +7,9 @@ # This file is part of the mantid workbench from __future__ import absolute_import, unicode_literals -from mock import MagicMock from qtpy.QtWidgets import QApplication, QWidget +from mantid.py3compat.mock import MagicMock from mantidqt.utils.qt.testing import GuiTest from mantidqt.utils.qt.testing.qt_widget_finder import QtWidgetFinder from workbench.widgets.settings.presenter import SettingsPresenter diff --git a/qt/python/mantidqt/dialogs/test/test_spectraselectiondialog.py b/qt/python/mantidqt/dialogs/test/test_spectraselectiondialog.py index 0fc6be93203720f86dc3aee9c4d68c96fa5d4ded..71a03e12e92b35582e00b10bff7e4a1ba2002072 100644 --- a/qt/python/mantidqt/dialogs/test/test_spectraselectiondialog.py +++ b/qt/python/mantidqt/dialogs/test/test_spectraselectiondialog.py @@ -10,13 +10,11 @@ # std imports import unittest -try: - from unittest import mock -except ImportError: - import mock + # 3rdparty imports from mantid.api import WorkspaceFactory +from mantid.py3compat import mock from qtpy.QtGui import QIcon from qtpy.QtWidgets import QDialog, QDialogButtonBox diff --git a/qt/python/mantidqt/plotting/test/test_functions.py b/qt/python/mantidqt/plotting/test/test_functions.py index 8fb1e9a4d52e0f024444510ddb86e69626915317..f2018512f6a7fe70ad58f3f4327364f11252ccca 100644 --- a/qt/python/mantidqt/plotting/test/test_functions.py +++ b/qt/python/mantidqt/plotting/test/test_functions.py @@ -11,13 +11,11 @@ from __future__ import absolute_import # std imports from unittest import TestCase, main -try: - from unittest import mock -except ImportError: - import mock + # third party imports from mantid.api import AnalysisDataService, WorkspaceFactory +from mantid.py3compat import mock # register mantid projection import mantid.plots # noqa import matplotlib diff --git a/qt/python/mantidqt/project/test/test_plotsloader.py b/qt/python/mantidqt/project/test/test_plotsloader.py index df4dd5fc0f70367daf080448fe1e98b1c63bdbec..9427d8eb0b00b296b630a99ff83d61751aba6852 100644 --- a/qt/python/mantidqt/project/test/test_plotsloader.py +++ b/qt/python/mantidqt/project/test/test_plotsloader.py @@ -11,7 +11,6 @@ from __future__ import (absolute_import, division, print_function, unicode_liter import matplotlib matplotlib.use('AGG') -import sys # noqa import unittest # noqa import matplotlib.pyplot as plt # noqa import matplotlib.figure # noqa @@ -21,13 +20,7 @@ from mantidqt.project.plotsloader import PlotsLoader # noqa import mantid.plots.plotfunctions # noqa from mantid.api import AnalysisDataService as ADS # noqa from mantid.dataobjects import Workspace2D # noqa - -if sys.version_info.major >= 3: - # Python 3 and above - from unittest import mock -else: - # Python 2 - import mock +from mantid.py3compat import mock # noqa def pass_func(): diff --git a/qt/python/mantidqt/project/test/test_project.py b/qt/python/mantidqt/project/test/test_project.py index 04e8af032437b877c8ae2a9d7fd639d22889895f..f5c81800e21123d8c4f1212e407380d3eacd72c0 100644 --- a/qt/python/mantidqt/project/test/test_project.py +++ b/qt/python/mantidqt/project/test/test_project.py @@ -9,7 +9,6 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) import os -import sys import tempfile import unittest @@ -17,15 +16,9 @@ from qtpy.QtWidgets import QMessageBox from mantid.api import AnalysisDataService as ADS from mantid.simpleapi import CreateSampleWorkspace, GroupWorkspaces, RenameWorkspace, UnGroupWorkspace +from mantid.py3compat import mock from mantidqt.project.project import Project -if sys.version_info.major >= 3: - # Python 3 and above - from unittest import mock -else: - # Python 2 - import mock - class FakeGlobalFigureManager(object): def add_observer(self, *unused): diff --git a/qt/python/mantidqt/project/test/test_projectloader.py b/qt/python/mantidqt/project/test/test_projectloader.py index b0d1a33a1a4d1dc735384410000ad3224ca7e374..99fd6aa7eca6e3083af04a4525d2343cc4ba314c 100644 --- a/qt/python/mantidqt/project/test/test_projectloader.py +++ b/qt/python/mantidqt/project/test/test_projectloader.py @@ -6,9 +6,7 @@ # SPDX - License - Identifier: GPL - 3.0 + # This file is part of the mantidqt package # - import matplotlib -import sys import tempfile import unittest from os.path import isdir @@ -22,15 +20,10 @@ import tempfile # noqa from mantid.api import AnalysisDataService as ADS # noqa from mantid.simpleapi import CreateSampleWorkspace # noqa +from mantid.py3compat import mock # noqa from mantidqt.project import projectloader, projectsaver # noqa -if sys.version_info.major >= 3: - from unittest import mock -else: - import mock - - project_file_ext = ".mtdproj" working_directory = tempfile.mkdtemp() working_project_file = join(working_directory, "temp" + project_file_ext) diff --git a/qt/python/mantidqt/project/test/test_projectsaver.py b/qt/python/mantidqt/project/test/test_projectsaver.py index ee9270f5b412df8ba35049122a283fd407c8c88c..1566c8bf13f3193c8da228e08188cf64cf6e73f5 100644 --- a/qt/python/mantidqt/project/test/test_projectsaver.py +++ b/qt/python/mantidqt/project/test/test_projectsaver.py @@ -10,19 +10,15 @@ import json import matplotlib.backend_bases import matplotlib.figure import os -import sys import tempfile import unittest from shutil import rmtree from mantid.api import AnalysisDataService as ADS from mantid.simpleapi import CreateSampleWorkspace +from mantid.py3compat import mock from mantidqt.project import projectsaver -if sys.version_info.major >= 3: - from unittest import mock -else: - import mock project_file_ext = ".mtdproj" working_directory = tempfile.mkdtemp() diff --git a/qt/python/mantidqt/utils/test/test_modal_tester.py b/qt/python/mantidqt/utils/test/test_modal_tester.py index dc8f4678ff4d4135e10185cddc11f85400fef4c3..5b835ec3dd26bc10d901a391705c5a4815fe1364 100644 --- a/qt/python/mantidqt/utils/test/test_modal_tester.py +++ b/qt/python/mantidqt/utils/test/test_modal_tester.py @@ -10,11 +10,10 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) -from mock import patch import unittest - from qtpy.QtWidgets import QInputDialog +from mantid.py3compat.mock import patch from mantidqt.utils.qt.testing import GuiTest, ModalTester diff --git a/qt/python/mantidqt/utils/test/test_writetosignal.py b/qt/python/mantidqt/utils/test/test_writetosignal.py index 8f7012ff701f5fe7af35a0a0d703ea859a677693..134c1e9ebf6e5d43cc6eed93a20c93a6c3480ab9 100644 --- a/qt/python/mantidqt/utils/test/test_writetosignal.py +++ b/qt/python/mantidqt/utils/test/test_writetosignal.py @@ -9,19 +9,14 @@ # from __future__ import (absolute_import) -import unittest - -import sys from qtpy.QtCore import QCoreApplication, QObject +import sys +import unittest +from mantid.py3compat.mock import patch from mantidqt.utils.qt.testing import GuiTest from mantidqt.utils.writetosignal import WriteToSignal -if sys.version_info.major == 2: - from mock import patch -else: - from unittest.mock import patch - class Receiver(QObject): captured_txt = None diff --git a/qt/python/mantidqt/widgets/codeeditor/test/test_interpreter.py b/qt/python/mantidqt/widgets/codeeditor/test/test_interpreter.py index 69d79bd0719147eb808f19d675327a3497fb0a61..f56a4d251ae7c502086b7621ee917adbedc2cee2 100644 --- a/qt/python/mantidqt/widgets/codeeditor/test/test_interpreter.py +++ b/qt/python/mantidqt/widgets/codeeditor/test/test_interpreter.py @@ -11,16 +11,10 @@ from __future__ import (absolute_import, unicode_literals) import unittest -import six - +from mantid.py3compat import mock from mantidqt.utils.qt.testing import GuiTest from mantidqt.widgets.codeeditor.interpreter import PythonFileInterpreter -if six.PY2: - import mock -else: - from unittest import mock - class PythonFileInterpreterTest(GuiTest): diff --git a/qt/python/mantidqt/widgets/codeeditor/test/test_multifileinterpreter.py b/qt/python/mantidqt/widgets/codeeditor/test/test_multifileinterpreter.py index 37b78bc5177c098fb2c0433444edb8fa06e5b122..81526ccb47b043f4b98f8c91a927feeed70385ad 100644 --- a/qt/python/mantidqt/widgets/codeeditor/test/test_multifileinterpreter.py +++ b/qt/python/mantidqt/widgets/codeeditor/test/test_multifileinterpreter.py @@ -11,11 +11,7 @@ from __future__ import (absolute_import, unicode_literals) import unittest -try: - from unittest import mock -except ImportError: - import mock - +from mantid.py3compat import mock from mantidqt.utils.qt.testing import GuiTest from mantidqt.utils.qt.testing.qt_widget_finder import QtWidgetFinder from mantidqt.widgets.codeeditor.multifileinterpreter import MultiPythonFileInterpreter diff --git a/qt/python/mantidqt/widgets/codeeditor/test/test_scriptcompatibility.py b/qt/python/mantidqt/widgets/codeeditor/test/test_scriptcompatibility.py index 0058e32eaa20375548ce5dca36ef439ef8862da8..b8a0aab8ea3d76ea44dadcb2517f7597d9ebe92f 100644 --- a/qt/python/mantidqt/widgets/codeeditor/test/test_scriptcompatibility.py +++ b/qt/python/mantidqt/widgets/codeeditor/test/test_scriptcompatibility.py @@ -9,11 +9,8 @@ # import unittest -try: - from unittest import mock -except ImportError: - import mock +from mantid.py3compat import mock from mantidqt.widgets.codeeditor.scriptcompatibility import (mantid_api_import_needed, mantid_algorithm_used_without_import) diff --git a/qt/python/mantidqt/widgets/samplelogs/test/test_samplelogs_presenter.py b/qt/python/mantidqt/widgets/samplelogs/test/test_samplelogs_presenter.py index 0a4f9a53db3d39953e07b435bcd84ea1e295c478..caa4101b42d857059f68d9d8eace783030ba07b2 100644 --- a/qt/python/mantidqt/widgets/samplelogs/test/test_samplelogs_presenter.py +++ b/qt/python/mantidqt/widgets/samplelogs/test/test_samplelogs_presenter.py @@ -11,17 +11,13 @@ from __future__ import (absolute_import, division, print_function) import matplotlib matplotlib.use('Agg') # noqa: E402 +import unittest +from mantid.py3compat import mock from mantidqt.widgets.samplelogs.model import SampleLogsModel from mantidqt.widgets.samplelogs.presenter import SampleLogs from mantidqt.widgets.samplelogs.view import SampleLogsView -import unittest -try: - from unittest import mock -except ImportError: - import mock - class SampleLogsTest(unittest.TestCase): diff --git a/scripts/SANS/sans/test_helper/mock_objects.py b/scripts/SANS/sans/test_helper/mock_objects.py index 7a1e2b710379e5ee14a3f8848c3f94f01505c532..d0cf26e686d02c1840198261c045c37fe4aebb4a 100644 --- a/scripts/SANS/sans/test_helper/mock_objects.py +++ b/scripts/SANS/sans/test_helper/mock_objects.py @@ -6,21 +6,17 @@ # SPDX - License - Identifier: GPL - 3.0 + from __future__ import (absolute_import) +from functools import (partial) + +from mantid.py3compat import mock +from sans.gui_logic.presenter.run_tab_presenter import RunTabPresenter +from sans.common.enums import (RangeStepType, OutputMode, SANSFacility, SANSInstrument) +from sans.test_helper.test_director import TestDirector from ui.sans_isis.sans_data_processor_gui import SANSDataProcessorGui from ui.sans_isis.settings_diagnostic_tab import SettingsDiagnosticTab from ui.sans_isis.diagnostics_page import DiagnosticsPage from ui.sans_isis.masking_table import MaskingTable from ui.sans_isis.beam_centre import BeamCentre -from sans.gui_logic.presenter.run_tab_presenter import RunTabPresenter -from sans.common.enums import (RangeStepType, OutputMode, SANSFacility, SANSInstrument) -from sans.test_helper.test_director import TestDirector -from functools import (partial) - -import sys -if sys.version_info.major == 3: - from unittest import mock -else: - import mock def create_mock_settings_diagnostic_tab(): diff --git a/scripts/test/CrystalFieldTest.py b/scripts/test/CrystalFieldTest.py index e80594be62ba75054212e43f353cedcab9f494de..18d8b80f6f1e1d497d2356f1018756a0f6888320 100644 --- a/scripts/test/CrystalFieldTest.py +++ b/scripts/test/CrystalFieldTest.py @@ -1471,12 +1471,9 @@ class CrystalFieldFitTest(unittest.TestCase): def test_CrystalField_PointCharge_file(self): from CrystalField import PointCharge - import sys import mantid.simpleapi - if sys.version_info.major == 3: - from unittest import mock - else: - import mock + from mantid.py3compat import mock + # Just check that LoadCIF is called... we'll rely on LoadCIF working properly! with mock.patch.object(mantid.simpleapi, 'LoadCIF') as loadcif: self.assertRaises(RuntimeError, PointCharge, 'somefile.cif') # Error because no actual CIF loaded diff --git a/scripts/test/MultiPlotting/AxisChangerTwoPresenter_test.py b/scripts/test/MultiPlotting/AxisChangerTwoPresenter_test.py index 38a5652a8a7490d59bf7242233b05b9f6ff8949b..e6614ab412366d1d2d80be4840ea3bb39071300b 100644 --- a/scripts/test/MultiPlotting/AxisChangerTwoPresenter_test.py +++ b/scripts/test/MultiPlotting/AxisChangerTwoPresenter_test.py @@ -6,16 +6,11 @@ # SPDX - License - Identifier: GPL - 3.0 + import unittest +from mantid.py3compat import mock from MultiPlotting.AxisChanger.axis_changer_presenter import AxisChangerPresenter from MultiPlotting.AxisChanger.axis_changer_view import AxisChangerView -try: - from unittest import mock -except ImportError: - import mock - - class AxisChangerTwoPresenterTest(unittest.TestCase): def setUp(self): view = mock.create_autospec(AxisChangerView) diff --git a/scripts/test/MultiPlotting/AxisChangerTwoView_test.py b/scripts/test/MultiPlotting/AxisChangerTwoView_test.py index 202fa62e69aaa085c8d58a5d0057748103c138d4..8bf17b5427bbc58a292d3ba7bb94b2130c37a56e 100644 --- a/scripts/test/MultiPlotting/AxisChangerTwoView_test.py +++ b/scripts/test/MultiPlotting/AxisChangerTwoView_test.py @@ -6,15 +6,10 @@ # SPDX - License - Identifier: GPL - 3.0 + import unittest +from mantid.py3compat import mock from MultiPlotting.AxisChanger.axis_changer_view import AxisChangerView - from Muon.GUI.Common import mock_widget -try: - from unittest import mock -except ImportError: - import mock - class AxisChangerTwoViewTest(unittest.TestCase): def setUp(self): diff --git a/scripts/test/MultiPlotting/DefaultGridspec_test.py b/scripts/test/MultiPlotting/DefaultGridspec_test.py index 9e6c31844c3213b3dd72f4ed031d69e7f2a2f8da..1e05456dbcd73adee9bd27a9deaf1095c4416dfc 100644 --- a/scripts/test/MultiPlotting/DefaultGridspec_test.py +++ b/scripts/test/MultiPlotting/DefaultGridspec_test.py @@ -9,48 +9,40 @@ import unittest from MultiPlotting.gridspec_engine import defaultGridspecGrid -try: - from unittest import mock -except ImportError: - import mock - - class DefaultGridSpecTest(unittest.TestCase): def test_someSquares(self): - roots = [2,3,4,5,123] + roots = [2, 3, 4, 5, 123] for root in roots: result = defaultGridspecGrid(root*root) - self.assertEquals(result, [root,root]) + self.assertEquals(result, [root, root]) def test_notSquares(self): - roots = [3,4,5,123] + roots = [3, 4, 5, 123] for root in roots: result = defaultGridspecGrid(root*root-1) - self.assertEquals(result, [root,root]) + self.assertEquals(result, [root, root]) def test_specialCaseOne(self): number = 1 result = defaultGridspecGrid(number) - self.assertEquals(result, [1,1]) + self.assertEquals(result, [1, 1]) def test_specialCaseTwo(self): number = 2 result = defaultGridspecGrid(number) - self.assertEquals(result, [1,2]) - + self.assertEquals(result, [1, 2]) def test_specialCaseThree(self): number = 3 result = defaultGridspecGrid(number) - self.assertEquals(result, [3,1]) + self.assertEquals(result, [3, 1]) def test_smallerGrid(self): number = 5 result = defaultGridspecGrid(number) - self.assertEquals(result, [2,3]) + self.assertEquals(result, [2, 3]) - if __name__ == "__main__": unittest.main() diff --git a/scripts/test/MultiPlotting/Gridspec_test.py b/scripts/test/MultiPlotting/Gridspec_test.py index 439b20779ae3e8e4bd4e374606f5604c101088b4..4c7ab1b4a8fbe3a006ac3c6c3d475c0f58fa2bee 100644 --- a/scripts/test/MultiPlotting/Gridspec_test.py +++ b/scripts/test/MultiPlotting/Gridspec_test.py @@ -4,18 +4,12 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import unittest from matplotlib.gridspec import GridSpec +import unittest from MultiPlotting.gridspec_engine import gridspecEngine -try: - from unittest import mock -except ImportError: - import mock - - class GridSpecTest(unittest.TestCase): """ We do not need to test the layout from the gridspec @@ -34,13 +28,13 @@ class GridSpecTest(unittest.TestCase): self.engine = gridspecEngine(max_plot=10) result = self.engine.getGridSpec(100) self.assertEquals(result, None) - def test_returnType(self): gridspec = GridSpec(1,1) self.engine = gridspecEngine() result = self.engine.getGridSpec(1) self.assertEquals(type(result),type(gridspec)) - + + if __name__ == "__main__": unittest.main() diff --git a/scripts/test/MultiPlotting/MultiPlotWidget_test.py b/scripts/test/MultiPlotting/MultiPlotWidget_test.py index 95b326363d79f54904d040f60a5d26a53ad1250a..a6a56bb1bee8efbc964122ee2ca2c5f0249b7b87 100644 --- a/scripts/test/MultiPlotting/MultiPlotWidget_test.py +++ b/scripts/test/MultiPlotting/MultiPlotWidget_test.py @@ -6,19 +6,14 @@ # SPDX - License - Identifier: GPL - 3.0 + import unittest -from Muon.GUI.Common import mock_widget - +from mantid.py3compat import mock from MultiPlotting.multi_plotting_widget import MultiPlotWidget from MultiPlotting.QuickEdit.quickEdit_widget import QuickEditWidget from MultiPlotting.subplot.subplot import subplot from MultiPlotting.multi_plotting_context import PlottingContext +from Muon.GUI.Common import mock_widget -try: - from unittest import mock -except ImportError: - import mock - class bounds(object): def __init__(self,x,y): self.x = x @@ -37,6 +32,7 @@ class bounds(object): def errors(self): return self.error + def data(): values = {} values["one"] = bounds([5,20],[5,10]) @@ -45,6 +41,7 @@ def data(): values["four"] = bounds([4,12],[4,50]) return values + class MultiPlotWidgetTest(unittest.TestCase): def setUp(self): @@ -88,7 +85,6 @@ class MultiPlotWidgetTest(unittest.TestCase): self.widget._update_quick_edit("no match") self.assertEquals(self.widget.quickEdit.rm_subplot.call_count, 1) - def test_updateQuickEdit1Match(self): self.widget._context.subplots = data() @@ -136,7 +132,6 @@ class MultiPlotWidgetTest(unittest.TestCase): self.widget.quickEdit.set_plot_x_range.assert_called_with([6,10]) self.widget.quickEdit.set_plot_y_range.assert_called_with([0,9]) - def test_selectionChangedAll(self): self.widget._context.subplots = data() # mocks as we only want to test logic diff --git a/scripts/test/MultiPlotting/MultiPlottingContext_test.py b/scripts/test/MultiPlotting/MultiPlottingContext_test.py index ab32922ec104a6fcc2ef72ab582f4b2cd3e9295c..7acca36087d6802980537706d07d8c48ca7f9429 100644 --- a/scripts/test/MultiPlotting/MultiPlottingContext_test.py +++ b/scripts/test/MultiPlotting/MultiPlottingContext_test.py @@ -6,15 +6,11 @@ # SPDX - License - Identifier: GPL - 3.0 + import unittest +from mantid.py3compat import mock from MultiPlotting.multi_plotting_context import PlottingContext from MultiPlotting.subplot.subplot_context import subplotContext -try: - from unittest import mock -except ImportError: - import mock - class gen_ws(object): def __init__(self,mock): self._input = "in" @@ -27,6 +23,7 @@ class gen_ws(object): def OutputWorkspace(self): return self._OutputWorkspace + class MultiPlottingContextTest(unittest.TestCase): def setUp(self): self.context = PlottingContext() @@ -56,7 +53,6 @@ class MultiPlottingContextTest(unittest.TestCase): self.assertEquals(patch.call_count,1) patch.assert_called_with(mockWS,specNum) - def test_updateLayout(self): # add mocks figure = mock.Mock() diff --git a/scripts/test/MultiPlotting/QuickEditPresenter_test.py b/scripts/test/MultiPlotting/QuickEditPresenter_test.py index e927eb4dfcb0e10fea771649f515318799345195..c66ee9473273ed0294c7475fa3acbd27a7751b09 100644 --- a/scripts/test/MultiPlotting/QuickEditPresenter_test.py +++ b/scripts/test/MultiPlotting/QuickEditPresenter_test.py @@ -6,16 +6,11 @@ # SPDX - License - Identifier: GPL - 3.0 + import unittest +from mantid.py3compat import mock from MultiPlotting.QuickEdit.quickEdit_presenter import QuickEditPresenter from MultiPlotting.QuickEdit.quickEdit_view import QuickEditView -try: - from unittest import mock -except ImportError: - import mock - - class QuickEditPresenterTest(unittest.TestCase): def setUp(self): self.view = mock.create_autospec(QuickEditView) diff --git a/scripts/test/MultiPlotting/QuickEditWidget_test.py b/scripts/test/MultiPlotting/QuickEditWidget_test.py index 42c528346a5e108a4b371199fbe08655e26ed11f..d70fbd233034e2f86c05ba0a4d27c897bf8df4ba 100644 --- a/scripts/test/MultiPlotting/QuickEditWidget_test.py +++ b/scripts/test/MultiPlotting/QuickEditWidget_test.py @@ -6,18 +6,12 @@ # SPDX - License - Identifier: GPL - 3.0 + import unittest +from mantid.py3compat import mock from MultiPlotting.QuickEdit.quickEdit_presenter import QuickEditPresenter from MultiPlotting.QuickEdit.quickEdit_widget import QuickEditWidget - from Muon.GUI.Common import mock_widget -try: - from unittest import mock -except ImportError: - import mock - - class QuickEditWidgetTest(unittest.TestCase): def setUp(self): self._qapp = mock_widget.mockQapp() diff --git a/scripts/test/MultiPlotting/SubPlotContext_test.py b/scripts/test/MultiPlotting/SubPlotContext_test.py index b1e69cca64bbedbbbb41937208fab7ca545ee6a5..ff32902ff2829fc3b6821eceb674a5f25dc5ba2a 100644 --- a/scripts/test/MultiPlotting/SubPlotContext_test.py +++ b/scripts/test/MultiPlotting/SubPlotContext_test.py @@ -6,13 +6,10 @@ # SPDX - License - Identifier: GPL - 3.0 + import unittest +from mantid.py3compat import mock from MultiPlotting.subplot.subplot_context import subplotContext from mantid import plots -try: - from unittest import mock -except ImportError: - import mock class line(object): diff --git a/scripts/test/MultiPlotting/Subplot_test.py b/scripts/test/MultiPlotting/Subplot_test.py index 1ebdf54fd48fa9bbcfee2bd9a5b5aaba015b0a33..73777f35ba30b2bde68c1c6b4af96a747ee0f9be 100644 --- a/scripts/test/MultiPlotting/Subplot_test.py +++ b/scripts/test/MultiPlotting/Subplot_test.py @@ -4,17 +4,13 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import unittest from matplotlib.gridspec import GridSpec +import unittest +from mantid.py3compat import mock from MultiPlotting.subplot.subplot import subplot from MultiPlotting.multi_plotting_context import PlottingContext - from Muon.GUI.Common import mock_widget -try: - from unittest import mock -except ImportError: - import mock def rm_logic(name): diff --git a/scripts/test/Muon/FFTModel_test.py b/scripts/test/Muon/FFTModel_test.py index 000784e35a5229262ab7f23bbbcdbedc9c1b9446..8a0b6dc63a7b3b9f6fb0380e87bb79d9036fa284 100644 --- a/scripts/test/Muon/FFTModel_test.py +++ b/scripts/test/Muon/FFTModel_test.py @@ -4,16 +4,10 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import sys - -from Muon.GUI.FrequencyDomainAnalysis.FFT import fft_model - import unittest -if sys.version_info.major == 3: - from unittest import mock -else: - import mock +from mantid.py3compat import mock +from Muon.GUI.FrequencyDomainAnalysis.FFT import fft_model class FFTModelTest(unittest.TestCase): diff --git a/scripts/test/Muon/FFTPresenter_test.py b/scripts/test/Muon/FFTPresenter_test.py index f264252fe9833db930f13a2b8b87c793eca9da7c..2fc0f76987c87e29d1fc84da923bcb3a38050c9d 100644 --- a/scripts/test/Muon/FFTPresenter_test.py +++ b/scripts/test/Muon/FFTPresenter_test.py @@ -4,21 +4,15 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import sys +import unittest +from mantid.py3compat import mock from Muon.GUI.Common.utilities import load_utils from Muon.GUI.Common import thread_model from Muon.GUI.FrequencyDomainAnalysis.FFT import fft_presenter from Muon.GUI.FrequencyDomainAnalysis.FFT import fft_view from Muon.GUI.FrequencyDomainAnalysis.FFT import fft_model -import unittest - -if sys.version_info.major == 3: - from unittest import mock -else: - import mock - class FFTPresenterTest(unittest.TestCase): diff --git a/scripts/test/Muon/LoadWidgetPresenter_test.py b/scripts/test/Muon/LoadWidgetPresenter_test.py index db84e85018fd43fe37038522f571d8651e0ce46e..9b6a430d6da2f6eb373af9a62a4139afaefd1d54 100644 --- a/scripts/test/Muon/LoadWidgetPresenter_test.py +++ b/scripts/test/Muon/LoadWidgetPresenter_test.py @@ -6,17 +6,12 @@ # SPDX - License - Identifier: GPL - 3.0 + import unittest +from mantid.py3compat import mock +from Muon.GUI.Common import mock_widget from Muon.GUI.Common.load_widget.load_presenter import LoadPresenter from Muon.GUI.Common.load_widget.load_view import LoadView from Muon.GUI.ElementalAnalysis.LoadWidget.load_model import LoadModel, CoLoadModel -from Muon.GUI.Common import mock_widget - -try: - from unittest import mock -except ImportError: - import mock - class LoadPresenterTest(unittest.TestCase): def setUp(self): diff --git a/scripts/test/Muon/LoadWidgetView_test.py b/scripts/test/Muon/LoadWidgetView_test.py index bcd2432171b70da63fbd94316f02982182649086..9b26ebe67a343ecbe59026a2324a3180b2ab7853 100644 --- a/scripts/test/Muon/LoadWidgetView_test.py +++ b/scripts/test/Muon/LoadWidgetView_test.py @@ -5,16 +5,11 @@ # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + import unittest +from mantid.py3compat import mock from Muon.GUI.Common.load_widget.load_view import LoadView - from Muon.GUI.Common import mock_widget -try: - from unittest import mock -except ImportError: - import mock - class LoadViewTest(unittest.TestCase): def setUp(self): diff --git a/scripts/test/Muon/MaxEntModel_test.py b/scripts/test/Muon/MaxEntModel_test.py index 32d376075bb59a9021067324e3d07050cb841a1a..6c97f4051bdebad41eb9e72e4098a6878b002c11 100644 --- a/scripts/test/Muon/MaxEntModel_test.py +++ b/scripts/test/Muon/MaxEntModel_test.py @@ -4,16 +4,10 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import sys - -from Muon.GUI.FrequencyDomainAnalysis.MaxEnt import maxent_model - import unittest -if sys.version_info.major == 3: - from unittest import mock -else: - import mock +from mantid.py3compat import mock +from Muon.GUI.FrequencyDomainAnalysis.MaxEnt import maxent_model class MaxEntModelTest(unittest.TestCase): diff --git a/scripts/test/Muon/MaxEntPresenter_test.py b/scripts/test/Muon/MaxEntPresenter_test.py index fd6d4b514e2a65f33e2b8154e3b22e211bc4abd6..99ed5479cd1632b2dc42ea173a351658571c5e3e 100644 --- a/scripts/test/Muon/MaxEntPresenter_test.py +++ b/scripts/test/Muon/MaxEntPresenter_test.py @@ -6,22 +6,20 @@ # SPDX - License - Identifier: GPL - 3.0 + from __future__ import (absolute_import, division, print_function) -import sys +import unittest + +from mantid.py3compat import mock +from Muon.GUI.Common.utilities import load_utils +from Muon.GUI.Common import thread_model +from Muon.GUI.FrequencyDomainAnalysis.MaxEnt import maxent_presenter +from Muon.GUI.FrequencyDomainAnalysis.MaxEnt import maxent_view +from Muon.GUI.FrequencyDomainAnalysis.MaxEnt import maxent_model -from Muon.GUI.Common.utilities import load_utils -from Muon.GUI.Common import thread_model -from Muon.GUI.FrequencyDomainAnalysis.MaxEnt import maxent_presenter -from Muon.GUI.FrequencyDomainAnalysis.MaxEnt import maxent_view -from Muon.GUI.FrequencyDomainAnalysis.MaxEnt import maxent_model -import unittest -if sys.version_info.major == 3: - from unittest import mock -else: - import mock def test(inputs): inputs["OutputPhaseTable"] = "test" + class MaxEntPresenterTest(unittest.TestCase): def setUp(self): self.load=mock.create_autospec(load_utils.LoadUtils,spec_set=True) diff --git a/scripts/test/Muon/PeriodicTableModel_test.py b/scripts/test/Muon/PeriodicTableModel_test.py index 0d2123fe97f4537b00d9bf8b75941ba3d6d124a0..5f9259fbbf8dcd1c47f606246385c1ccf87812ff 100644 --- a/scripts/test/Muon/PeriodicTableModel_test.py +++ b/scripts/test/Muon/PeriodicTableModel_test.py @@ -8,13 +8,9 @@ from __future__ import absolute_import, print_function import unittest +from mantid.py3compat import mock from Muon.GUI.ElementalAnalysis.PeriodicTable.periodic_table_model import PeriodicTableModel -try: - from unittest import mock -except ImportError: - import mock - class PeriodicTableModelTest(unittest.TestCase): def setUp(self): diff --git a/scripts/test/Muon/PeriodicTablePresenter_test.py b/scripts/test/Muon/PeriodicTablePresenter_test.py index 97eb33ff8603937e7cf0a14dcdf919974d4c6f91..de02e6615a602190aa77774b709235e6bc1f3f0a 100644 --- a/scripts/test/Muon/PeriodicTablePresenter_test.py +++ b/scripts/test/Muon/PeriodicTablePresenter_test.py @@ -8,19 +8,13 @@ from __future__ import absolute_import, print_function import unittest +from mantid.py3compat import mock +from Muon.GUI.Common import mock_widget from Muon.GUI.ElementalAnalysis.PeriodicTable.periodic_table_presenter import PeriodicTablePresenter from Muon.GUI.ElementalAnalysis.PeriodicTable.periodic_table_view import PeriodicTableView from Muon.GUI.ElementalAnalysis.PeriodicTable.periodic_table_model import PeriodicTableModel from Muon.GUI.ElementalAnalysis.PeriodicTable.periodic_table import PeriodicTable as silxPT, PeriodicTableItem -from Muon.GUI.Common import mock_widget - - -try: - from unittest import mock -except ImportError: - import mock - class PeriodicTablePresenterTest(unittest.TestCase): diff --git a/scripts/test/Muon/PlottingView_test.py b/scripts/test/Muon/PlottingView_test.py index 7fbe9ad99ee98bcd8b123915c3c1931674bbd68b..81ef3bfd8df754098b9c6b24853c8c38b3fd99df 100644 --- a/scripts/test/Muon/PlottingView_test.py +++ b/scripts/test/Muon/PlottingView_test.py @@ -11,19 +11,13 @@ os.environ["QT_API"] = "pyqt" # noqa E402 from matplotlib.figure import Figure -from mantid import WorkspaceFactory -from mantid import plots +from mantid import WorkspaceFactory, plots +from mantid.py3compat import mock +from Muon.GUI.Common import mock_widget from Muon.GUI.ElementalAnalysis.Plotting.subPlot_object import subPlot from Muon.GUI.ElementalAnalysis.Plotting.plotting_view import PlotView from Muon.GUI.ElementalAnalysis.Plotting.AxisChanger.axis_changer_presenter import AxisChangerPresenter -from Muon.GUI.Common import mock_widget - -try: - from unittest import mock -except ImportError: - import mock - def get_subPlot(name): data_x, data_y = [1, 2, 3, 4], [4, 5, 6, 7] diff --git a/scripts/test/Muon/grouping_tab/grouping_tab_presenter_test.py b/scripts/test/Muon/grouping_tab/grouping_tab_presenter_test.py index 4424cb55f098af3e25d7817ae1efd10b7bb8d577..c5c3e52611c16c67f8ffaf82c685bcf55388bf34 100644 --- a/scripts/test/Muon/grouping_tab/grouping_tab_presenter_test.py +++ b/scripts/test/Muon/grouping_tab/grouping_tab_presenter_test.py @@ -1,8 +1,8 @@ -import unittest -import sys -import six from PyQt4 import QtGui +import six +import unittest +from mantid.py3compat import mock from Muon.GUI.Common.grouping_table_widget.grouping_table_widget_view import GroupingTableView from Muon.GUI.Common.grouping_table_widget.grouping_table_widget_presenter import GroupingTablePresenter, MuonGroup @@ -16,11 +16,6 @@ from Muon.GUI.Common.grouping_tab_widget.grouping_tab_widget_view import Groupin from Muon.GUI.Common.muon_data_context import MuonDataContext from Muon.GUI.Common import mock_widget -if sys.version_info.major > 2: - from unittest import mock -else: - import mock - class GroupingTabPresenterTest(unittest.TestCase): def setUp(self): diff --git a/scripts/test/Muon/grouping_tab/grouping_table_presenter_test.py b/scripts/test/Muon/grouping_tab/grouping_table_presenter_test.py index 5758fbfd4b3e28d49ede51630a08090153af3e6e..357bb85105cbe83d8850dfa4573af474fe39f0f2 100644 --- a/scripts/test/Muon/grouping_tab/grouping_table_presenter_test.py +++ b/scripts/test/Muon/grouping_tab/grouping_table_presenter_test.py @@ -1,7 +1,8 @@ -import unittest -import sys -import six from PyQt4 import QtGui +import six +import unittest + +from mantid.py3compat import mock from Muon.GUI.Common.grouping_tab_widget.grouping_tab_widget_model import GroupingTabModel from Muon.GUI.Common.grouping_table_widget.grouping_table_widget_view import GroupingTableView from Muon.GUI.Common.grouping_table_widget.grouping_table_widget_presenter import GroupingTablePresenter @@ -10,10 +11,6 @@ from Muon.GUI.Common.muon_data_context import MuonDataContext from Muon.GUI.Common import mock_widget from Muon.GUI.Common.observer_pattern import Observer -if sys.version_info.major > 2: - from unittest import mock -else: - import mock maximum_number_of_groups = 20 diff --git a/scripts/test/Muon/grouping_tab/pairing_table_alpha_test.py b/scripts/test/Muon/grouping_tab/pairing_table_alpha_test.py index f7154639d4ec83cd46d25dc53342fafc7cac9fe2..f2ed6f37e58f4bc5b06ce7773c70721dd11ad37c 100644 --- a/scripts/test/Muon/grouping_tab/pairing_table_alpha_test.py +++ b/scripts/test/Muon/grouping_tab/pairing_table_alpha_test.py @@ -1,13 +1,7 @@ -import unittest -import sys - -if sys.version_info.major == 3: - from unittest import mock -else: - import mock - from PyQt4 import QtGui +import unittest +from mantid.py3compat import mock from Muon.GUI.Common.pairing_table_widget.pairing_table_widget_model import PairingTableModel from Muon.GUI.Common.pairing_table_widget.pairing_table_widget_view import PairingTableView from Muon.GUI.Common.pairing_table_widget.pairing_table_widget_presenter import PairingTablePresenter diff --git a/scripts/test/Muon/grouping_tab/pairing_table_group_selector_test.py b/scripts/test/Muon/grouping_tab/pairing_table_group_selector_test.py index 6eedaedd40164c4fda2fdb4845273e885e62516c..92963cd80da57206efc38175d40e5c0814f05779 100644 --- a/scripts/test/Muon/grouping_tab/pairing_table_group_selector_test.py +++ b/scripts/test/Muon/grouping_tab/pairing_table_group_selector_test.py @@ -1,7 +1,7 @@ -import unittest -import sys from PyQt4 import QtGui +import unittest +from mantid.py3compat import mock from Muon.GUI.Common.pairing_table_widget.pairing_table_widget_model import PairingTableModel from Muon.GUI.Common.pairing_table_widget.pairing_table_widget_view import PairingTableView from Muon.GUI.Common.pairing_table_widget.pairing_table_widget_presenter import PairingTablePresenter @@ -11,10 +11,6 @@ from Muon.GUI.Common.muon_pair import MuonPair from Muon.GUI.Common.muon_data_context import MuonDataContext from Muon.GUI.Common import mock_widget -if sys.version_info.major > 2: - from unittest import mock -else: - import mock def pair_name(): name = [] @@ -22,6 +18,7 @@ def pair_name(): name.append("pair_" + str(i+1)) return name + class GroupSelectorTest(unittest.TestCase): def setUp(self): diff --git a/scripts/test/Muon/grouping_tab/pairing_table_presenter_test.py b/scripts/test/Muon/grouping_tab/pairing_table_presenter_test.py index 924987e6d13dac6704d7b68282b86766da961994..f8f173ea46dfbae8425442d5e4018cd109287d7a 100644 --- a/scripts/test/Muon/grouping_tab/pairing_table_presenter_test.py +++ b/scripts/test/Muon/grouping_tab/pairing_table_presenter_test.py @@ -1,14 +1,8 @@ -import unittest -import sys -import six - -if sys.version_info.major == 3: - from unittest import mock -else: - import mock - from PyQt4 import QtGui +import six +import unittest +from mantid.py3compat import mock from Muon.GUI.Common.pairing_table_widget.pairing_table_widget_model import PairingTableModel from Muon.GUI.Common.pairing_table_widget.pairing_table_widget_view import PairingTableView from Muon.GUI.Common.pairing_table_widget.pairing_table_widget_presenter import PairingTablePresenter diff --git a/scripts/test/Muon/help_widget_presenter_test.py b/scripts/test/Muon/help_widget_presenter_test.py index 926666e75ef8525ba58322d683bca4ff4d52658c..afe464d73a6c4546db025d0c94b704da18e9e41a 100644 --- a/scripts/test/Muon/help_widget_presenter_test.py +++ b/scripts/test/Muon/help_widget_presenter_test.py @@ -4,18 +4,13 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import sys +import unittest +from mantid.py3compat import mock from Muon.GUI.Common.help_widget.help_widget_view import HelpWidgetView from Muon.GUI.Common.help_widget.help_widget_presenter import HelpWidgetPresenter -import unittest from Muon.GUI.Common import mock_widget -if sys.version_info.major > 2: - from unittest import mock -else: - import mock - class HelpWidgetPresenterTest(unittest.TestCase): def setUp(self): diff --git a/scripts/test/Muon/home_grouping_widget_test.py b/scripts/test/Muon/home_grouping_widget_test.py index 16452df366df24c85928710432d8b17216986ceb..f145d603688ab2bc9760245067df3c8007fcc23f 100644 --- a/scripts/test/Muon/home_grouping_widget_test.py +++ b/scripts/test/Muon/home_grouping_widget_test.py @@ -4,27 +4,21 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import sys +from PyQt4 import QtGui +import unittest +from mantid import ConfigService +from mantid.api import FileFinder +from mantid.py3compat import mock +from Muon.GUI.Common import mock_widget from Muon.GUI.Common.home_grouping_widget.home_grouping_widget_model import HomeGroupingWidgetModel from Muon.GUI.Common.home_grouping_widget.home_grouping_widget_presenter import HomeGroupingWidgetPresenter from Muon.GUI.Common.home_grouping_widget.home_grouping_widget_view import HomeGroupingWidgetView +from Muon.GUI.Common.observer_pattern import Observer from Muon.GUI.Common.muon_data_context import MuonDataContext from Muon.GUI.Common.muon_load_data import MuonLoadData -from Muon.GUI.Common import mock_widget -import unittest -from PyQt4 import QtGui -from Muon.GUI.Common.observer_pattern import Observer -from mantid.api import FileFinder -from mantid import ConfigService -import Muon.GUI.Common.utilities.load_utils as load_utils from Muon.GUI.Common.muon_pair import MuonPair - - -if sys.version_info.major < 2: - from unittest import mock -else: - import mock +import Muon.GUI.Common.utilities.load_utils as load_utils class HomeTabGroupingPresenterTest(unittest.TestCase): diff --git a/scripts/test/Muon/home_instrument_widget_test.py b/scripts/test/Muon/home_instrument_widget_test.py index 60f551561b723156cf8f2101fde306f2f43042d5..16e23c2d967c765aa0f390168c30620ec80f4183 100644 --- a/scripts/test/Muon/home_instrument_widget_test.py +++ b/scripts/test/Muon/home_instrument_widget_test.py @@ -4,22 +4,18 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import sys +from PyQt4 import QtGui +import unittest +from mantid.api import FileFinder +from mantid.py3compat import mock from Muon.GUI.Common.home_instrument_widget.home_instrument_widget_view import InstrumentWidgetView from Muon.GUI.Common.home_instrument_widget.home_instrument_widget_presenter import InstrumentWidgetPresenter from Muon.GUI.Common.home_instrument_widget.home_instrument_widget_model import InstrumentWidgetModel from Muon.GUI.Common.muon_data_context import MuonDataContext from Muon.GUI.Common import mock_widget -import unittest -from PyQt4 import QtGui -from Muon.GUI.Common.observer_pattern import Observer -from mantid.api import FileFinder -if sys.version_info.major < 2: - from unittest import mock -else: - import mock +from Muon.GUI.Common.observer_pattern import Observer class HomeTabInstrumentPresenterTest(unittest.TestCase): diff --git a/scripts/test/Muon/home_plot_widget_test.py b/scripts/test/Muon/home_plot_widget_test.py index ad82d596435056cb4ed74c7201337e0335a196fb..2b17e92b1e77637204a357eadfea7e1a5f11c149 100644 --- a/scripts/test/Muon/home_plot_widget_test.py +++ b/scripts/test/Muon/home_plot_widget_test.py @@ -4,20 +4,15 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import sys +from PyQt4 import QtGui +import unittest +from mantid.py3compat import mock from Muon.GUI.Common.home_plot_widget.home_plot_widget_view import HomePlotWidgetView from Muon.GUI.Common.home_plot_widget.home_plot_widget_presenter import HomePlotWidgetPresenter from Muon.GUI.Common.home_plot_widget.home_plot_widget_model import HomePlotWidgetModel from Muon.GUI.Common.muon_data_context import MuonDataContext from Muon.GUI.Common import mock_widget -import unittest -from PyQt4 import QtGui - -if sys.version_info.major < 2: - from unittest import mock -else: - import mock class HomeTabPlotPresenterTest(unittest.TestCase): diff --git a/scripts/test/Muon/home_runinfo_presenter_test.py b/scripts/test/Muon/home_runinfo_presenter_test.py index 9adc7496f4a11f420bf0078a91f3d1721efcff1e..b79d3005fa9c90e0c0789b66536bad99bce528a2 100644 --- a/scripts/test/Muon/home_runinfo_presenter_test.py +++ b/scripts/test/Muon/home_runinfo_presenter_test.py @@ -4,25 +4,19 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import sys +from PyQt4 import QtGui +import unittest +from mantid.api import FileFinder +from mantid.py3compat import mock +from Muon.GUI.Common import mock_widget from Muon.GUI.Common.home_runinfo_widget.home_runinfo_widget_view import HomeRunInfoWidgetView from Muon.GUI.Common.home_runinfo_widget.home_runinfo_widget_presenter import HomeRunInfoWidgetPresenter from Muon.GUI.Common.home_runinfo_widget.home_runinfo_widget_model import HomeRunInfoWidgetModel from Muon.GUI.Common.muon_data_context import MuonDataContext from Muon.GUI.Common.muon_load_data import MuonLoadData - -from Muon.GUI.Common import mock_widget -from mantid.api import FileFinder -import Muon.GUI.Common.utilities.load_utils as load_utils from Muon.GUI.Common.muon_pair import MuonPair -import unittest -from PyQt4 import QtGui - -if sys.version_info.major < 2: - from unittest import mock -else: - import mock +import Muon.GUI.Common.utilities.load_utils as load_utils class HomeTabRunInfoPresenterTest(unittest.TestCase): diff --git a/scripts/test/Muon/load_file_widget/loadfile_presenter_multiple_file_test.py b/scripts/test/Muon/load_file_widget/loadfile_presenter_multiple_file_test.py index e322d74dff71dc8410be020067091d0fdaeade9a..55604f9a76927900cfeda636041919aaa05fd5eb 100644 --- a/scripts/test/Muon/load_file_widget/loadfile_presenter_multiple_file_test.py +++ b/scripts/test/Muon/load_file_widget/loadfile_presenter_multiple_file_test.py @@ -1,12 +1,7 @@ import six -import sys import unittest -if sys.version_info.major == 3: - from unittest import mock -else: - import mock - +from mantid.py3compat import mock from Muon.GUI.Common import mock_widget from Muon.GUI.Common.load_file_widget.view import BrowseFileWidgetView from Muon.GUI.Common.load_file_widget.presenter import BrowseFileWidgetPresenter diff --git a/scripts/test/Muon/load_file_widget/loadfile_presenter_single_file_test.py b/scripts/test/Muon/load_file_widget/loadfile_presenter_single_file_test.py index dba80fd0167520db4bbed26a97f22f3e3da48901..e7602f0f9eda02cb3d11185d9bc7e6c56fa7720e 100644 --- a/scripts/test/Muon/load_file_widget/loadfile_presenter_single_file_test.py +++ b/scripts/test/Muon/load_file_widget/loadfile_presenter_single_file_test.py @@ -4,14 +4,9 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import sys import unittest -if sys.version_info.major == 3: - from unittest import mock -else: - import mock - +from mantid.py3compat import mock from Muon.GUI.Common.load_file_widget.view import BrowseFileWidgetView from Muon.GUI.Common.load_file_widget.presenter import BrowseFileWidgetPresenter from Muon.GUI.Common.load_file_widget.model import BrowseFileWidgetModel diff --git a/scripts/test/Muon/load_run_widget/loadrun_model_test.py b/scripts/test/Muon/load_run_widget/loadrun_model_test.py index 99ef947b90133cc0710a9ab74a05642ea13bcfee..455f7b3057225dcdc705cd4096cbb4adfb308138 100644 --- a/scripts/test/Muon/load_run_widget/loadrun_model_test.py +++ b/scripts/test/Muon/load_run_widget/loadrun_model_test.py @@ -4,18 +4,13 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import sys +import unittest +from mantid.py3compat import mock from Muon.GUI.Common.load_run_widget.load_run_model import LoadRunWidgetModel +from Muon.GUI.Common.muon_data_context import MuonDataContext from Muon.GUI.Common.muon_load_data import MuonLoadData from Muon.GUI.Common.utilities.muon_test_helpers import IteratorWithException -import unittest -from Muon.GUI.Common.muon_data_context import MuonDataContext - -if sys.version_info.major == 3: - from unittest import mock -else: - import mock class LoadRunWidgetModelTest(unittest.TestCase): diff --git a/scripts/test/Muon/load_run_widget/loadrun_presenter_current_run_test.py b/scripts/test/Muon/load_run_widget/loadrun_presenter_current_run_test.py index 61cf0fcaa98e648669dae0696c5fb34fb1d0048b..10a239f862e9758bb718619fcfbdbe9fe9ea7eff 100644 --- a/scripts/test/Muon/load_run_widget/loadrun_presenter_current_run_test.py +++ b/scripts/test/Muon/load_run_widget/loadrun_presenter_current_run_test.py @@ -4,25 +4,18 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import sys +from PyQt4 import QtGui +import unittest + +from mantid.py3compat import mock from Muon.GUI.Common.load_run_widget.load_run_model import LoadRunWidgetModel from Muon.GUI.Common.load_run_widget.load_run_view import LoadRunWidgetView from Muon.GUI.Common.load_run_widget.load_run_presenter import LoadRunWidgetPresenter from Muon.GUI.Common import mock_widget from Muon.GUI.Common.muon_data_context import MuonDataContext - from Muon.GUI.Common.muon_load_data import MuonLoadData import Muon.GUI.Common.utilities.muon_file_utils as fileUtils -import unittest - -if sys.version_info.major == 3: - from unittest import mock -else: - import mock - -from PyQt4 import QtGui - class LoadRunWidgetLoadCurrentRunTest(unittest.TestCase): def run_test_with_and_without_threading(test_function): diff --git a/scripts/test/Muon/load_run_widget/loadrun_presenter_increment_decrement_test.py b/scripts/test/Muon/load_run_widget/loadrun_presenter_increment_decrement_test.py index 3c8e05d9a722e4bd34b0ff58f1d265e0fbefaca3..0f1896d20a1459359ecdd1d072bdf137ccbe7d23 100644 --- a/scripts/test/Muon/load_run_widget/loadrun_presenter_increment_decrement_test.py +++ b/scripts/test/Muon/load_run_widget/loadrun_presenter_increment_decrement_test.py @@ -4,9 +4,11 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import sys +from PyQt4 import QtGui import os +import unittest +from mantid.py3compat import mock from Muon.GUI.Common.load_run_widget.load_run_model import LoadRunWidgetModel from Muon.GUI.Common.load_run_widget.load_run_view import LoadRunWidgetView from Muon.GUI.Common.load_run_widget.load_run_presenter import LoadRunWidgetPresenter @@ -14,15 +16,6 @@ from Muon.GUI.Common import mock_widget from Muon.GUI.Common.muon_data_context import MuonDataContext from Muon.GUI.Common.muon_load_data import MuonLoadData -import unittest - -if sys.version_info.major == 3: - from unittest import mock -else: - import mock - -from PyQt4 import QtGui - class LoadRunWidgetIncrementDecrementSingleFileModeTest(unittest.TestCase): def run_test_with_and_without_threading(test_function): diff --git a/scripts/test/Muon/load_run_widget/loadrun_presenter_multiple_file_test.py b/scripts/test/Muon/load_run_widget/loadrun_presenter_multiple_file_test.py index 3340d0ecefb927497d837ecb048559ce9a343c37..98d388871fbbb8b9159361dd70e4780d74c236db 100644 --- a/scripts/test/Muon/load_run_widget/loadrun_presenter_multiple_file_test.py +++ b/scripts/test/Muon/load_run_widget/loadrun_presenter_multiple_file_test.py @@ -4,25 +4,19 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import sys +from PyQt4 import QtGui import six +import unittest + +from mantid.py3compat import mock from Muon.GUI.Common.load_run_widget.load_run_model import LoadRunWidgetModel from Muon.GUI.Common.load_run_widget.load_run_view import LoadRunWidgetView from Muon.GUI.Common.load_run_widget.load_run_presenter import LoadRunWidgetPresenter - from Muon.GUI.Common import mock_widget from Muon.GUI.Common.muon_data_context import MuonDataContext from Muon.GUI.Common.muon_load_data import MuonLoadData -import unittest -from PyQt4 import QtGui - -if sys.version_info.major == 3: - from unittest import mock -else: - import mock - class LoadRunWidgetIncrementDecrementMultipleFileModeTest(unittest.TestCase): def run_test_with_and_without_threading(test_function): diff --git a/scripts/test/Muon/load_run_widget/loadrun_presenter_single_file_test.py b/scripts/test/Muon/load_run_widget/loadrun_presenter_single_file_test.py index ff80ce9d2e7f54371ed9ca79add7015969c30eb3..fdf37140bf4e201f438c891a5c37b5a0981996ff 100644 --- a/scripts/test/Muon/load_run_widget/loadrun_presenter_single_file_test.py +++ b/scripts/test/Muon/load_run_widget/loadrun_presenter_single_file_test.py @@ -4,26 +4,18 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import sys +from PyQt4 import QtGui import os +import unittest +from mantid.py3compat import mock +from Muon.GUI.Common import mock_widget from Muon.GUI.Common.load_run_widget.load_run_model import LoadRunWidgetModel from Muon.GUI.Common.load_run_widget.load_run_view import LoadRunWidgetView from Muon.GUI.Common.load_run_widget.load_run_presenter import LoadRunWidgetPresenter - -from Muon.GUI.Common import mock_widget from Muon.GUI.Common.muon_data_context import MuonDataContext from Muon.GUI.Common.muon_load_data import MuonLoadData -import unittest - -if sys.version_info.major == 3: - from unittest import mock -else: - import mock - -from PyQt4 import QtGui - class LoadRunWidgetPresenterTest(unittest.TestCase): def run_test_with_and_without_threading(test_function): diff --git a/scripts/test/Muon/loading_tab/loadwidget_presenter_failure_test.py b/scripts/test/Muon/loading_tab/loadwidget_presenter_failure_test.py index f759651c4abbeb47fe3b79197d24a23fa828f8e7..4020aa032edd8bad9a9aa5651e92419138a14b76 100644 --- a/scripts/test/Muon/loading_tab/loadwidget_presenter_failure_test.py +++ b/scripts/test/Muon/loading_tab/loadwidget_presenter_failure_test.py @@ -4,19 +4,10 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import unittest - -try: - from unittest import mock -except ImportError: - import mock - from PyQt4 import QtGui +import unittest -from Muon.GUI.MuonAnalysis.load_widget.load_widget_model import LoadWidgetModel -from Muon.GUI.MuonAnalysis.load_widget.load_widget_view import LoadWidgetView -from Muon.GUI.MuonAnalysis.load_widget.load_widget_presenter import LoadWidgetPresenter - +from mantid.py3compat import mock from Muon.GUI.Common.load_run_widget.load_run_model import LoadRunWidgetModel from Muon.GUI.Common.load_run_widget.load_run_view import LoadRunWidgetView from Muon.GUI.Common.load_run_widget.load_run_presenter import LoadRunWidgetPresenter @@ -30,6 +21,10 @@ from Muon.GUI.Common.muon_load_data import MuonLoadData from Muon.GUI.Common.muon_data_context import MuonDataContext import Muon.GUI.Common.utilities.muon_file_utils as file_utils +from Muon.GUI.MuonAnalysis.load_widget.load_widget_model import LoadWidgetModel +from Muon.GUI.MuonAnalysis.load_widget.load_widget_view import LoadWidgetView +from Muon.GUI.MuonAnalysis.load_widget.load_widget_presenter import LoadWidgetPresenter + class LoadRunWidgetPresenterLoadFailTest(unittest.TestCase): def wait_for_thread(self, thread_model): diff --git a/scripts/test/Muon/loading_tab/loadwidget_presenter_multiple_file_test.py b/scripts/test/Muon/loading_tab/loadwidget_presenter_multiple_file_test.py index 566aa68c5240eb0e23804ce1551e1e26d1e54df0..939835504d871a6b52b71afe8db16d217c80289c 100644 --- a/scripts/test/Muon/loading_tab/loadwidget_presenter_multiple_file_test.py +++ b/scripts/test/Muon/loading_tab/loadwidget_presenter_multiple_file_test.py @@ -4,19 +4,12 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import unittest - -try: - from unittest import mock -except ImportError: - import mock - from PyQt4 import QtGui +import unittest -from Muon.GUI.MuonAnalysis.load_widget.load_widget_model import LoadWidgetModel -from Muon.GUI.MuonAnalysis.load_widget.load_widget_view import LoadWidgetView -from Muon.GUI.MuonAnalysis.load_widget.load_widget_presenter import LoadWidgetPresenter - +from mantid import ConfigService +from mantid.api import FileFinder +from mantid.py3compat import mock from Muon.GUI.Common.load_run_widget.load_run_model import LoadRunWidgetModel from Muon.GUI.Common.load_run_widget.load_run_view import LoadRunWidgetView from Muon.GUI.Common.load_run_widget.load_run_presenter import LoadRunWidgetPresenter @@ -27,8 +20,10 @@ from Muon.GUI.Common.load_file_widget.model import BrowseFileWidgetModel from Muon.GUI.Common.muon_load_data import MuonLoadData from Muon.GUI.Common.muon_data_context import MuonDataContext from Muon.GUI.Common import mock_widget -from mantid.api import FileFinder -from mantid import ConfigService + +from Muon.GUI.MuonAnalysis.load_widget.load_widget_model import LoadWidgetModel +from Muon.GUI.MuonAnalysis.load_widget.load_widget_view import LoadWidgetView +from Muon.GUI.MuonAnalysis.load_widget.load_widget_presenter import LoadWidgetPresenter class LoadRunWidgetPresenterMultipleFileTest(unittest.TestCase): diff --git a/scripts/test/Muon/loading_tab/loadwidget_presenter_test.py b/scripts/test/Muon/loading_tab/loadwidget_presenter_test.py index ac69d564accb9105b946499c5cea7080c4826cd1..6396c7c4e41c1d195bd16b8a6b79f483f44cee25 100644 --- a/scripts/test/Muon/loading_tab/loadwidget_presenter_test.py +++ b/scripts/test/Muon/loading_tab/loadwidget_presenter_test.py @@ -4,19 +4,11 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import unittest - -try: - from unittest import mock -except ImportError: - import mock - from PyQt4 import QtGui +import unittest -from Muon.GUI.MuonAnalysis.load_widget.load_widget_model import LoadWidgetModel -from Muon.GUI.MuonAnalysis.load_widget.load_widget_view import LoadWidgetView -from Muon.GUI.MuonAnalysis.load_widget.load_widget_presenter import LoadWidgetPresenter - +from mantid.api import FileFinder +from mantid.py3compat import mock from Muon.GUI.Common.load_run_widget.load_run_model import LoadRunWidgetModel from Muon.GUI.Common.load_run_widget.load_run_view import LoadRunWidgetView from Muon.GUI.Common.load_run_widget.load_run_presenter import LoadRunWidgetPresenter @@ -29,7 +21,10 @@ from Muon.GUI.Common import mock_widget from Muon.GUI.Common.muon_load_data import MuonLoadData from Muon.GUI.Common.muon_data_context import MuonDataContext import Muon.GUI.Common.utilities.muon_file_utils as file_utils -from mantid.api import FileFinder + +from Muon.GUI.MuonAnalysis.load_widget.load_widget_model import LoadWidgetModel +from Muon.GUI.MuonAnalysis.load_widget.load_widget_view import LoadWidgetView +from Muon.GUI.MuonAnalysis.load_widget.load_widget_presenter import LoadWidgetPresenter class LoadRunWidgetPresenterTest(unittest.TestCase): diff --git a/scripts/test/Muon/muon_data_context_test.py b/scripts/test/Muon/muon_data_context_test.py index 4b2c1f11b4992a3f930a5648845f30ffe41e2bfe..0126a873ca15129e813f3b96d720b6f80641a745 100644 --- a/scripts/test/Muon/muon_data_context_test.py +++ b/scripts/test/Muon/muon_data_context_test.py @@ -4,22 +4,15 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import sys +import copy +import unittest + +from mantid.api import AnalysisDataService, FileFinder +from mantid.py3compat import mock from Muon.GUI.Common.muon_load_data import MuonLoadData from Muon.GUI.Common.utilities.load_utils import load_workspace_from_filename from Muon.GUI.Common.muon_data_context import MuonDataContext -from mantid.api import AnalysisDataService -import unittest from Muon.GUI.Common.observer_pattern import Observer -from mantid.api import FileFinder - - -import copy - -if sys.version_info.major < 2: - from unittest import mock -else: - import mock class MuonDataContextTest(unittest.TestCase): diff --git a/scripts/test/Muon/transformWidget_test.py b/scripts/test/Muon/transformWidget_test.py index db45accc41cb0d51e3d7f83a85c6ba58cd8636fb..dd097ede3551aec4aa4d6c2a1cf224de024e687d 100644 --- a/scripts/test/Muon/transformWidget_test.py +++ b/scripts/test/Muon/transformWidget_test.py @@ -4,23 +4,17 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import sys - -from Muon.GUI.Common import mock_widget -from Muon.GUI.Common.utilities import load_utils -from Muon.GUI.FrequencyDomainAnalysis.FFT import fft_presenter -from Muon.GUI.FrequencyDomainAnalysis.Transform import transform_widget -from Muon.GUI.FrequencyDomainAnalysis.Transform import transform_view -from Muon.GUI.FrequencyDomainAnalysis.TransformSelection import transform_selection_view -from Muon.GUI.FrequencyDomainAnalysis.MaxEnt import maxent_presenter +import unittest +from mantid.py3compat import mock +from Muon.GUI.Common import mock_widget +from Muon.GUI.Common.utilities import load_utils +from Muon.GUI.FrequencyDomainAnalysis.FFT import fft_presenter +from Muon.GUI.FrequencyDomainAnalysis.Transform import transform_widget +from Muon.GUI.FrequencyDomainAnalysis.Transform import transform_view +from Muon.GUI.FrequencyDomainAnalysis.TransformSelection import transform_selection_view +from Muon.GUI.FrequencyDomainAnalysis.MaxEnt import maxent_presenter -# need to update this -import unittest -if sys.version_info.major == 3: - from unittest import mock -else: - import mock class TransformTest(unittest.TestCase): def setUp(self): diff --git a/scripts/test/Muon/utilities/load_utils_test.py b/scripts/test/Muon/utilities/load_utils_test.py index 8e3f515205c1c952e1e051e8cc997e52c35d8b60..b820f64e062af01ac65c7812cfb292f97f0fa8af 100644 --- a/scripts/test/Muon/utilities/load_utils_test.py +++ b/scripts/test/Muon/utilities/load_utils_test.py @@ -5,17 +5,12 @@ # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + import Muon.GUI.Common.utilities.load_utils as utils -import sys import os +import unittest + from mantid import simpleapi, ConfigService from mantid.api import AnalysisDataService, ITableWorkspace -import unittest - -if sys.version_info.major > 2: - from unittest import mock -else: - import mock def create_simple_workspace(data_x, data_y, run_number=0): alg = simpleapi.AlgorithmManager.create("CreateWorkspace") diff --git a/scripts/test/Muon/utilities/muon_file_utils_test.py b/scripts/test/Muon/utilities/muon_file_utils_test.py index ef16f09948a656862a5a9f54e44315d55c903101..7036bbbb5cc659ae27bb682280e8e8c328d4aaae 100644 --- a/scripts/test/Muon/utilities/muon_file_utils_test.py +++ b/scripts/test/Muon/utilities/muon_file_utils_test.py @@ -4,16 +4,11 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + -import Muon.GUI.Common.utilities.muon_file_utils as utils -import sys import os - import unittest -if sys.version_info.major == 3: - from unittest import mock -else: - import mock +from mantid.py3compat import mock +import Muon.GUI.Common.utilities.muon_file_utils as utils class MuonFileUtilsTest(unittest.TestCase): diff --git a/scripts/test/Muon/utilities/muon_load_data_test.py b/scripts/test/Muon/utilities/muon_load_data_test.py index 3f1e6e86cf26b06f0e5b9b97384201d08991d9c7..102abcf3e7c602a88d95088a47ce94124f5d0ff8 100644 --- a/scripts/test/Muon/utilities/muon_load_data_test.py +++ b/scripts/test/Muon/utilities/muon_load_data_test.py @@ -7,12 +7,10 @@ from __future__ import (absolute_import, division, print_function) import unittest -import sys + +from mantid.py3compat import mock from Muon.GUI.Common.muon_load_data import MuonLoadData -if sys.version_info.major > 2: - from unittest import mock -else: - import mock + class MuonLoadDataTest(unittest.TestCase): diff --git a/scripts/test/Muon/utilities/thread_model_test.py b/scripts/test/Muon/utilities/thread_model_test.py index 1c32fa0698b2012eaf192ab81e0939289487098a..50d7a583b06ff2fb10a817ff220408d02fad06e6 100644 --- a/scripts/test/Muon/utilities/thread_model_test.py +++ b/scripts/test/Muon/utilities/thread_model_test.py @@ -5,15 +5,11 @@ # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + import unittest -import sys + +from mantid.py3compat import mock from Muon.GUI.Common.thread_model import ThreadModel from Muon.GUI.Common import mock_widget -if sys.version_info.major == 3: - from unittest import mock -else: - import mock - class testModelWithoutExecute: diff --git a/scripts/test/SANS/algorithm_detail/batch_execution_test.py b/scripts/test/SANS/algorithm_detail/batch_execution_test.py index 5e348a72d2528c3fb9dc11df85b859801a85a90a..082d604424fba23d8f1d52ea480790c0bf48ecb2 100644 --- a/scripts/test/SANS/algorithm_detail/batch_execution_test.py +++ b/scripts/test/SANS/algorithm_detail/batch_execution_test.py @@ -5,14 +5,12 @@ # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + from __future__ import (absolute_import, division, print_function) + import unittest -import sys -from sans.algorithm_detail.batch_execution import get_all_names_to_save, ReductionPackage + from mantid.simpleapi import CreateSampleWorkspace -if sys.version_info.major > 2: - from unittest import mock -else: - import mock +from mantid.py3compat import mock +from sans.algorithm_detail.batch_execution import get_all_names_to_save, ReductionPackage class GetAllNamesToSaveTest(unittest.TestCase): diff --git a/scripts/test/SANS/algorithm_detail/centre_finder_new_test.py b/scripts/test/SANS/algorithm_detail/centre_finder_new_test.py index 5b251676a2d9dc03d58656c266dcf57df3d275d5..9c08696fa7c9dc2d38e7f845e97ec0dc1a9f3341 100644 --- a/scripts/test/SANS/algorithm_detail/centre_finder_new_test.py +++ b/scripts/test/SANS/algorithm_detail/centre_finder_new_test.py @@ -7,15 +7,11 @@ from __future__ import (absolute_import, division, print_function) import unittest -import sys + +from mantid.py3compat import mock from sans.algorithm_detail.centre_finder_new import centre_finder_new, centre_finder_mass from sans.common.enums import (SANSDataType, FindDirectionEnum, DetectorType) -if sys.version_info.major == 3: - from unittest import mock -else: - import mock - class CentreFinderNewTest(unittest.TestCase): def setUp(self): diff --git a/scripts/test/SANS/gui_logic/add_runs_presenter_test.py b/scripts/test/SANS/gui_logic/add_runs_presenter_test.py index cb0c311cd9e9e005ba26e35b2ff9a5aacd43aed2..c1081ec8f52a99ab3fa4cae599ed3eb8427fe05b 100644 --- a/scripts/test/SANS/gui_logic/add_runs_presenter_test.py +++ b/scripts/test/SANS/gui_logic/add_runs_presenter_test.py @@ -5,10 +5,9 @@ # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + import unittest -import sys from mantid.kernel import ConfigService -from sans.common.enums import SANSInstrument +from mantid.py3compat import mock from sans.gui_logic.models.run_summation import RunSummation from sans.gui_logic.models.run_file import SummableRunFile from sans.gui_logic.models.run_selection import RunSelection @@ -21,11 +20,6 @@ from ui.sans_isis.sans_data_processor_gui import SANSDataProcessorGui from fake_signal import FakeSignal from assert_called import assert_called -if sys.version_info.major == 2: - import mock -else: - from unittest import mock - class MockedOutAddRunsFilenameManager(AddRunsFilenameManager): def __init__(self): diff --git a/scripts/test/SANS/gui_logic/batch_process_runner_test.py b/scripts/test/SANS/gui_logic/batch_process_runner_test.py index 9ad50a0655d793d2afa7b732db149aa0f98a3fc4..dc1611a6b5acffd89e81cea52a9cf94b7d20c83f 100644 --- a/scripts/test/SANS/gui_logic/batch_process_runner_test.py +++ b/scripts/test/SANS/gui_logic/batch_process_runner_test.py @@ -5,16 +5,13 @@ # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + from __future__ import (absolute_import, division, print_function) -from sans.gui_logic.models.batch_process_runner import BatchProcessRunner -import unittest -import sys -from sans.common.enums import (OutputMode) + from qtpy.QtCore import QThreadPool +import unittest -if sys.version_info.major > 2: - from unittest import mock -else: - import mock +from mantid.py3compat import mock +from sans.common.enums import (OutputMode) +from sans.gui_logic.models.batch_process_runner import BatchProcessRunner class BatchProcessRunnerTest(unittest.TestCase): diff --git a/scripts/test/SANS/gui_logic/beam_centre_model_test.py b/scripts/test/SANS/gui_logic/beam_centre_model_test.py index 1050c26e989a9be300e732c5bcf5fe19d6090ba8..0a5c6f2247914a1d2271e29b2f341e666e942b10 100644 --- a/scripts/test/SANS/gui_logic/beam_centre_model_test.py +++ b/scripts/test/SANS/gui_logic/beam_centre_model_test.py @@ -7,7 +7,8 @@ from __future__ import (absolute_import, division, print_function) import unittest -import sys + +from mantid.py3compat import mock from sans.gui_logic.models.beam_centre_model import BeamCentreModel from sans.common.enums import FindDirectionEnum, SANSInstrument, DetectorType, SANSFacility from sans.test_helper.test_director import TestDirector @@ -15,12 +16,6 @@ from sans.state.data import get_data_builder from sans.test_helper.file_information_mock import SANSFileInformationMock -if sys.version_info.major == 3: - from unittest import mock -else: - import mock - - class BeamCentreModelTest(unittest.TestCase): def setUp(self): self.result = {'pos1':300, 'pos2':-300} diff --git a/scripts/test/SANS/gui_logic/beam_centre_presenter_test.py b/scripts/test/SANS/gui_logic/beam_centre_presenter_test.py index 2f1ebe66d98f828399ad8440b2f70586d830d2ae..6692af4249cb5e079615a4a3daeaed881d99d2df 100644 --- a/scripts/test/SANS/gui_logic/beam_centre_presenter_test.py +++ b/scripts/test/SANS/gui_logic/beam_centre_presenter_test.py @@ -5,16 +5,14 @@ # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + from __future__ import (absolute_import, division, print_function) + import unittest -import sys + +from mantid.py3compat import mock from sans.test_helper.mock_objects import create_mock_beam_centre_tab from sans.common.enums import SANSInstrument from sans.gui_logic.presenter.beam_centre_presenter import BeamCentrePresenter from sans.test_helper.mock_objects import (create_run_tab_presenter_mock) -if sys.version_info.major == 3: - from unittest import mock -else: - import mock class BeamCentrePresenterTest(unittest.TestCase): diff --git a/scripts/test/SANS/gui_logic/create_file_information_test.py b/scripts/test/SANS/gui_logic/create_file_information_test.py index 924f509359a3599169c4c909dacc0dd5eb37c50f..c4d04f1584e734e2ed41643a71c713893d04bd69 100644 --- a/scripts/test/SANS/gui_logic/create_file_information_test.py +++ b/scripts/test/SANS/gui_logic/create_file_information_test.py @@ -4,18 +4,12 @@ # NScD Oak Ridge National Laboratory, European Spallation Source # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + +from qtpy.QtCore import QCoreApplication +import unittest +from mantid.py3compat import mock from sans.gui_logic.presenter.create_file_information import create_file_information from ui.sans_isis.work_handler import WorkHandler -import sys -import unittest -from qtpy.QtCore import QCoreApplication - -if sys.version_info.major == 3: - from unittest import mock -else: - import mock - class CreateFileInformationTest(unittest.TestCase): def setUp(self): diff --git a/scripts/test/SANS/gui_logic/create_state_test.py b/scripts/test/SANS/gui_logic/create_state_test.py index 6917ab2370bd9a89599b13c0306197064eb6d2b9..799011503e5d09d959646f124a8d0b55d862165e 100644 --- a/scripts/test/SANS/gui_logic/create_state_test.py +++ b/scripts/test/SANS/gui_logic/create_state_test.py @@ -7,8 +7,8 @@ from __future__ import (absolute_import, division, print_function) import unittest -import sys +from mantid.py3compat import mock from sans.gui_logic.models.create_state import (create_states, create_gui_state_from_userfile) from sans.common.enums import (SANSInstrument, ISISReductionMode, SANSFacility, SaveType) from sans.gui_logic.models.state_gui_model import StateGuiModel @@ -16,10 +16,6 @@ from sans.gui_logic.models.table_model import TableModel, TableIndexModel from sans.state.state import State from qtpy.QtCore import QCoreApplication -if sys.version_info.major == 3: - from unittest import mock -else: - import mock class GuiCommonTest(unittest.TestCase): def setUp(self): diff --git a/scripts/test/SANS/gui_logic/diagnostics_page_presenter_test.py b/scripts/test/SANS/gui_logic/diagnostics_page_presenter_test.py index 593766b219aceb7b427f66b4d7ed22c2b3a76310..e06af9e7fefe219f72319f1c06af14d683a8ada4 100644 --- a/scripts/test/SANS/gui_logic/diagnostics_page_presenter_test.py +++ b/scripts/test/SANS/gui_logic/diagnostics_page_presenter_test.py @@ -5,18 +5,15 @@ # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + from __future__ import (absolute_import, division, print_function) + import unittest -import sys + +from mantid.py3compat import mock from sans.test_helper.mock_objects import create_mock_diagnostics_tab from sans.common.enums import SANSInstrument, DetectorType, IntegralEnum, SANSFacility from sans.gui_logic.presenter.diagnostic_presenter import DiagnosticsPagePresenter from sans.test_helper.mock_objects import (create_run_tab_presenter_mock) -if sys.version_info.major > 2: - from unittest import mock -else: - import mock - class DiagnosticsPagePresenterTest(unittest.TestCase): def setUp(self): diff --git a/scripts/test/SANS/gui_logic/masking_table_presenter_test.py b/scripts/test/SANS/gui_logic/masking_table_presenter_test.py index 6ed0f59bab69f6c523cf7aa3e32e9333995ce829..b1eab6ded90e9b662c13f9b5ddf24148e9267c4e 100644 --- a/scripts/test/SANS/gui_logic/masking_table_presenter_test.py +++ b/scripts/test/SANS/gui_logic/masking_table_presenter_test.py @@ -7,14 +7,10 @@ from __future__ import (absolute_import, division, print_function) import unittest -import sys +from mantid.py3compat import mock from sans.gui_logic.presenter.masking_table_presenter import (MaskingTablePresenter, masking_information) from sans.test_helper.mock_objects import (FakeParentPresenter, FakeState, create_mock_masking_table, create_run_tab_presenter_mock) -if sys.version_info.major == 3: - from unittest import mock -else: - import mock class MaskingTablePresenterTest(unittest.TestCase): diff --git a/scripts/test/SANS/gui_logic/run_selector_presenter_test.py b/scripts/test/SANS/gui_logic/run_selector_presenter_test.py index c4b599748482ee5360237b6f9a7415401f24c1d6..e91b7cd520141352d325774a7c6d3574f9547d38 100644 --- a/scripts/test/SANS/gui_logic/run_selector_presenter_test.py +++ b/scripts/test/SANS/gui_logic/run_selector_presenter_test.py @@ -5,7 +5,8 @@ # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + import unittest -import sys + +from mantid.py3compat import mock from sans.gui_logic.presenter.run_selector_presenter import RunSelectorPresenter from sans.gui_logic.models.run_selection import RunSelection from sans.gui_logic.models.run_finder import SummableRunFinder @@ -14,10 +15,6 @@ from ui.sans_isis.run_selector_widget import RunSelectorWidget from fake_signal import FakeSignal from assert_called import assert_called -if sys.version_info.major == 2: - import mock -else: - from unittest import mock class RunSelectorPresenterTest(unittest.TestCase): diff --git a/scripts/test/SANS/gui_logic/run_tab_presenter_test.py b/scripts/test/SANS/gui_logic/run_tab_presenter_test.py index 472ed3db4a5dc39e6f055a9927751d92f4a1a8be..2e7500a0127084fce6b052bda1c71e857534f4ec 100644 --- a/scripts/test/SANS/gui_logic/run_tab_presenter_test.py +++ b/scripts/test/SANS/gui_logic/run_tab_presenter_test.py @@ -8,10 +8,10 @@ from __future__ import (absolute_import, division, print_function) import unittest -import sys from mantid.kernel import config from mantid.kernel import PropertyManagerDataService +from mantid.py3compat import mock from sans.gui_logic.presenter.run_tab_presenter import RunTabPresenter from sans.common.enums import (SANSFacility, ReductionDimensionality, SaveType, ISISReductionMode, @@ -24,10 +24,6 @@ from sans.common.enums import BatchReductionEntry, SANSInstrument from sans.gui_logic.models.table_model import TableModel, TableIndexModel from sans.test_helper.file_information_mock import SANSFileInformationMock -if sys.version_info.major >= 3: - from unittest import mock -else: - import mock BATCH_FILE_TEST_CONTENT_1 = [{BatchReductionEntry.SampleScatter: 1, BatchReductionEntry.SampleTransmission: 2, BatchReductionEntry.SampleDirect: 3, BatchReductionEntry.Output: 'test_file', diff --git a/scripts/test/SANS/gui_logic/save_other_presenter_test.py b/scripts/test/SANS/gui_logic/save_other_presenter_test.py index e1ecbf325564d2ad05d4e5aa09b2d42f854f7e6c..27223a47d4868b22ba7a9c59a19fb2e44dac0bd8 100644 --- a/scripts/test/SANS/gui_logic/save_other_presenter_test.py +++ b/scripts/test/SANS/gui_logic/save_other_presenter_test.py @@ -5,14 +5,12 @@ # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + from __future__ import (absolute_import, division, print_function) + import unittest -import sys + from mantid import ConfigService +from mantid.py3compat import mock from sans.gui_logic.presenter.save_other_presenter import SaveOtherPresenter -if sys.version_info.major == 3: - from unittest import mock -else: - import mock class SaveOtherPresenterTest(unittest.TestCase): diff --git a/scripts/test/SANS/gui_logic/settings_diagnostic_presenter_test.py b/scripts/test/SANS/gui_logic/settings_diagnostic_presenter_test.py index 3721cc1eecfdfb0c6a3708c57be9bf9bb1c8bd0e..ca7a1d7786124d15f525938c1429549e4f67f81e 100644 --- a/scripts/test/SANS/gui_logic/settings_diagnostic_presenter_test.py +++ b/scripts/test/SANS/gui_logic/settings_diagnostic_presenter_test.py @@ -8,18 +8,14 @@ from __future__ import (absolute_import, division, print_function) import tempfile import unittest -import sys import os import json import mantid +from mantid.py3compat import mock from sans.gui_logic.presenter.settings_diagnostic_presenter import SettingsDiagnosticPresenter from sans.test_helper.mock_objects import (create_run_tab_presenter_mock, FakeState, create_mock_settings_diagnostic_tab) -if sys.version_info.major == 3: - from unittest import mock -else: - import mock class SettingsDiagnosticPresenterTest(unittest.TestCase): diff --git a/scripts/test/SANS/gui_logic/summation_settings_presenter_test.py b/scripts/test/SANS/gui_logic/summation_settings_presenter_test.py index ea49a71d0ad8463f1269c67cc201b180ffc599ab..f846a17a5b78f687fbce210900d03b2a8ca5d80b 100644 --- a/scripts/test/SANS/gui_logic/summation_settings_presenter_test.py +++ b/scripts/test/SANS/gui_logic/summation_settings_presenter_test.py @@ -5,7 +5,8 @@ # & Institut Laue - Langevin # SPDX - License - Identifier: GPL - 3.0 + import unittest -import sys + +from mantid.py3compat import mock from sans.gui_logic.presenter.summation_settings_presenter import SummationSettingsPresenter from sans.gui_logic.models.summation_settings import SummationSettings from sans.gui_logic.models.binning_type import BinningType @@ -13,10 +14,6 @@ from ui.sans_isis.summation_settings_widget import SummationSettingsWidget from fake_signal import FakeSignal from assert_called import assert_called -if sys.version_info.major == 3: - from unittest import mock -else: - import mock class SummationSettingsPresenterTest(unittest.TestCase): diff --git a/scripts/test/SANS/gui_logic/table_model_test.py b/scripts/test/SANS/gui_logic/table_model_test.py index 69ddcb7606ac59e0a303191bf8f399b08618c0d6..1b369e1485d6b2b8ea96fac1208f6a2bf48d6ffd 100644 --- a/scripts/test/SANS/gui_logic/table_model_test.py +++ b/scripts/test/SANS/gui_logic/table_model_test.py @@ -8,14 +8,11 @@ from __future__ import (absolute_import, division, print_function) import unittest +from mantid.py3compat import mock from sans.gui_logic.models.table_model import (TableModel, TableIndexModel, OptionsColumnModel, SampleShapeColumnModel, options_column_bool) from sans.gui_logic.models.basic_hint_strategy import BasicHintStrategy from qtpy.QtCore import QCoreApplication from sans.common.enums import (RowState, SampleShape) -try: - from unittest import mock -except: - import mock class TableModelTest(unittest.TestCase): diff --git a/scripts/test/TOFTOF/TOFTOFGUITest.py b/scripts/test/TOFTOF/TOFTOFGUITest.py index 548ff97ddb49c727ea3e11f24b47936d74674c14..a30164ddaedc9f4b28a837769f1c3e15e321d948 100644 --- a/scripts/test/TOFTOF/TOFTOFGUITest.py +++ b/scripts/test/TOFTOF/TOFTOFGUITest.py @@ -6,15 +6,13 @@ # SPDX - License - Identifier: GPL - 3.0 + from __future__ import (absolute_import, division, print_function) +from qtpy.QtWidgets import QApplication +import unittest + +from mantid.py3compat import mock from reduction_gui.reduction.toftof.toftof_reduction import TOFTOFScriptElement, OptionalFloat from reduction_gui.widgets.toftof.toftof_setup import TOFTOFSetupWidget -from qtpy.QtWidgets import QApplication -import unittest -try: - from unittest import mock -except ImportError: - import mock try: unicode('test for unicode type')