From 0be88490f0ce22f19f42284db2d9340a759384b0 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Fri, 16 Apr 2021 18:23:09 +0100 Subject: [PATCH] TEST: Remove use of six/backported mock --- tests/__init__.py | 6 ++---- tests/test_idle.py | 7 +++---- tests/test_image.py | 6 +----- tests/test_image_advanced.py | 2 +- tests/test_memoize.py | 5 ++--- tests/test_platform.py | 19 +++++++++---------- tests/test_run.py | 8 ++------ tests/test_settings.py | 7 +------ tests/test_transform/test_affine.py | 7 +------ tests/test_wrappers/test_wrapperutils.py | 6 ++---- 10 files changed, 24 insertions(+), 49 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 24587392f..58e6d23be 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -20,11 +20,9 @@ import os.path as op import numpy as np import nibabel as nib -from six import StringIO +from io import StringIO - -try: from unittest import mock -except ImportError: import mock +from unittest import mock import fsl.data.image as fslimage from fsl.utils.tempdir import tempdir diff --git a/tests/test_idle.py b/tests/test_idle.py index edf0ecb17..6ceb010bb 100644 --- a/tests/test_idle.py +++ b/tests/test_idle.py @@ -9,11 +9,10 @@ import gc import time import threading import random - -from six.moves import reload_module +import importlib import pytest -import mock +from unittest import mock import fsl.utils.idle as idle from fsl.utils.platform import platform as fslplatform @@ -428,7 +427,7 @@ def test_idle_alwaysQueue4(): with pytest.raises(ImportError): import wx - reload_module(fsl.utils.platform) + importlib.reload(fsl.utils.platform) assert called[0] diff --git a/tests/test_image.py b/tests/test_image.py index 8085cb92c..34a5482ce 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -32,11 +32,7 @@ from fsl.utils.tempdir import tempdir from . import make_random_image from . import make_dummy_file -try: - from unittest import mock -except ImportError: - import mock - +from unittest import mock try: import indexed_gzip as igzip diff --git a/tests/test_image_advanced.py b/tests/test_image_advanced.py index fd7f64359..1f1aed8a2 100644 --- a/tests/test_image_advanced.py +++ b/tests/test_image_advanced.py @@ -7,8 +7,8 @@ import os.path as op import time +from unittest import mock -import mock import pytest import numpy as np diff --git a/tests/test_memoize.py b/tests/test_memoize.py index 386674659..30844884d 100644 --- a/tests/test_memoize.py +++ b/tests/test_memoize.py @@ -6,7 +6,6 @@ # import collections -import six import numpy as np @@ -44,7 +43,7 @@ def test_memoize(): assert timesCalled[0] == 6 # Unicode arg - s = six.u('\u25B2') + s = '\u25B2' assert memoized(s) == s * 5 assert timesCalled[0] == 7 assert memoized(s) == s * 5 @@ -146,7 +145,7 @@ def test_memoizeMD5(): assert timesCalled[0] == 6 # Unicode arg (and return value) - s = six.u('\u25B2') + s = '\u25B2' assert memoized(s) == s * 5 assert timesCalled[0] == 7 assert memoized(s) == s * 5 diff --git a/tests/test_platform.py b/tests/test_platform.py index 9024bec82..a38408175 100644 --- a/tests/test_platform.py +++ b/tests/test_platform.py @@ -6,15 +6,14 @@ # -import os -import gc -import os.path as op -import sys -import shutil -import tempfile -import pytest - -import mock +import os +import gc +import os.path as op +import sys +import shutil +import tempfile +import pytest +from unittest import mock import fsl.utils.platform as fslplatform @@ -216,7 +215,7 @@ def test_detect_ssh(): def test_fslwsl(): """ Note that ``Platform.fsldir`` requires the directory in ``FSLDIR`` to exist and - sets ``FSLDIR`` to ``None`` if it doesn't. So we create a ``Platform`` first + sets ``FSLDIR`` to ``None`` if it doesn't. So we create a ``Platform`` first and then overwrite ``FSLDIR``. This is a bit of a hack but the logic we are testing here is whether ``Platform.fslwsl`` recognizes a WSL ``FSLDIR`` string """ diff --git a/tests/test_run.py b/tests/test_run.py index 7308b849c..287ccd643 100644 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -11,12 +11,8 @@ import os import shutil import textwrap -# python 3 -try: from unittest import mock -# python 2 -except ImportError: import mock +from unittest import mock -import six import pytest import fsl.utils.tempdir as tempdir @@ -273,7 +269,7 @@ def test_runfsl(): def mock_submit(cmd, **kwargs): - if isinstance(cmd, six.string_types): + if isinstance(cmd, str): name = cmd.split()[0] else: name = cmd[0] diff --git a/tests/test_settings.py b/tests/test_settings.py index b17b1b87a..fc0ca9edf 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -12,12 +12,7 @@ import pickle import textwrap import tempfile -# python 3 -try: - import unittest.mock as mock -# python 2 -except: - import mock +import unittest.mock as mock import pytest diff --git a/tests/test_transform/test_affine.py b/tests/test_transform/test_affine.py index f1dceb613..e686080fc 100644 --- a/tests/test_transform/test_affine.py +++ b/tests/test_transform/test_affine.py @@ -6,8 +6,6 @@ # -from __future__ import division - import random import glob import os.path as op @@ -15,8 +13,6 @@ import itertools as it import numpy as np import numpy.linalg as npla -import six - import pytest import fsl.transform.affine as affine @@ -39,8 +35,7 @@ def readlines(filename): # # Pass it [bytes, bytes, ...], and it works # fine. - if six.PY3: - lines = [l.encode('ascii') for l in lines] + lines = [l.encode('ascii') for l in lines] return lines diff --git a/tests/test_wrappers/test_wrapperutils.py b/tests/test_wrappers/test_wrapperutils.py index 9bddb5c6b..f8a9d0dd4 100644 --- a/tests/test_wrappers/test_wrapperutils.py +++ b/tests/test_wrappers/test_wrapperutils.py @@ -11,10 +11,8 @@ import shlex import pathlib import textwrap -try: from unittest import mock -except ImportError: import mock +from unittest import mock -import six import pytest import numpy as np @@ -317,7 +315,7 @@ def test_fileOrThing_sequence(): @wutils.fileOrArray('arrs', 'out') def func(arrs, out): - if isinstance(arrs, six.string_types): + if isinstance(arrs, str): arrs = [arrs] arrs = [np.loadtxt(a) for a in arrs] -- GitLab