From 9d64c01b57352e44d11a9fee113d39727169ade5 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Thu, 1 Feb 2024 17:30:07 +0100 Subject: [PATCH 1/5] Remove Python SIX usage We stopped caring about Python 2 support long time ago and with libblockdev 3.0 which is Python 3 only it wouldn't even be possible to support Python 2 so we should finally remove it. --- blivet/actionlist.py | 4 +- blivet/blivet.py | 4 +- blivet/deviceaction.py | 5 +-- blivet/devicefactory.py | 8 ++-- blivet/devicelibs/raid.py | 8 +--- blivet/devices/cache.py | 10 ++--- blivet/devices/container.py | 5 +-- blivet/devices/device.py | 4 +- blivet/devices/lvm.py | 9 ++-- blivet/devices/md.py | 5 +-- blivet/devices/raid.py | 5 +-- blivet/devicetree.py | 26 ++++++------ blivet/events/handler.py | 5 +-- blivet/events/manager.py | 15 ++----- blivet/formats/__init__.py | 4 +- blivet/i18n.py | 14 +------ blivet/populator/helpers/__init__.py | 5 +-- blivet/populator/helpers/disklabel.py | 29 +++++++------ blivet/populator/helpers/partition.py | 5 +-- blivet/populator/populator.py | 4 +- blivet/tasks/availability.py | 5 +-- blivet/tasks/dfresize.py | 5 +-- blivet/tasks/fsck.py | 5 +-- blivet/tasks/fsinfo.py | 5 +-- blivet/tasks/fslabeling.py | 5 +-- blivet/tasks/fsminsize.py | 5 +-- blivet/tasks/fsmkfs.py | 11 ++--- blivet/tasks/fsreadlabel.py | 5 +-- blivet/tasks/fssize.py | 4 +- blivet/tasks/fssync.py | 4 +- blivet/tasks/fstask.py | 4 +- blivet/tasks/fsuuid.py | 5 +-- blivet/tasks/task.py | 8 +--- blivet/threads.py | 12 ++---- blivet/util.py | 9 ++-- misc/install-test-dependencies.yml | 2 - python-blivet.spec | 1 - scripts/makebumpver | 14 ++----- scripts/makeupdates | 5 +-- setup.py | 2 +- tests/run_tests.py | 4 +- .../devices_test/partition_test.py | 12 ++---- .../storage_tests/formats_test/fslabeling.py | 12 +++--- tests/storage_tests/formats_test/fstesting.py | 4 +- tests/storage_tests/formats_test/fsuuid.py | 8 ++-- tests/storage_tests/partitioning_test.py | 7 ++-- .../unsupported_disklabel_test.py | 17 ++------ tests/unit_tests/devicefactory_test.py | 9 ++-- tests/unit_tests/devicelibs_test/disk_test.py | 5 +-- tests/unit_tests/devicelibs_test/raid_test.py | 9 ++-- .../devices_test/device_dependencies_test.py | 7 ++-- .../devices_test/device_methods_test.py | 13 +++--- .../devices_test/device_names_test.py | 3 +- .../devices_test/device_properties_test.py | 39 +++++++++-------- tests/unit_tests/devices_test/lvm_test.py | 42 +++++++++---------- tests/unit_tests/devices_test/md_test.py | 9 ++-- tests/unit_tests/devices_test/stratis_test.py | 3 +- tests/unit_tests/devicetree_test.py | 11 +++-- .../unit_tests/formats_tests/methods_test.py | 31 +++++++------- tests/unit_tests/formats_tests/swap_test.py | 3 +- tests/unit_tests/populator_test.py | 3 +- tests/unit_tests/size_test.py | 5 +-- tests/unit_tests/util_test.py | 8 +--- 63 files changed, 197 insertions(+), 357 deletions(-) diff --git a/blivet/actionlist.py b/blivet/actionlist.py index 9b3f727e9..9e85337db 100644 --- a/blivet/actionlist.py +++ b/blivet/actionlist.py @@ -22,7 +22,6 @@ import copy from functools import wraps -from six import add_metaclass from .callbacks import callbacks as _callbacks from .deviceaction import ActionCreateDevice @@ -53,8 +52,7 @@ def wrapped_func(obj, *args, **kwargs): return run_func_with_flag_attr_set -@add_metaclass(SynchronizedMeta) -class ActionList(object): +class ActionList(object, metaclass=SynchronizedMeta): _unsynchronized_methods = ['process'] def __init__(self, addfunc=None, removefunc=None): diff --git a/blivet/blivet.py b/blivet/blivet.py index f290a0695..e7e50212a 100644 --- a/blivet/blivet.py +++ b/blivet/blivet.py @@ -25,7 +25,6 @@ import contextlib import time import functools -import six from .storage_log import log_method_call, log_exception_info from .devices import BTRFSSubVolumeDevice, BTRFSVolumeDevice @@ -59,8 +58,7 @@ FSTAB_PATH = "/etc/fstab" -@six.add_metaclass(SynchronizedMeta) -class Blivet(object): +class Blivet(object, metaclass=SynchronizedMeta): """ Top-level class for managing storage configuration. """ diff --git a/blivet/deviceaction.py b/blivet/deviceaction.py index 307ae735d..db9fd483a 100644 --- a/blivet/deviceaction.py +++ b/blivet/deviceaction.py @@ -22,8 +22,6 @@ import copy -from six import add_metaclass - from . import util from . import udev from .errors import DependencyError, PartitioningError @@ -108,8 +106,7 @@ def resize_type_from_string(type_string): return k -@add_metaclass(SynchronizedMeta) -class DeviceAction(util.ObjectID): +class DeviceAction(util.ObjectID, metaclass=SynchronizedMeta): """ An action that will be carried out in the future on a Device. diff --git a/blivet/devicefactory.py b/blivet/devicefactory.py index b995cc22c..59c72fbe3 100644 --- a/blivet/devicefactory.py +++ b/blivet/devicefactory.py @@ -20,8 +20,6 @@ # Red Hat Author(s): David Lehman # -from six import raise_from - from .storage_log import log_method_call from .errors import DeviceFactoryError, StorageError from .devices import BTRFSDevice, DiskDevice @@ -746,7 +744,7 @@ def _create_device(self): except (StorageError, blockdev.BlockDevError) as e: log.error("device post-create method failed: %s", e) self.storage.destroy_device(device) - raise_from(StorageError(e), e) + raise StorageError(e) from e else: if not device.size: self.storage.destroy_device(device) @@ -941,7 +939,7 @@ def configure(self): self._revert_devicetree() if not isinstance(e, (StorageError, OverflowError)): - raise_from(DeviceFactoryError(e), e) + raise DeviceFactoryError(e) from e raise @@ -2189,7 +2187,7 @@ def _create_device(self): except (StorageError, blockdev.BlockDevError) as e: log.error("device post-create method failed: %s", e) self.storage.destroy_device(device) - raise_from(StorageError(e), e) + raise StorageError(e) from e else: if not device.size: self.storage.destroy_device(device) diff --git a/blivet/devicelibs/raid.py b/blivet/devicelibs/raid.py index a9e241c7a..7a891c02a 100644 --- a/blivet/devicelibs/raid.py +++ b/blivet/devicelibs/raid.py @@ -23,8 +23,6 @@ import abc -from six import add_metaclass - from ..errors import RaidError from ..size import Size @@ -38,8 +36,7 @@ def div_up(a, b): return (a + (b - 1)) // b -@add_metaclass(abc.ABCMeta) -class RAIDLevel(object): +class RAIDLevel(object, metaclass=abc.ABCMeta): """An abstract class which is the parent of all classes which represent a RAID level. @@ -77,8 +74,7 @@ def __deepcopy__(self, memo): return self -@add_metaclass(abc.ABCMeta) -class RAIDn(RAIDLevel): +class RAIDn(RAIDLevel, metaclass=abc.ABCMeta): """An abstract class which is the parent of classes which represent a numeric RAID level. A better word would be classification, since 'level' diff --git a/blivet/devices/cache.py b/blivet/devices/cache.py index 27771395d..20995d3bc 100644 --- a/blivet/devices/cache.py +++ b/blivet/devices/cache.py @@ -24,12 +24,10 @@ """ -from six import add_metaclass import abc -@add_metaclass(abc.ABCMeta) -class Cache(object): +class Cache(object, metaclass=abc.ABCMeta): """Abstract base class for cache objects providing the cache-related functionality on cached devices. Instances of this class are not expected to @@ -74,8 +72,7 @@ def detach(self): """ -@add_metaclass(abc.ABCMeta) -class CacheStats(object): +class CacheStats(object, metaclass=abc.ABCMeta): """Abstract base class for common statistics of caches (cached devices). Inheriting classes are expected to add (cache-)type-specific @@ -109,8 +106,7 @@ def misses(self): """number of misses""" -@add_metaclass(abc.ABCMeta) -class CacheRequest(object): +class CacheRequest(object, metaclass=abc.ABCMeta): """Abstract base class for cache requests specifying cache parameters for a cached device diff --git a/blivet/devices/container.py b/blivet/devices/container.py index e96e428d7..30553da2d 100644 --- a/blivet/devices/container.py +++ b/blivet/devices/container.py @@ -21,8 +21,6 @@ import abc -from six import add_metaclass - from .. import errors from ..storage_log import log_method_call from ..formats import get_device_format_class @@ -34,8 +32,7 @@ from .storage import StorageDevice -@add_metaclass(SynchronizedABCMeta) -class ContainerDevice(StorageDevice): +class ContainerDevice(StorageDevice, metaclass=SynchronizedABCMeta): """ A device that aggregates a set of member devices. diff --git a/blivet/devices/device.py b/blivet/devices/device.py index d82c23b22..cd7f515ee 100644 --- a/blivet/devices/device.py +++ b/blivet/devices/device.py @@ -21,7 +21,6 @@ # import pprint -from six import add_metaclass from .. import util from ..storage_log import log_method_call @@ -33,8 +32,7 @@ from .lib import ParentList -@add_metaclass(SynchronizedMeta) -class Device(util.ObjectID): +class Device(util.ObjectID, metaclass=SynchronizedMeta): """ A generic device. diff --git a/blivet/devices/lvm.py b/blivet/devices/lvm.py index bb3cac0df..b39f59897 100644 --- a/blivet/devices/lvm.py +++ b/blivet/devices/lvm.py @@ -28,7 +28,6 @@ from collections import namedtuple, defaultdict from functools import wraps from enum import Enum -import six import gi gi.require_version("BlockDev", "3.0") @@ -1825,8 +1824,8 @@ def _create(self): extra["profile"] = profile_name if self.chunk_size: extra["chunksize"] = str(int(self.chunk_size)) - data_lv = six.next(lv for lv in self._internal_lvs if lv.int_lv_type == LVMInternalLVtype.data) - meta_lv = six.next(lv for lv in self._internal_lvs if lv.int_lv_type == LVMInternalLVtype.meta) + data_lv = next(lv for lv in self._internal_lvs if lv.int_lv_type == LVMInternalLVtype.data) + meta_lv = next(lv for lv in self._internal_lvs if lv.int_lv_type == LVMInternalLVtype.meta) try: blockdev.lvm.thpool_convert(self.vg.name, data_lv.lvname, meta_lv.lvname, self.lvname, **extra) except blockdev.LVMError as err: @@ -2346,8 +2345,8 @@ def _create(self): if self.mode: # we need the string here, it will be passed directly to he lvm command extra["cachemode"] = self._cache_mode - data_lv = six.next(lv for lv in self._internal_lvs if lv.int_lv_type == LVMInternalLVtype.data) - meta_lv = six.next(lv for lv in self._internal_lvs if lv.int_lv_type == LVMInternalLVtype.meta) + data_lv = next(lv for lv in self._internal_lvs if lv.int_lv_type == LVMInternalLVtype.data) + meta_lv = next(lv for lv in self._internal_lvs if lv.int_lv_type == LVMInternalLVtype.meta) try: blockdev.lvm.cache_pool_convert(self.vg.name, data_lv.lvname, meta_lv.lvname, self.lvname, **extra) except blockdev.LVMError as err: diff --git a/blivet/devices/md.py b/blivet/devices/md.py index 9efca08b5..61865fc3a 100644 --- a/blivet/devices/md.py +++ b/blivet/devices/md.py @@ -21,10 +21,9 @@ import math import os -import six import time -from six.moves import reduce +from functools import reduce import gi gi.require_version("BlockDev", "3.0") @@ -355,7 +354,7 @@ def _get_member_devices(self): return self._member_devices def _set_member_devices(self, number): - if not isinstance(number, six.integer_types): + if not isinstance(number, int): raise ValueError("member_devices must be an integer") if not self.exists and number > self.total_devices: diff --git a/blivet/devices/raid.py b/blivet/devices/raid.py index 13e32616d..8e8b1bd1b 100644 --- a/blivet/devices/raid.py +++ b/blivet/devices/raid.py @@ -21,8 +21,6 @@ import abc -from six import add_metaclass - from .. import errors from ..i18n import _, P_ from ..threads import SynchronizedABCMeta @@ -30,8 +28,7 @@ from .storage import StorageDevice -@add_metaclass(SynchronizedABCMeta) -class RaidDevice(StorageDevice): +class RaidDevice(StorageDevice, metaclass=SynchronizedABCMeta): """ Metaclass for devices that support RAID in some form. """ members = abc.abstractproperty(lambda s: [], diff --git a/blivet/devicetree.py b/blivet/devicetree.py index 6f0e1eee7..d85f4f9ee 100644 --- a/blivet/devicetree.py +++ b/blivet/devicetree.py @@ -23,7 +23,6 @@ import os import pprint import re -import six import gi gi.require_version("BlockDev", "3.0") @@ -52,8 +51,7 @@ _LVM_DEVICE_CLASSES = (LVMLogicalVolumeDevice, LVMVolumeGroupDevice) -@six.add_metaclass(SynchronizedMeta) -class DeviceTreeBase(object): +class DeviceTreeBase(object, metaclass=SynchronizedMeta): """ A quasi-tree that represents the devices in the system. The tree contains a list of :class:`~.devices.StorageDevice` instances, @@ -500,7 +498,7 @@ def get_device_by_sysfs_path(self, path, incomplete=False, hidden=False): result = None if path: devices = self._filter_devices(incomplete=incomplete, hidden=hidden) - result = six.next((d for d in devices if d.sysfs_path == path), None) + result = next((d for d in devices if d.sysfs_path == path), None) log_method_return(self, result) return result @@ -517,7 +515,7 @@ def get_device_by_uuid(self, uuid, incomplete=False, hidden=False): result = None if uuid: devices = self._filter_devices(incomplete=incomplete, hidden=hidden) - result = six.next((d for d in devices if d.uuid == uuid or d.format.uuid == uuid), None) + result = next((d for d in devices if d.uuid == uuid or d.format.uuid == uuid), None) log_method_return(self, result) return result @@ -534,7 +532,7 @@ def get_device_by_label(self, label, incomplete=False, hidden=False): result = None if label: devices = self._filter_devices(incomplete=incomplete, hidden=hidden) - result = six.next((d for d in devices if getattr(d.format, "label", None) == label), None) + result = next((d for d in devices if getattr(d.format, "label", None) == label), None) log_method_return(self, result) return result @@ -551,9 +549,9 @@ def get_device_by_name(self, name, incomplete=False, hidden=False): result = None if name: devices = self._filter_devices(incomplete=incomplete, hidden=hidden) - result = six.next((d for d in devices if d.name == name or - (isinstance(d, _LVM_DEVICE_CLASSES) and d.name == name.replace("--", "-"))), - None) + result = next((d for d in devices if d.name == name or + (isinstance(d, _LVM_DEVICE_CLASSES) and d.name == name.replace("--", "-"))), + None) log_method_return(self, result) return result @@ -577,9 +575,9 @@ def get_device_by_path(self, path, incomplete=False, hidden=False): # The usual order of the devices list is one where leaves are at # the end. So that the search can prefer leaves to interior nodes # the list that is searched is the reverse of the devices list. - result = six.next((d for d in reversed(list(devices)) if d.path == path or - (isinstance(d, _LVM_DEVICE_CLASSES) and d.path == path.replace("--", "-"))), - None) + result = next((d for d in reversed(list(devices)) if d.path == path or + (isinstance(d, _LVM_DEVICE_CLASSES) and d.path == path.replace("--", "-"))), + None) log_method_return(self, result) return result @@ -595,7 +593,7 @@ def get_device_by_id(self, id_num, incomplete=False, hidden=False): """ log_method_call(self, id_num=id_num, incomplete=incomplete, hidden=hidden) devices = self._filter_devices(incomplete=incomplete, hidden=hidden) - result = six.next((d for d in devices if d.id == id_num), None) + result = next((d for d in devices if d.id == id_num), None) log_method_return(self, result) return result @@ -610,7 +608,7 @@ def get_device_by_device_id(self, device_id, incomplete=False, hidden=False): """ log_method_call(self, device_id=device_id, incomplete=incomplete, hidden=hidden) devices = self._filter_devices(incomplete=incomplete, hidden=hidden) - result = six.next((d for d in devices if d.device_id == device_id), None) + result = next((d for d in devices if d.device_id == device_id), None) log_method_return(self, result) return result diff --git a/blivet/events/handler.py b/blivet/events/handler.py index f839e8c3a..0066846fb 100644 --- a/blivet/events/handler.py +++ b/blivet/events/handler.py @@ -20,8 +20,6 @@ # Red Hat Author(s): David Lehman # -from six import add_metaclass - from ..callbacks import callbacks from ..errors import DeviceError, EventHandlingError from ..devices import DM_MAJORS, MD_MAJORS @@ -37,8 +35,7 @@ event_log = logging.getLogger("blivet.event") -@add_metaclass(SynchronizedMeta) -class EventHandlerMixin(object): +class EventHandlerMixin(object, metaclass=SynchronizedMeta): def __init__(self): event_manager.handler_cb = self.handle_event diff --git a/blivet/events/manager.py b/blivet/events/manager.py index da1f43c91..b47ceee82 100644 --- a/blivet/events/manager.py +++ b/blivet/events/manager.py @@ -24,7 +24,6 @@ import inspect from threading import current_thread, RLock, Thread import pyudev -import six import sys import time import traceback @@ -49,14 +48,7 @@ def validate_cb(cb, kwargs=None, arg_count=None): kwargs = kwargs or [] arg_count = arg_count or 0 - if six.PY2: - argspec = inspect.getargspec(cb) # pylint: disable=deprecated-method,no-member - if argspec.varargs or argspec.keywords: - return True - params = argspec.args - else: - params = list(inspect.signature(cb).parameters.keys()) - + params = list(inspect.signature(cb).parameters.keys()) if len(params) < arg_count: return False @@ -126,8 +118,7 @@ def match(self, event): # # EventManager # -@six.add_metaclass(abc.ABCMeta) -class EventManager(object): +class EventManager(object, metaclass=abc.ABCMeta): def __init__(self, handler_cb=None, notify_cb=None, error_cb=None): self._handler_cb = None """ event handler (must accept 'event', 'notify_cb' kwargs """ @@ -215,7 +206,7 @@ def disable(self): def _mask_event(self, event): """ Return True if this event should be ignored """ with self._lock: - return six.next((m for m in self._mask_list if m.match(event)), None) is not None + return next((m for m in self._mask_list if m.match(event)), None) is not None def add_mask(self, device=None, action=None, partitions=False): """ Add an event mask and return the new :class:`EventMask`. diff --git a/blivet/formats/__init__.py b/blivet/formats/__init__.py index 306300de4..029399160 100644 --- a/blivet/formats/__init__.py +++ b/blivet/formats/__init__.py @@ -23,7 +23,6 @@ import os import importlib -from six import add_metaclass import gi gi.require_version("BlockDev", "3.0") @@ -135,8 +134,7 @@ def get_device_format_class(fmt_type): return fmt -@add_metaclass(SynchronizedMeta) -class DeviceFormat(ObjectID): +class DeviceFormat(ObjectID, metaclass=SynchronizedMeta): """ Generic device format. diff --git a/blivet/i18n.py b/blivet/i18n.py index 8e90bd5e9..4b0d18cab 100644 --- a/blivet/i18n.py +++ b/blivet/i18n.py @@ -23,7 +23,6 @@ import gettext import locale -import six # Create and cache a translations object for the current LC_MESSAGES value _cached_translations = {} @@ -42,14 +41,5 @@ def _get_translations(): N_ = lambda x: x - -# In Python 2, return the translated strings as unicode objects. -# yes, pylint, the lambdas are necessary, because I want _get_translations() -# evaluated on every call. -# pylint: disable=unnecessary-lambda,redundant-u-string-prefix -if six.PY2: - _ = lambda x: _get_translations().ugettext(x) if x != "" else u"" - P_ = lambda x, y, z: _get_translations().ungettext(x, y, z) -else: - _ = lambda x: _get_translations().gettext(x) if x != "" else "" - P_ = lambda x, y, z: _get_translations().ngettext(x, y, z) +_ = lambda x: _get_translations().gettext(x) if x != "" else "" +P_ = lambda x, y, z: _get_translations().ngettext(x, y, z) diff --git a/blivet/populator/helpers/__init__.py b/blivet/populator/helpers/__init__.py index 4443fc007..583675e6d 100644 --- a/blivet/populator/helpers/__init__.py +++ b/blivet/populator/helpers/__init__.py @@ -1,5 +1,4 @@ import inspect as _inspect -import six as _six from .devicepopulator import DevicePopulator from .formatpopulator import FormatPopulator @@ -51,7 +50,7 @@ def get_device_helper(data): The helper lists are sorted according to priorities defined within each class. This function returns the first matching class. """ - return _six.next((h for h in _device_helpers if h.match(data)), None) + return next((h for h in _device_helpers if h.match(data)), None) def get_format_helper(data, device): @@ -60,4 +59,4 @@ def get_format_helper(data, device): The helper lists are sorted according to priorities defined within each class. This function returns the first matching class. """ - return _six.next((h for h in _format_helpers if h.match(data, device=device)), None) + return next((h for h in _format_helpers if h.match(data, device=device)), None) diff --git a/blivet/populator/helpers/disklabel.py b/blivet/populator/helpers/disklabel.py index 842cd3081..b8d708e8e 100644 --- a/blivet/populator/helpers/disklabel.py +++ b/blivet/populator/helpers/disklabel.py @@ -21,7 +21,6 @@ # import os -import six from ... import formats from ... import udev @@ -111,22 +110,22 @@ def update(self): start_sector = partition.parted_partition.geometry.start udev_device = None if self.device.format.label_type == "gpt": - udev_device = six.next((ud for ud in udev_devices - if udev.device_get_partition_uuid(ud) == partition.uuid), - None) + udev_device = next((ud for ud in udev_devices + if udev.device_get_partition_uuid(ud) == partition.uuid), + None) else: - udev_device = six.next((ud for ud in udev_devices - if udev.device_get_partition_disk(ud) == self.device.name and - int(ud.get("ID_PART_ENTRY_OFFSET")) == start_sector), - None) + udev_device = next((ud for ud in udev_devices + if udev.device_get_partition_disk(ud) == self.device.name and + int(ud.get("ID_PART_ENTRY_OFFSET")) == start_sector), + None) if udev_device is None: self._devicetree.recursive_remove(partition, modparent=False, actions=False) continue - parted_partition = six.next((pp for pp in parted_partitions - if os.path.basename(pp.path) == udev.device_get_name(udev_device)), - None) + parted_partition = next((pp for pp in parted_partitions + if os.path.basename(pp.path) == udev.device_get_name(udev_device)), + None) log.debug("got parted_partition %s for partition %s", parted_partition.path.split("/")[-1], partition.name) partition.parted_partition = parted_partition @@ -135,10 +134,10 @@ def update(self): for parted_partition in self.device.format.partitions: partition_name = os.path.basename(parted_partition.path) start_sector = parted_partition.geometry.start - udev_device = six.next((ud for ud in udev_devices - if udev.device_get_name(ud) == partition_name and - int(ud.get("ID_PART_ENTRY_OFFSET")) == start_sector), - None) + udev_device = next((ud for ud in udev_devices + if udev.device_get_name(ud) == partition_name and + int(ud.get("ID_PART_ENTRY_OFFSET")) == start_sector), + None) if udev_device is None: continue diff --git a/blivet/populator/helpers/partition.py b/blivet/populator/helpers/partition.py index 2548f0e94..fd9cababb 100644 --- a/blivet/populator/helpers/partition.py +++ b/blivet/populator/helpers/partition.py @@ -21,7 +21,6 @@ # import copy -import six from ... import udev from ...devices import PartitionDevice @@ -56,8 +55,8 @@ def run(self): disk = self._devicetree.get_device_by_device_id(disk_name) if disk is None: # create a device instance for the disk - disk_info = six.next((i for i in udev.get_devices() - if udev.device_get_name(i) == disk_name), None) + disk_info = next((i for i in udev.get_devices() + if udev.device_get_name(i) == disk_name), None) if disk_info is not None: self._devicetree.handle_device(disk_info) disk = self._devicetree.get_device_by_device_id(disk_name) diff --git a/blivet/populator/populator.py b/blivet/populator/populator.py index c842ef7c9..2ddea6618 100644 --- a/blivet/populator/populator.py +++ b/blivet/populator/populator.py @@ -24,7 +24,6 @@ import pprint import copy import parted -from six import add_metaclass import gi gi.require_version("BlockDev", "3.0") @@ -70,8 +69,7 @@ def parted_exn_handler(exn_type, exn_options, exn_msg): return ret -@add_metaclass(SynchronizedMeta) -class PopulatorMixin(object): +class PopulatorMixin(object, metaclass=SynchronizedMeta): def __init__(self, disk_images=None): """ :keyword disk_images: dictoinary of disk images diff --git a/blivet/tasks/availability.py b/blivet/tasks/availability.py index 626b2633c..4d82ef533 100644 --- a/blivet/tasks/availability.py +++ b/blivet/tasks/availability.py @@ -22,8 +22,6 @@ import abc import shutil -from six import add_metaclass - from .. import safe_dbus from ..devicelibs.stratis import STRATIS_SERVICE, STRATIS_PATH @@ -94,8 +92,7 @@ def available(self): return self.availability_errors == [] -@add_metaclass(abc.ABCMeta) -class Method(object): +class Method(object, metaclass=abc.ABCMeta): """ Method for determining if external resource is available.""" diff --git a/blivet/tasks/dfresize.py b/blivet/tasks/dfresize.py index 2390a8da0..6b4ac1fad 100644 --- a/blivet/tasks/dfresize.py +++ b/blivet/tasks/dfresize.py @@ -21,13 +21,10 @@ import abc -from six import add_metaclass - from . import task -@add_metaclass(abc.ABCMeta) -class DFResizeTask(task.Task): +class DFResizeTask(task.Task, metaclass=abc.ABCMeta): """ The abstract properties that any resize task must have. """ unit = abc.abstractproperty(doc="Resize unit.") diff --git a/blivet/tasks/fsck.py b/blivet/tasks/fsck.py index 3b5036396..8a52f63d5 100644 --- a/blivet/tasks/fsck.py +++ b/blivet/tasks/fsck.py @@ -21,8 +21,6 @@ import abc -from six import add_metaclass - from ..errors import FSError from .. import util @@ -33,8 +31,7 @@ _UNKNOWN_RC_MSG = "Unknown return code: %d" -@add_metaclass(abc.ABCMeta) -class FSCK(task.BasicApplication, fstask.FSTask): +class FSCK(task.BasicApplication, fstask.FSTask, metaclass=abc.ABCMeta): """An abstract class that represents actions associated with checking consistency of a filesystem. diff --git a/blivet/tasks/fsinfo.py b/blivet/tasks/fsinfo.py index ea092b0e3..a1387a18f 100644 --- a/blivet/tasks/fsinfo.py +++ b/blivet/tasks/fsinfo.py @@ -21,8 +21,6 @@ import abc -from six import add_metaclass - from ..errors import FSError from . import availability @@ -34,8 +32,7 @@ from gi.repository import BlockDev -@add_metaclass(abc.ABCMeta) -class FSInfo(task.BasicApplication, fstask.FSTask): +class FSInfo(task.BasicApplication, fstask.FSTask, metaclass=abc.ABCMeta): """ An abstract class that represents an information gathering app. """ diff --git a/blivet/tasks/fslabeling.py b/blivet/tasks/fslabeling.py index 11b2280bb..d9427e522 100644 --- a/blivet/tasks/fslabeling.py +++ b/blivet/tasks/fslabeling.py @@ -21,15 +21,12 @@ import abc -from six import add_metaclass - import gi gi.require_version("BlockDev", "3.0") from gi.repository import BlockDev -@add_metaclass(abc.ABCMeta) -class FSLabeling(object): +class FSLabeling(object, metaclass=abc.ABCMeta): """An abstract class that represents filesystem labeling actions. """ diff --git a/blivet/tasks/fsminsize.py b/blivet/tasks/fsminsize.py index eac2fe567..bf18c765d 100644 --- a/blivet/tasks/fsminsize.py +++ b/blivet/tasks/fsminsize.py @@ -21,8 +21,6 @@ import abc -from six import add_metaclass - from ..errors import FSError from .. import util from ..size import Size @@ -32,8 +30,7 @@ from . import task -@add_metaclass(abc.ABCMeta) -class FSMinSize(task.BasicApplication, fstask.FSTask): +class FSMinSize(task.BasicApplication, fstask.FSTask, metaclass=abc.ABCMeta): """ An abstract class that represents min size information extraction. """ diff --git a/blivet/tasks/fsmkfs.py b/blivet/tasks/fsmkfs.py index e9daa9ea3..717cee3a3 100644 --- a/blivet/tasks/fsmkfs.py +++ b/blivet/tasks/fsmkfs.py @@ -22,8 +22,6 @@ import abc import shlex -from six import add_metaclass - from ..errors import FSError, FSWriteLabelError, FSWriteUUIDError from .. import util @@ -36,16 +34,14 @@ from gi.repository import BlockDev -@add_metaclass(abc.ABCMeta) -class FSMkfsTask(fstask.FSTask): +class FSMkfsTask(fstask.FSTask, metaclass=abc.ABCMeta): can_label = abc.abstractproperty(doc="whether this task labels") can_set_uuid = abc.abstractproperty(doc="whether this task can set UUID") can_nodiscard = abc.abstractproperty(doc="whether this task can set nodiscard option") -@add_metaclass(abc.ABCMeta) -class FSMkfs(task.BasicApplication, FSMkfsTask): +class FSMkfs(task.BasicApplication, FSMkfsTask, metaclass=abc.ABCMeta): """An abstract class that represents filesystem creation actions. """ description = "mkfs" @@ -237,8 +233,7 @@ def args(self): return [] -@add_metaclass(abc.ABCMeta) -class FSBlockDevMkfs(task.BasicApplication, FSMkfsTask): +class FSBlockDevMkfs(task.BasicApplication, FSMkfsTask, metaclass=abc.ABCMeta): """An abstract class that represents filesystem creation actions. """ description = "mkfs" diff --git a/blivet/tasks/fsreadlabel.py b/blivet/tasks/fsreadlabel.py index 5c6003a36..f95b6befa 100644 --- a/blivet/tasks/fsreadlabel.py +++ b/blivet/tasks/fsreadlabel.py @@ -21,8 +21,6 @@ import abc -from six import add_metaclass - from ..errors import FSReadLabelError from . import availability @@ -30,8 +28,7 @@ from . import task -@add_metaclass(abc.ABCMeta) -class FSReadLabel(task.BasicApplication, fstask.FSTask): +class FSReadLabel(task.BasicApplication, fstask.FSTask, metaclass=abc.ABCMeta): """ An abstract class that represents reading a filesystem's label. """ description = "read filesystem label" diff --git a/blivet/tasks/fssize.py b/blivet/tasks/fssize.py index 53152b81b..a23e6d9cf 100644 --- a/blivet/tasks/fssize.py +++ b/blivet/tasks/fssize.py @@ -21,7 +21,6 @@ import abc import os -import six from ..errors import FSError from ..size import Size @@ -29,8 +28,7 @@ from . import fstask -@six.add_metaclass(abc.ABCMeta) -class FSSize(fstask.FSTask): +class FSSize(fstask.FSTask, metaclass=abc.ABCMeta): """ An abstract class that represents size information extraction. """ description = "current filesystem size" diff --git a/blivet/tasks/fssync.py b/blivet/tasks/fssync.py index 85cac3b03..07d64c039 100644 --- a/blivet/tasks/fssync.py +++ b/blivet/tasks/fssync.py @@ -21,7 +21,6 @@ import abc -from six import add_metaclass from ..errors import FSError @@ -34,8 +33,7 @@ from gi.repository import BlockDev -@add_metaclass(abc.ABCMeta) -class FSSync(task.BasicApplication, fstask.FSTask): +class FSSync(task.BasicApplication, fstask.FSTask, metaclass=abc.ABCMeta): """ An abstract class that represents syncing a filesystem. """ diff --git a/blivet/tasks/fstask.py b/blivet/tasks/fstask.py index 9f0d874ac..052f4c466 100644 --- a/blivet/tasks/fstask.py +++ b/blivet/tasks/fstask.py @@ -21,13 +21,11 @@ import abc -from six import add_metaclass from . import task -@add_metaclass(abc.ABCMeta) -class FSTask(task.Task): +class FSTask(task.Task, metaclass=abc.ABCMeta): """ An abstract class that encapsulates the fact that all FSTasks have a single master object: the filesystem that they belong to. diff --git a/blivet/tasks/fsuuid.py b/blivet/tasks/fsuuid.py index 849d7d975..3aa84b3b2 100644 --- a/blivet/tasks/fsuuid.py +++ b/blivet/tasks/fsuuid.py @@ -1,14 +1,11 @@ import abc -from six import add_metaclass - import gi gi.require_version("BlockDev", "3.0") from gi.repository import BlockDev -@add_metaclass(abc.ABCMeta) -class FSUUID(object): +class FSUUID(object, metaclass=abc.ABCMeta): """An abstract class that represents filesystem actions for setting the UUID. diff --git a/blivet/tasks/task.py b/blivet/tasks/task.py index 9ac430129..36d8f950f 100644 --- a/blivet/tasks/task.py +++ b/blivet/tasks/task.py @@ -21,11 +21,8 @@ import abc -from six import add_metaclass - -@add_metaclass(abc.ABCMeta) -class Task(object): +class Task(object, metaclass=abc.ABCMeta): """ An abstract class that represents some task. """ @@ -82,8 +79,7 @@ def do_task(self, *args, **kwargs): raise NotImplementedError() -@add_metaclass(abc.ABCMeta) -class BasicApplication(Task): +class BasicApplication(Task, metaclass=abc.ABCMeta): """ A task representing an application. """ diff --git a/blivet/threads.py b/blivet/threads.py index 5e2dff3f2..3439f3ff6 100644 --- a/blivet/threads.py +++ b/blivet/threads.py @@ -20,11 +20,10 @@ # Red Hat Author(s): David Lehman # +import functools import threading from types import FunctionType from abc import ABCMeta -from six import raise_from, wraps, PY3 -import functools from .errors import ThreadError from .flags import flags @@ -33,22 +32,19 @@ def _is_main_thread(): - if PY3: - return threading.current_thread() == threading.main_thread() - else: - return threading.currentThread().name == "MainThread" # pylint: disable=deprecated-method + return threading.current_thread() == threading.main_thread() def exclusive(m): """ Run a callable while holding the global lock. """ - @wraps(m, set(functools.WRAPPER_ASSIGNMENTS) & set(dir(m))) + @functools.wraps(m, set(functools.WRAPPER_ASSIGNMENTS) & set(dir(m))) def run_with_lock(*args, **kwargs): with blivet_lock: if _is_main_thread(): exn_info = get_thread_exception() if exn_info[1]: clear_thread_exception() - raise_from(ThreadError("raising queued exception"), exn_info[1]) + raise ThreadError("raising queued exception") from exn_info[1] return m(*args, **kwargs) diff --git a/blivet/util.py b/blivet/util.py index f8a8f885c..9dfe684d7 100644 --- a/blivet/util.py +++ b/blivet/util.py @@ -25,8 +25,6 @@ from gi.repository import BlockDev as blockdev -import six - import logging log = logging.getLogger("blivet") program_log = logging.getLogger("program") @@ -202,7 +200,7 @@ def chroot(): preexec_fn=chroot, cwd=root, env=env) out, err = proc.communicate() - if not binary_output and six.PY3: + if not binary_output: out = out.decode("utf-8") if out: if not stderr_to_stdout: @@ -593,7 +591,7 @@ def numeric_type(num): if num is None: num = 0 - elif not isinstance(num, (six.integer_types, float, Size, Decimal)): + elif not isinstance(num, (int, float, Size, Decimal)): raise ValueError("value (%s) must be either a number or None" % num) return num @@ -1123,8 +1121,7 @@ class EvalMode(Enum): # TODO: no_sooner_than, if_changed,... -@six.add_metaclass(abc.ABCMeta) -class DependencyGuard(object): +class DependencyGuard(object, metaclass=abc.ABCMeta): error_msg = abc.abstractproperty(doc="Error message to report when a dependency is missing") diff --git a/misc/install-test-dependencies.yml b/misc/install-test-dependencies.yml index ec9982e4b..a25e55d1c 100644 --- a/misc/install-test-dependencies.yml +++ b/misc/install-test-dependencies.yml @@ -44,7 +44,6 @@ - python3-coverage - python3-pocketlint - python3-pycodestyle - - python3-six - python3-pyudev - python3-pyparted - libselinux-python3 @@ -96,7 +95,6 @@ - xfsprogs - python3-coverage - python3-pycodestyle - - python3-six - python3-pyudev - python3-pyparted - libselinux-python3 diff --git a/python-blivet.spec b/python-blivet.spec index 2486e3226..dfa1c2692 100644 --- a/python-blivet.spec +++ b/python-blivet.spec @@ -51,7 +51,6 @@ BuildRequires: python3-devel BuildRequires: python3-setuptools Requires: python3 -Requires: python3-six Requires: python3-pyudev >= %{pyudevver} Requires: parted >= %{partedver} Requires: python3-pyparted >= %{pypartedver} diff --git a/scripts/makebumpver b/scripts/makebumpver index 0871ea887..73eb97c5a 100755 --- a/scripts/makebumpver +++ b/scripts/makebumpver @@ -24,7 +24,6 @@ import argparse import datetime import os import re -import six import subprocess import sys import textwrap @@ -47,10 +46,7 @@ class MakeBumpVer: stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, _err = proc.communicate() - if six.PY3: - out = out.decode("utf-8") - - return out.strip('\n') + return out.decode("utf-8").strip('\n') def _incrementVersion(self): fields = self.version.split('.') @@ -64,10 +60,8 @@ class MakeBumpVer: stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, _err = proc.communicate() - if six.PY3: - out = out.decode("utf-8") - ret = out.strip('\n').split('\n') + ret = out.decode("utf-8").strip('\n').split('\n') if len(ret) == 1 and ret[0].find('@') != -1: ret = [ret[0].split('@')[0]] @@ -84,9 +78,7 @@ class MakeBumpVer: stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, _err = proc.communicate() - if six.PY3: - out = out.decode("utf-8") - lines = out.strip('\n').split('\n') + lines = out.decode("utf-8").strip('\n').split('\n') rpm_log = [] diff --git a/scripts/makeupdates b/scripts/makeupdates index f33ebcbe0..1b9fb7eab 100755 --- a/scripts/makeupdates +++ b/scripts/makeupdates @@ -23,7 +23,6 @@ import getopt import os import shutil -import six import subprocess import sys @@ -80,10 +79,8 @@ def doGitDiff(tag, args=None): stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, _err = proc.communicate() - if six.PY3: - out = out.decode("utf-8") - return out.split('\n') + return out.decode("utf-8").split('\n') def copyUpdatedFiles(tag, updates, python_version): def install_to_dir(fname, relpath): diff --git a/setup.py b/setup.py index f362138ab..27163e044 100644 --- a/setup.py +++ b/setup.py @@ -94,7 +94,7 @@ def make_release_tree(self, base_dir, files): url='http://github.com/storaged-project/blivet', data_files=data_files, packages=['blivet', 'blivet.dbus', 'blivet.devices', 'blivet.devicelibs', 'blivet.events', 'blivet.formats', 'blivet.populator', 'blivet.static_data', 'blivet.tasks', 'blivet.populator.helpers'], - install_requires=['pyudev', 'six'], + install_requires=['pyudev'], classifiers=["Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)", diff --git a/tests/run_tests.py b/tests/run_tests.py index e52105c29..cb74a6bb1 100644 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -7,7 +7,6 @@ import os import pdb import re -import six import subprocess import sys import traceback @@ -162,8 +161,7 @@ def addFailure(self, test, err): # pylint: disable=redefined-outer-name os.environ['PYTHONPATH'] = projdir # pylint: disable=environment-modify try: - pyver = 'python3' if six.PY3 else 'python' - os.execv(sys.executable, [pyver] + sys.argv) + os.execv(sys.executable, ['python3'] + sys.argv) except OSError as e: print('Failed re-exec with a new PYTHONPATH: %s' % str(e)) sys.exit(1) diff --git a/tests/storage_tests/devices_test/partition_test.py b/tests/storage_tests/devices_test/partition_test.py index d3ff78a39..2bff60659 100644 --- a/tests/storage_tests/devices_test/partition_test.py +++ b/tests/storage_tests/devices_test/partition_test.py @@ -1,7 +1,6 @@ # vim:set fileencoding=utf-8 import os -import six import unittest from uuid import UUID import parted @@ -55,28 +54,25 @@ def test_target_size(self): self.assertEqual(device.max_size, Size("9 MiB")) # ValueError if not Size - with six.assertRaisesRegex(self, ValueError, - "new size must.*type Size"): + with self.assertRaisesRegex(ValueError, "new size must.*type Size"): device.target_size = 22 self.assertEqual(device.target_size, orig_size) # ValueError if size smaller than min_size - with six.assertRaisesRegex(self, ValueError, - "size.*smaller than the minimum"): + with self.assertRaisesRegex(ValueError, "size.*smaller than the minimum"): device.target_size = Size("1 MiB") self.assertEqual(device.target_size, orig_size) # ValueError if size larger than max_size - with six.assertRaisesRegex(self, ValueError, - "size.*larger than the maximum"): + with self.assertRaisesRegex(ValueError, "size.*larger than the maximum"): device.target_size = Size("11 MiB") self.assertEqual(device.target_size, orig_size) # ValueError if unaligned - with six.assertRaisesRegex(self, ValueError, "new size.*not.*aligned"): + with self.assertRaisesRegex(ValueError, "new size.*not.*aligned"): device.target_size = Size("3.1 MiB") self.assertEqual(device.target_size, orig_size) diff --git a/tests/storage_tests/formats_test/fslabeling.py b/tests/storage_tests/formats_test/fslabeling.py index 80bb048b0..6d03ef51a 100644 --- a/tests/storage_tests/formats_test/fslabeling.py +++ b/tests/storage_tests/formats_test/fslabeling.py @@ -1,14 +1,12 @@ import abc -import six from . import loopbackedtestcase from blivet.errors import FSError, FSReadLabelError from blivet.size import Size -@six.add_metaclass(abc.ABCMeta) -class LabelingAsRoot(loopbackedtestcase.LoopBackedTestCase): +class LabelingAsRoot(loopbackedtestcase.LoopBackedTestCase, metaclass=abc.ABCMeta): """Tests various aspects of labeling a filesystem where there is no easy way to read the filesystem's label once it has been @@ -101,11 +99,11 @@ def test_labeling(self): self.assertIsNone(an_fs.write_label()) an_fs.label = None - with six.assertRaisesRegex(self, FSError, "default label"): + with self.assertRaisesRegex(FSError, "default label"): an_fs.write_label() an_fs.label = self._invalid_label - with six.assertRaisesRegex(self, FSError, "bad label format"): + with self.assertRaisesRegex(FSError, "bad label format"): an_fs.write_label() @@ -145,11 +143,11 @@ def test_labeling(self): self.assertEqual(an_fs.read_label(), an_fs.label) an_fs.label = None - with six.assertRaisesRegex(self, FSError, "default label"): + with self.assertRaisesRegex(FSError, "default label"): an_fs.write_label() an_fs.label = "n" * 129 - with six.assertRaisesRegex(self, FSError, "bad label format"): + with self.assertRaisesRegex(FSError, "bad label format"): an_fs.write_label() def test_creating(self): diff --git a/tests/storage_tests/formats_test/fstesting.py b/tests/storage_tests/formats_test/fstesting.py index 42090a30e..4c4f4cd6a 100644 --- a/tests/storage_tests/formats_test/fstesting.py +++ b/tests/storage_tests/formats_test/fstesting.py @@ -1,6 +1,5 @@ import abc -from six import add_metaclass import os import tempfile @@ -11,8 +10,7 @@ from blivet.formats import fs -@add_metaclass(abc.ABCMeta) -class FSAsRoot(loopbackedtestcase.LoopBackedTestCase): +class FSAsRoot(loopbackedtestcase.LoopBackedTestCase, metaclass=abc.ABCMeta): _fs_class = abc.abstractproperty( doc="The class of the filesystem being tested on.") diff --git a/tests/storage_tests/formats_test/fsuuid.py b/tests/storage_tests/formats_test/fsuuid.py index 0b9762fdb..95288e088 100644 --- a/tests/storage_tests/formats_test/fsuuid.py +++ b/tests/storage_tests/formats_test/fsuuid.py @@ -1,6 +1,5 @@ import sys import abc -import six from unittest import skipIf from . import loopbackedtestcase @@ -9,8 +8,7 @@ from blivet.util import capture_output -@six.add_metaclass(abc.ABCMeta) -class SetUUID(loopbackedtestcase.LoopBackedTestCase): +class SetUUID(loopbackedtestcase.LoopBackedTestCase, metaclass=abc.ABCMeta): """Base class for UUID tests without any test methods.""" @@ -48,7 +46,7 @@ def test_set_invalid_uuid(self): an_fs = self._fs_class(device=self.loop_devices[0], uuid=self._invalid_uuid) if self._fs_class._type == "swap": - with six.assertRaisesRegex(self, FSWriteUUIDError, "bad UUID format"): + with self.assertRaisesRegex(FSWriteUUIDError, "bad UUID format"): an_fs.create() else: with self.assertLogs('blivet', 'WARNING') as logs: @@ -99,7 +97,7 @@ def test_set_invalid_uuid_later(self): self.assertIsNone(an_fs.create()) an_fs.uuid = self._invalid_uuid - with six.assertRaisesRegex(self, FSError, "bad UUID format"): + with self.assertRaisesRegex(FSError, "bad UUID format"): an_fs.write_uuid() def test_reset_uuid(self): diff --git a/tests/storage_tests/partitioning_test.py b/tests/storage_tests/partitioning_test.py index e46a1c3b1..1be5046fa 100644 --- a/tests/storage_tests/partitioning_test.py +++ b/tests/storage_tests/partitioning_test.py @@ -3,7 +3,6 @@ except ImportError: from mock import patch, Mock -import six import unittest import parted @@ -259,8 +258,8 @@ def test_add_partition(self): # # fail: add a logical partition to a primary free region # - with six.assertRaisesRegex(self, PartitioningError, - "no extended partition"): + with self.assertRaisesRegex(PartitioningError, + "no extended partition"): part = add_partition(disk.format, free, parted.PARTITION_LOGICAL, Size("10 MiB")) @@ -291,7 +290,7 @@ def test_add_partition(self): # # fail: add a primary partition to an extended free region # - with six.assertRaisesRegex(self, PartitioningError, "overlap"): + with self.assertRaisesRegex(PartitioningError, "overlap"): part = add_partition(disk.format, all_free[1], parted.PARTITION_NORMAL, Size("10 MiB"), all_free[1].start) diff --git a/tests/storage_tests/unsupported_disklabel_test.py b/tests/storage_tests/unsupported_disklabel_test.py index 380553332..1737af261 100644 --- a/tests/storage_tests/unsupported_disklabel_test.py +++ b/tests/storage_tests/unsupported_disklabel_test.py @@ -3,7 +3,6 @@ except ImportError: from mock import patch, sentinel, DEFAULT -import six import unittest from blivet.actionlist import ActionList @@ -25,23 +24,15 @@ def setUp(self): fmt=get_format("disklabel", exists=True)) disk1.format._supported = False - if six.PY3: - with self.assertLogs("blivet", level="INFO") as cm: - partition1 = PartitionDevice("testpart1", size=Size("150 GiB"), exists=True, - parents=[disk1], fmt=get_format("ext4", exists=True)) - self.assertTrue("disklabel is unsupported" in "\n".join(cm.output)) - else: + with self.assertLogs("blivet", level="INFO") as cm: partition1 = PartitionDevice("testpart1", size=Size("150 GiB"), exists=True, parents=[disk1], fmt=get_format("ext4", exists=True)) + self.assertTrue("disklabel is unsupported" in "\n".join(cm.output)) - if six.PY3: - with self.assertLogs("blivet", level="INFO") as cm: - partition2 = PartitionDevice("testpart2", size=Size("100 GiB"), exists=True, - parents=[disk1], fmt=get_format("lvmpv", exists=True)) - self.assertTrue("disklabel is unsupported" in "\n".join(cm.output)) - else: + with self.assertLogs("blivet", level="INFO") as cm: partition2 = PartitionDevice("testpart2", size=Size("100 GiB"), exists=True, parents=[disk1], fmt=get_format("lvmpv", exists=True)) + self.assertTrue("disklabel is unsupported" in "\n".join(cm.output)) # To be supported, all of a devices ancestors must be supported. disk2 = DiskDevice("testdisk2", size=Size("300 GiB"), exists=True, diff --git a/tests/unit_tests/devicefactory_test.py b/tests/unit_tests/devicefactory_test.py index afaf8a6e3..9c1906845 100644 --- a/tests/unit_tests/devicefactory_test.py +++ b/tests/unit_tests/devicefactory_test.py @@ -1,5 +1,4 @@ -import six import unittest from decimal import Decimal import os @@ -900,16 +899,16 @@ def test_mdfactory(self, *args): # pylint: disable=unused-argument size=Size("1 GiB"), raid_level=0) - with six.assertRaisesRegex(self, devicefactory.DeviceFactoryError, "must have some RAID level"): + with self.assertRaisesRegex(devicefactory.DeviceFactoryError, "must have some RAID level"): devicefactory.get_device_factory( self.b, devicefactory.DEVICE_TYPE_MD, size=Size("1 GiB")) - with six.assertRaisesRegex(self, RaidError, "requires at least"): + with self.assertRaisesRegex(RaidError, "requires at least"): factory1._get_device_space() - with six.assertRaisesRegex(self, RaidError, "requires at least"): + with self.assertRaisesRegex(RaidError, "requires at least"): factory1._configure() self.assertEqual(factory1.container_list, []) @@ -922,7 +921,7 @@ def test_mdfactory(self, *args): # pylint: disable=unused-argument ] self.assertIsNotNone(factory1._get_new_device(parents=parents)) - with six.assertRaisesRegex(self, RaidError, "requires at least"): + with self.assertRaisesRegex(RaidError, "requires at least"): factory2._get_device_space() self.assertEqual(factory2.container_list, []) diff --git a/tests/unit_tests/devicelibs_test/disk_test.py b/tests/unit_tests/devicelibs_test/disk_test.py index 9cb39951c..b55f4e909 100644 --- a/tests/unit_tests/devicelibs_test/disk_test.py +++ b/tests/unit_tests/devicelibs_test/disk_test.py @@ -4,7 +4,6 @@ except ImportError: from mock import Mock, patch, sentinel -import six import unittest from blivet.devicelibs import disk as disklib @@ -92,10 +91,10 @@ def client_volume_raid_info(volume): return (volume.raid_type, volume.stripe_size, volume.drives, volume.min_io, volume.opt_io) def vpd83_search(vpd83): - return six.next((vol.nodes for vol in _client_volumes if vol.vpd83 == vpd83), None) + return next((vol.nodes for vol in _client_volumes if vol.vpd83 == vpd83), None) def system_by_id(sys_id): - return six.next((sys for sys in _client_systems if sys.id == sys_id), None) + return next((sys for sys in _client_systems if sys.id == sys_id), None) with patch("blivet.devicelibs.disk._lsm_required._check_avail", return_value=True): with patch("blivet.devicelibs.disk.lsm") as _lsm: diff --git a/tests/unit_tests/devicelibs_test/raid_test.py b/tests/unit_tests/devicelibs_test/raid_test.py index d380e18df..e019d9855 100644 --- a/tests/unit_tests/devicelibs_test/raid_test.py +++ b/tests/unit_tests/devicelibs_test/raid_test.py @@ -1,4 +1,3 @@ -import six import unittest import blivet.devicelibs.raid as raid @@ -15,7 +14,7 @@ def setUp(self): def test_raid(self): - with six.assertRaisesRegex(self, TypeError, "Can't instantiate abstract class"): + with self.assertRaisesRegex(TypeError, "Can't instantiate abstract class"): raid.ErsatzRAID() ## @@ -152,11 +151,11 @@ def test_raid(self): ## # __init__ ## - with six.assertRaisesRegex(self, errors.RaidError, "invalid RAID level"): + with self.assertRaisesRegex(errors.RaidError, "invalid RAID level"): self.levels_none.raid_level(10) - with six.assertRaisesRegex(self, errors.RaidError, "invalid RAID level"): + with self.assertRaisesRegex(errors.RaidError, "invalid RAID level"): self.levels_some.raid_level(10) - with six.assertRaisesRegex(self, errors.RaidError, "invalid standard RAID level descriptor"): + with self.assertRaisesRegex(errors.RaidError, "invalid standard RAID level descriptor"): raid.RAIDLevels(["raid3.1415"]) diff --git a/tests/unit_tests/devices_test/device_dependencies_test.py b/tests/unit_tests/devices_test/device_dependencies_test.py index 53d81691a..d7adbabcf 100644 --- a/tests/unit_tests/devices_test/device_dependencies_test.py +++ b/tests/unit_tests/devices_test/device_dependencies_test.py @@ -5,7 +5,6 @@ import unittest import os -import six import blivet import gi gi.require_version("BlockDev", "3.0") @@ -203,7 +202,7 @@ def test_weak_dependencies(self): raid1 = self.bvt.new_partition(size=Size("1GiB"), fmt_type="mdmember") raid2 = self.bvt.new_partition(size=Size("1GiB"), fmt_type="mdmember") - with six.assertRaisesRegex(self, ValueError, "resource to create this format.*unavailable"): + with self.assertRaisesRegex(ValueError, "resource to create this format.*unavailable"): self.bvt.create_device(pv_fail) # to be able to test functions like destroy_device it is necessary to have some @@ -245,7 +244,7 @@ def test_weak_dependencies(self): self.bvt.create_device(pool) self.unload_all_plugins() - with six.assertRaisesRegex(self, DependencyError, "requires unavailable_dependencies"): + with self.assertRaisesRegex(DependencyError, "requires unavailable_dependencies"): self.bvt.destroy_device(pool) try: @@ -253,7 +252,7 @@ def test_weak_dependencies(self): except blockdev.BlockDevNotImplementedError: # pylint: disable=catching-non-exception self.fail("Improper handling of missing libblockdev plugin") - with six.assertRaisesRegex(self, ValueError, "device cannot be resized"): + with self.assertRaisesRegex(ValueError, "device cannot be resized"): self.bvt.resize_device(lv3, Size("2GiB")) try: diff --git a/tests/unit_tests/devices_test/device_methods_test.py b/tests/unit_tests/devices_test/device_methods_test.py index b75839c1c..4470f51dc 100644 --- a/tests/unit_tests/devices_test/device_methods_test.py +++ b/tests/unit_tests/devices_test/device_methods_test.py @@ -1,4 +1,3 @@ -import six import unittest try: @@ -109,7 +108,7 @@ def test_create(self): self.device.exists = True self.patches["status"].return_value = True with patch.object(self.device, "_create"): - six.assertRaisesRegex(self, DeviceError, "has already been created", self.device.create) + self.assertRaisesRegex(DeviceError, "has already been created", self.device.create) self.assertFalse(self.device._create.called) self.device.exists = False @@ -121,7 +120,7 @@ def _create(): with patch.object(self.device, "_post_create"): with patch.object(self.device, "_pre_create"): self.device._create.side_effect = _create - six.assertRaisesRegex(self, RuntimeError, "problems", self.device.create) + self.assertRaisesRegex(RuntimeError, "problems", self.device.create) self.assertTrue(self.device._create.called) self.assertFalse(self.device._post_create.called) self.assertTrue(self.device._pre_create.called) @@ -144,7 +143,7 @@ def test_destroy(self): self.device.exists = False self.patches["status"].return_value = True with patch.object(self.device, "_destroy"): - six.assertRaisesRegex(self, DeviceError, "has not been created", self.device.destroy) + self.assertRaisesRegex(DeviceError, "has not been created", self.device.destroy) self.assertFalse(self.device._destroy.called) self.device.exists = True @@ -155,7 +154,7 @@ def _destroy(): with patch.object(self.device, "_destroy"): with patch.object(self.device, "_post_destroy"): self.device._destroy.side_effect = _destroy - six.assertRaisesRegex(self, RuntimeError, "problems", self.device.destroy) + self.assertRaisesRegex(RuntimeError, "problems", self.device.destroy) self.assertTrue(self.device._destroy.called) self.assertFalse(self.device._post_destroy.called) @@ -174,7 +173,7 @@ def test_setup(self): self.device.exists = False self.patches["status"].return_value = False with patch.object(self.device, "_setup"): - six.assertRaisesRegex(self, DeviceError, "has not been created", self.device.setup) + self.assertRaisesRegex(DeviceError, "has not been created", self.device.setup) self.assertFalse(self.device._setup.called) self.device.exists = True @@ -217,7 +216,7 @@ def test_setup(self): def test_teardown(self): self.device.exists = False with patch.object(self.device, "_teardown"): - six.assertRaisesRegex(self, DeviceError, "has not been created", self.device.teardown) + self.assertRaisesRegex(DeviceError, "has not been created", self.device.teardown) self.assertFalse(self.device._teardown.called) self.device.exists = True diff --git a/tests/unit_tests/devices_test/device_names_test.py b/tests/unit_tests/devices_test/device_names_test.py index ca44d38cd..7a49c5050 100644 --- a/tests/unit_tests/devices_test/device_names_test.py +++ b/tests/unit_tests/devices_test/device_names_test.py @@ -4,7 +4,6 @@ except ImportError: from mock import patch -import six import unittest from blivet.devices import LVMVolumeGroupDevice @@ -53,7 +52,7 @@ def test_storage_device(self, *patches): # pylint: disable=unused-argument if ' is not a valid name for this device' in str(e): self.fail("Device name checked on already existing device") - with six.assertRaisesRegex(self, ValueError, ' is not a valid name for this device'): + with self.assertRaisesRegex(ValueError, ' is not a valid name for this device'): StorageDevice(name, exists=False) def test_volume_group(self): diff --git a/tests/unit_tests/devices_test/device_properties_test.py b/tests/unit_tests/devices_test/device_properties_test.py index 3b4047585..60f9e17fa 100644 --- a/tests/unit_tests/devices_test/device_properties_test.py +++ b/tests/unit_tests/devices_test/device_properties_test.py @@ -1,4 +1,3 @@ -import six import unittest import gi @@ -76,7 +75,7 @@ def __init__(self, methodName='run_test'): "parents": xform(lambda x, m: self.assertEqual(len(x), 0, m) and self.assertIsInstance(x, ParentList, m)), "partitionable": xform(self.assertFalse), - "path": xform(lambda x, m: six.assertRegex(self, x, "^/dev", m)), + "path": xform(lambda x, m: self.assertRegex(x, "^/dev", m)), "raw_device": xform(self.assertIsNotNone), "resizable": xform(self.assertFalse), "size": xform(lambda x, m: self.assertEqual(x, Size(0), m)), @@ -549,35 +548,35 @@ def test_mdraid_array_device_init(self): parents=xform(lambda x, m: self.assertEqual(len(x), 2, m)), uuid=xform(lambda x, m: self.assertEqual(x, self.dev20.uuid, m))) - with six.assertRaisesRegex(self, DeviceError, "invalid"): + with self.assertRaisesRegex(DeviceError, "invalid"): MDRaidArrayDevice("dev") - with six.assertRaisesRegex(self, DeviceError, "invalid"): + with self.assertRaisesRegex(DeviceError, "invalid"): MDRaidArrayDevice("dev", level="raid2") - with six.assertRaisesRegex(self, DeviceError, "invalid"): + with self.assertRaisesRegex(DeviceError, "invalid"): MDRaidArrayDevice( "dev", parents=[StorageDevice("parent", fmt=get_format("mdmember"))]) - with six.assertRaisesRegex(self, DeviceError, "at least 2 members"): + with self.assertRaisesRegex(DeviceError, "at least 2 members"): MDRaidArrayDevice( "dev", level="raid0", parents=[StorageDevice("parent", fmt=get_format("mdmember"))]) - with six.assertRaisesRegex(self, DeviceError, "invalid"): + with self.assertRaisesRegex(DeviceError, "invalid"): MDRaidArrayDevice("dev", level="junk") - with six.assertRaisesRegex(self, DeviceError, "at least 2 members"): + with self.assertRaisesRegex(DeviceError, "at least 2 members"): MDRaidArrayDevice("dev", level=0, member_devices=2) def test_mdraid_array_device_methods(self): """Test for method calls on initialized MDRaidDevices.""" - with six.assertRaisesRegex(self, DeviceError, "invalid"): + with self.assertRaisesRegex(DeviceError, "invalid"): self.dev7.level = "junk" - with six.assertRaisesRegex(self, DeviceError, "invalid"): + with self.assertRaisesRegex(DeviceError, "invalid"): self.dev7.level = None @@ -653,27 +652,27 @@ def test_btrfsdevice_init(self): type=xform(lambda x, m: self.assertEqual(x, "btrfs volume", m)), uuid=xform(self.assertIsNotNone)) - with six.assertRaisesRegex(self, ValueError, "BTRFSDevice.*must have at least one parent"): + with self.assertRaisesRegex(ValueError, "BTRFSDevice.*must have at least one parent"): BTRFSVolumeDevice("dev") - with six.assertRaisesRegex(self, ValueError, "format"): + with self.assertRaisesRegex(ValueError, "format"): BTRFSVolumeDevice("dev", parents=[StorageDevice("deva", size=BTRFS_MIN_MEMBER_SIZE)]) - with six.assertRaisesRegex(self, DeviceError, "btrfs subvolume.*must be a btrfs volume"): + with self.assertRaisesRegex(DeviceError, "btrfs subvolume.*must be a btrfs volume"): fmt = blivet.formats.get_format("btrfs") device = StorageDevice("deva", fmt=fmt, size=BTRFS_MIN_MEMBER_SIZE) BTRFSSubVolumeDevice("dev1", parents=[device]) deva = OpticalDevice("deva", fmt=blivet.formats.get_format("btrfs", exists=True), exists=True) - with six.assertRaisesRegex(self, BTRFSValueError, "at least"): + with self.assertRaisesRegex(BTRFSValueError, "at least"): BTRFSVolumeDevice("dev1", data_level="raid1", parents=[deva]) deva = StorageDevice("deva", fmt=blivet.formats.get_format("btrfs"), size=BTRFS_MIN_MEMBER_SIZE) self.assertIsNotNone(BTRFSVolumeDevice("dev1", metadata_level="dup", parents=[deva])) deva = StorageDevice("deva", fmt=blivet.formats.get_format("btrfs"), size=BTRFS_MIN_MEMBER_SIZE) - with six.assertRaisesRegex(self, BTRFSValueError, "invalid"): + with self.assertRaisesRegex(BTRFSValueError, "invalid"): BTRFSVolumeDevice("dev1", data_level="dup", parents=[deva]) self.assertEqual(self.dev1.isleaf, False) @@ -698,24 +697,24 @@ def test_btrfsdevice_methods(self): self.assertIsNotNone(self.dev2.volume) # size - with six.assertRaisesRegex(self, RuntimeError, "cannot directly set size of btrfs volume"): + with self.assertRaisesRegex(RuntimeError, "cannot directly set size of btrfs volume"): self.dev1.size = Size("500 MiB") def test_btrfssnap_shot_device_init(self): parents = [StorageDevice("p1", fmt=blivet.formats.get_format("btrfs"), size=BTRFS_MIN_MEMBER_SIZE)] vol = BTRFSVolumeDevice("test", parents=parents) - with six.assertRaisesRegex(self, ValueError, "non-existent btrfs snapshots must have a source"): + with self.assertRaisesRegex(ValueError, "non-existent btrfs snapshots must have a source"): BTRFSSnapShotDevice("snap1", parents=[vol]) - with six.assertRaisesRegex(self, ValueError, "btrfs snapshot source must already exist"): + with self.assertRaisesRegex(ValueError, "btrfs snapshot source must already exist"): BTRFSSnapShotDevice("snap1", parents=[vol], source=vol) - with six.assertRaisesRegex(self, ValueError, "btrfs snapshot source must be a btrfs subvolume"): + with self.assertRaisesRegex(ValueError, "btrfs snapshot source must be a btrfs subvolume"): BTRFSSnapShotDevice("snap1", parents=[vol], source=parents[0]) parents2 = [StorageDevice("p1", fmt=blivet.formats.get_format("btrfs"), size=BTRFS_MIN_MEMBER_SIZE, exists=True)] vol2 = BTRFSVolumeDevice("test2", parents=parents2, exists=True) - with six.assertRaisesRegex(self, ValueError, ".*snapshot and source must be in the same volume"): + with self.assertRaisesRegex(ValueError, ".*snapshot and source must be in the same volume"): BTRFSSnapShotDevice("snap1", parents=[vol], source=vol2) vol.exists = True diff --git a/tests/unit_tests/devices_test/lvm_test.py b/tests/unit_tests/devices_test/lvm_test.py index 16cbd85c7..c8ee902c5 100644 --- a/tests/unit_tests/devices_test/lvm_test.py +++ b/tests/unit_tests/devices_test/lvm_test.py @@ -3,7 +3,6 @@ except ImportError: from mock import patch, PropertyMock -import six import unittest import blivet @@ -32,10 +31,10 @@ def test_lvmsnap_shot_device_init(self): lv = LVMLogicalVolumeDevice("testlv", parents=[vg], fmt=blivet.formats.get_format("xfs")) - with six.assertRaisesRegex(self, errors.DeviceError, "lvm snapshot origin must be a logical volume"): + with self.assertRaisesRegex(errors.DeviceError, "lvm snapshot origin must be a logical volume"): LVMLogicalVolumeDevice("snap1", parents=[vg], origin=pv) - with six.assertRaisesRegex(self, errors.DeviceError, "only existing vorigin snapshots are supported"): + with self.assertRaisesRegex(errors.DeviceError, "only existing vorigin snapshots are supported"): LVMLogicalVolumeDevice("snap1", parents=[vg], vorigin=True) lv.exists = True @@ -60,7 +59,7 @@ def test_lvmthin_snap_shot_device_init(self): pool = LVMLogicalVolumeDevice("pool1", parents=[vg], size=Size("500 MiB"), seg_type="thin-pool") thinlv = LVMLogicalVolumeDevice("thinlv", parents=[pool], size=Size("200 MiB"), seg_type="thin") - with six.assertRaisesRegex(self, errors.DeviceError, "lvm snapshot origin must be a logical volume"): + with self.assertRaisesRegex(errors.DeviceError, "lvm snapshot origin must be a logical volume"): LVMLogicalVolumeDevice("snap1", parents=[pool], origin=pv, seg_type="thin") # now make the constructor succeed so we can test some properties @@ -411,16 +410,16 @@ def test_target_size(self, *args): # pylint: disable=unused-argument self.assertEqual(lv.size, orig_size) # ValueError if size smaller than min_size - with six.assertRaisesRegex(self, ValueError, - "size.*smaller than the minimum"): + with self.assertRaisesRegex(ValueError, + "size.*smaller than the minimum"): lv.target_size = Size("1 MiB") # target size should be unchanged self.assertEqual(lv.target_size, orig_size) # ValueError if size larger than max_size - with six.assertRaisesRegex(self, ValueError, - "size.*larger than the maximum"): + with self.assertRaisesRegex(ValueError, + "size.*larger than the maximum"): lv.target_size = Size("1 GiB") # target size should be unchanged @@ -445,7 +444,7 @@ def test_lvm_inconsistent_sector_size(self): with patch("blivet.devices.StorageDevice.sector_size", new_callable=PropertyMock) as mock_property: mock_property.__get__ = lambda _mock, pv, _class: 512 if pv.name == "pv1" else 4096 - with six.assertRaisesRegex(self, ValueError, "Cannot create volume group"): + with self.assertRaisesRegex(ValueError, "Cannot create volume group"): LVMVolumeGroupDevice("testvg", parents=[pv, pv2]) def test_skip_activate(self): @@ -920,17 +919,17 @@ def test_vdo_dependencies(self): "libblockdev lvm plugin", "libblockdev lvm plugin (vdo technology)"] pool_deps = [d.name for d in vdopool.external_dependencies] - six.assertCountEqual(self, pool_deps, lvm_vdo_dependencies) + self.assertCountEqual(pool_deps, lvm_vdo_dependencies) vdolv_deps = [d.name for d in vdolv.external_dependencies] - six.assertCountEqual(self, vdolv_deps, lvm_vdo_dependencies) + self.assertCountEqual(vdolv_deps, lvm_vdo_dependencies) # same dependencies should be returned when checking with class not instance pool_type_deps = [d.name for d in LVMVDOPoolMixin.type_external_dependencies()] - six.assertCountEqual(self, pool_type_deps, lvm_vdo_dependencies) + self.assertCountEqual(pool_type_deps, lvm_vdo_dependencies) vdolv_type_deps = [d.name for d in LVMVDOLogicalVolumeMixin.type_external_dependencies()] - six.assertCountEqual(self, vdolv_type_deps, lvm_vdo_dependencies) + self.assertCountEqual(vdolv_type_deps, lvm_vdo_dependencies) with patch("blivet.blivet.Blivet.names", new=[]): # just to be sure LVM VDO specific code didn't break "normal" LVs @@ -939,8 +938,7 @@ def test_vdo_dependencies(self): size=blivet.size.Size("1 GiB")) normalvl_deps = [d.name for d in normallv.external_dependencies] - six.assertCountEqual(self, normalvl_deps, ["libblockdev dm plugin", - "libblockdev lvm plugin"]) + self.assertCountEqual(normalvl_deps, ["libblockdev dm plugin", "libblockdev lvm plugin"]) with patch("blivet.devices.lvm.LVMVDOPoolMixin._external_dependencies", new=[blivet.tasks.availability.unavailable_resource("VDO unavailability test")]): @@ -951,22 +949,22 @@ def test_vdo_dependencies(self): lvm_type_deps = [d.name for d in LVMLogicalVolumeDevice.unavailable_type_dependencies()] pool_deps = [d.name for d in vdopool.unavailable_dependencies] - six.assertCountEqual(self, pool_deps, ["VDO unavailability test"] + lvm_type_deps) + self.assertCountEqual(pool_deps, ["VDO unavailability test"] + lvm_type_deps) vdolv_deps = [d.name for d in vdolv.unavailable_dependencies] - six.assertCountEqual(self, vdolv_deps, ["VDO unavailability test"] + lvm_type_deps) + self.assertCountEqual(vdolv_deps, ["VDO unavailability test"] + lvm_type_deps) # same dependencies should be returned when checking with class not instance pool_type_deps = [d.name for d in LVMVDOPoolMixin.unavailable_type_dependencies()] - six.assertCountEqual(self, pool_type_deps, - ["VDO unavailability test"] + lvm_type_deps) + self.assertCountEqual(pool_type_deps, + ["VDO unavailability test"] + lvm_type_deps) vdolv_type_deps = [d.name for d in LVMVDOLogicalVolumeMixin.unavailable_type_dependencies()] - six.assertCountEqual(self, vdolv_type_deps, - ["VDO unavailability test"] + lvm_type_deps) + self.assertCountEqual(vdolv_type_deps, + ["VDO unavailability test"] + lvm_type_deps) normallv_deps = [d.name for d in normallv.unavailable_dependencies] - six.assertCountEqual(self, normallv_deps, lvm_type_deps) + self.assertCountEqual(normallv_deps, lvm_type_deps) with self.assertRaises(errors.DependencyError): self.b.create_device(vdopool) diff --git a/tests/unit_tests/devices_test/md_test.py b/tests/unit_tests/devices_test/md_test.py index b3e825ca8..a522b0d19 100644 --- a/tests/unit_tests/devices_test/md_test.py +++ b/tests/unit_tests/devices_test/md_test.py @@ -1,4 +1,3 @@ -import six import unittest try: @@ -69,13 +68,13 @@ def test_chunk_size2(self): raid_array.chunk_size = Size(0) self.assertEqual(raid_array.chunk_size, mdraid.MD_CHUNK_SIZE) - with six.assertRaisesRegex(self, ValueError, "new chunk size must be of type Size"): + with self.assertRaisesRegex(ValueError, "new chunk size must be of type Size"): raid_array.chunk_size = 1 - with six.assertRaisesRegex(self, ValueError, "new chunk size must be multiple of 4 KiB"): + with self.assertRaisesRegex(ValueError, "new chunk size must be multiple of 4 KiB"): raid_array.chunk_size = Size("5 KiB") - with six.assertRaisesRegex(self, ValueError, "specifying chunk size is not allowed for raid1"): + with self.assertRaisesRegex(ValueError, "specifying chunk size is not allowed for raid1"): MDRaidArrayDevice(name="raid", level="raid1", member_devices=2, total_devices=2, parents=[member1, member2], chunk_size=Size("1024 KiB")) @@ -83,7 +82,7 @@ def test_chunk_size2(self): raid_array = MDRaidArrayDevice(name="raid", level="raid1", member_devices=2, total_devices=2, parents=[member1, member2]) - with six.assertRaisesRegex(self, ValueError, "specifying chunk size is not allowed for raid1"): + with self.assertRaisesRegex(ValueError, "specifying chunk size is not allowed for raid1"): raid_array.chunk_size = Size("512 KiB") def test_device_id(self): diff --git a/tests/unit_tests/devices_test/stratis_test.py b/tests/unit_tests/devices_test/stratis_test.py index f22372219..35fb6b049 100644 --- a/tests/unit_tests/devices_test/stratis_test.py +++ b/tests/unit_tests/devices_test/stratis_test.py @@ -1,4 +1,3 @@ -import six import unittest try: @@ -51,7 +50,7 @@ def test_new_stratis(self): self.assertAlmostEqual(fs.used_size, Size("20 MiB"), delta=Size("1 MiB")) with patch("blivet.devicetree.DeviceTree.names", []): - with six.assertRaisesRegex(self, StratisError, "not enough free space in the pool"): + with self.assertRaisesRegex(StratisError, "not enough free space in the pool"): # not enough free space for a 2 TiB filesystem b.new_stratis_filesystem(name="testfs2", parents=[pool], size=Size("2 TiB")) diff --git a/tests/unit_tests/devicetree_test.py b/tests/unit_tests/devicetree_test.py index 77781d42f..0eeb93844 100644 --- a/tests/unit_tests/devicetree_test.py +++ b/tests/unit_tests/devicetree_test.py @@ -3,7 +3,6 @@ except ImportError: from mock import patch, Mock, PropertyMock, sentinel -import six import unittest from blivet.actionlist import ActionList @@ -217,17 +216,17 @@ def test_add_device(self, *args): # pylint: disable=unused-argument self.assertTrue(dev1.add_hook.called) # pylint: disable=no-member # adding an already-added device fails - six.assertRaisesRegex(self, DeviceTreeError, "Trying to add already existing device.", dt._add_device, dev1) + self.assertRaisesRegex(DeviceTreeError, "Trying to add already existing device.", dt._add_device, dev1) # adding a device with the same UUID dev_clone = StorageDevice("dev_clone", exists=False, uuid=sentinel.dev1_uuid, parents=[]) - six.assertRaisesRegex(self, DuplicateUUIDError, "Duplicate UUID.*", dt._add_device, dev_clone) + self.assertRaisesRegex(DuplicateUUIDError, "Duplicate UUID.*", dt._add_device, dev_clone) dev2 = StorageDevice("dev2", exists=False, parents=[]) dev3 = StorageDevice("dev3", exists=False, parents=[dev1, dev2]) # adding a device with one or more parents not already in the tree fails - six.assertRaisesRegex(self, DeviceTreeError, "parent.*not in tree", dt._add_device, dev3) + self.assertRaisesRegex(DeviceTreeError, "parent.*not in tree", dt._add_device, dev3) self.assertFalse(dev2 in dt.devices) self.assertFalse(dev2.name in dt.names) @@ -247,7 +246,7 @@ def test_remove_device(self, *args): # pylint: disable=unused-argument dev1 = StorageDevice("dev1", exists=False, parents=[]) # removing a device not in the tree raises an exception - six.assertRaisesRegex(self, ValueError, "not in tree", dt._remove_device, dev1) + self.assertRaisesRegex(ValueError, "not in tree", dt._remove_device, dev1) dt._add_device(dev1) with patch("blivet.devicetree.callbacks") as callbacks: @@ -265,7 +264,7 @@ def test_remove_device(self, *args): # pylint: disable=unused-argument self.assertTrue(dev2.name in dt.names) # removal of a non-leaf device raises an exception - six.assertRaisesRegex(self, ValueError, "non-leaf device", dt._remove_device, dev1) + self.assertRaisesRegex(ValueError, "non-leaf device", dt._remove_device, dev1) self.assertTrue(dev1 in dt.devices) self.assertTrue(dev1.name in dt.names) self.assertTrue(dev2 in dt.devices) diff --git a/tests/unit_tests/formats_tests/methods_test.py b/tests/unit_tests/formats_tests/methods_test.py index 48d0a35c3..8a9b84603 100644 --- a/tests/unit_tests/formats_tests/methods_test.py +++ b/tests/unit_tests/formats_tests/methods_test.py @@ -3,7 +3,6 @@ except ImportError: from mock import patch, sentinel, PropertyMock -import six import unittest from blivet.errors import DeviceFormatError @@ -88,7 +87,7 @@ def test_create(self): self.format.exists = True with patch.object(self.format, "_create"): self.set_os_path_exists(True) - six.assertRaisesRegex(self, DeviceFormatError, "format already exists", self.format.create) + self.assertRaisesRegex(DeviceFormatError, "format already exists", self.format.create) self.assertFalse(self.format._create.called) # pylint: disable=no-member self.format.exists = False @@ -96,7 +95,7 @@ def test_create(self): with patch.object(self.format, "_create"): # device must be accessible self.set_os_path_exists(False) - six.assertRaisesRegex(self, DeviceFormatError, "invalid device specification", self.format.create) + self.assertRaisesRegex(DeviceFormatError, "invalid device specification", self.format.create) self.assertFalse(self.format._create.called) # pylint: disable=no-member self.set_os_path_exists(True) @@ -110,14 +109,14 @@ def _fail(*args, **kwargs): with patch.object(self.format, "_create"): with patch.object(self.format, "_pre_create") as m: m.side_effect = _fail - six.assertRaisesRegex(self, RuntimeError, "problems", self.format.create) + self.assertRaisesRegex(RuntimeError, "problems", self.format.create) self.assertFalse(self.format._create.called) # pylint: disable=no-member self.assertFalse(self.format.exists) # _create raises -> no _post_create -> exists == False with patch.object(self.format, "_create") as m: m.side_effect = _fail - six.assertRaisesRegex(self, RuntimeError, "problems", self.format.create) + self.assertRaisesRegex(RuntimeError, "problems", self.format.create) self.assertTrue(self.format._create.called) # pylint: disable=no-member self.assertFalse(self.format.exists) @@ -141,7 +140,7 @@ def test_destroy(self): self.format.exists = False with patch.object(self.format, "_destroy"): self.patches["os"].access.return_value = True - six.assertRaisesRegex(self, DeviceFormatError, "has not been created", self.format.destroy) + self.assertRaisesRegex(DeviceFormatError, "has not been created", self.format.destroy) self.assertFalse(self.format._destroy.called) # pylint: disable=no-member self.format.exists = True @@ -149,14 +148,14 @@ def test_destroy(self): # format must be inactive with patch.object(self.format, "_destroy"): self.patches["status"].return_value = True - six.assertRaisesRegex(self, DeviceFormatError, "is active", self.format.destroy) + self.assertRaisesRegex(DeviceFormatError, "is active", self.format.destroy) self.assertFalse(self.format._destroy.called) # pylint: disable=no-member # device must be accessible with patch.object(self.format, "_destroy"): self.patches["os"].access.return_value = False self.patches["status"].return_value = False - six.assertRaisesRegex(self, DeviceFormatError, "device path does not exist", self.format.destroy) + self.assertRaisesRegex(DeviceFormatError, "device path does not exist", self.format.destroy) self.assertFalse(self.format._destroy.called) # pylint: disable=no-member self.patches["os"].access.return_value = True @@ -170,14 +169,14 @@ def _fail(*args, **kwargs): with patch.object(self.format, "_destroy"): with patch.object(self.format, "_pre_destroy") as m: m.side_effect = _fail - six.assertRaisesRegex(self, RuntimeError, "problems", self.format.destroy) + self.assertRaisesRegex(RuntimeError, "problems", self.format.destroy) self.assertFalse(self.format._destroy.called) # pylint: disable=no-member self.assertTrue(self.format.exists) # _destroy raises -> no _post_destroy -> exists == True with patch.object(self.format, "_destroy") as m: m.side_effect = _fail - six.assertRaisesRegex(self, RuntimeError, "problems", self.format.destroy) + self.assertRaisesRegex(RuntimeError, "problems", self.format.destroy) self.assertTrue(self.format._destroy.called) # pylint: disable=no-member self.assertTrue(self.format.exists) @@ -201,7 +200,7 @@ def test_setup(self): self.format.exists = False with patch.object(self.format, "_setup"): self.set_os_path_exists(True) - six.assertRaisesRegex(self, DeviceFormatError, "has not been created", self.format.setup) + self.assertRaisesRegex(DeviceFormatError, "has not been created", self.format.setup) # _pre_setup raises exn -> no _setup self.assertFalse(self.format._setup.called) # pylint: disable=no-member self.format.exists = True @@ -209,7 +208,7 @@ def test_setup(self): # device must be accessible with patch.object(self.format, "_setup"): self.set_os_path_exists(False) - six.assertRaisesRegex(self, DeviceFormatError, "invalid|does not exist", self.format.setup) + self.assertRaisesRegex(DeviceFormatError, "invalid|does not exist", self.format.setup) # _pre_setup raises exn -> no _setup self.assertFalse(self.format._setup.called) # pylint: disable=no-member @@ -229,7 +228,7 @@ def _fail(*args, **kwargs): with patch.object(self.format, "_setup", side_effect=_fail): with patch.object(self.format, "_post_setup"): - six.assertRaisesRegex(self, RuntimeError, "problems", self.format.setup) + self.assertRaisesRegex(RuntimeError, "problems", self.format.setup) self.assertFalse(self.format._post_setup.called) # pylint: disable=no-member # _setup succeeds -> _post_setup @@ -247,7 +246,7 @@ def test_teardown(self): self.format.exists = False with patch.object(self.format, "_teardown"): self.set_os_path_exists(True) - six.assertRaisesRegex(self, DeviceFormatError, "has not been created", self.format.teardown) + self.assertRaisesRegex(DeviceFormatError, "has not been created", self.format.teardown) self.assertFalse(self.format._teardown.called) # pylint: disable=no-member self.format.exists = True @@ -255,7 +254,7 @@ def test_teardown(self): # device must be accessible # with patch.object(self.format, "_teardown"): # self.set_os_path_exists(False) - # six.assertRaisesRegex(self, DeviceFormatError, "invalid device specification", self.format.teardown) + # self.assertRaisesRegex(DeviceFormatError, "invalid device specification", self.format.teardown) # self.assertFalse(self.format._teardown.called) # pylint: disable=no-member # _teardown fails -> no _post_teardown @@ -267,7 +266,7 @@ def _fail(*args, **kwargs): with patch.object(self.format, "_teardown", side_effect=_fail): with patch.object(self.format, "_post_teardown"): - six.assertRaisesRegex(self, RuntimeError, "problems", self.format.teardown) + self.assertRaisesRegex(RuntimeError, "problems", self.format.teardown) self.assertFalse(self.format._post_teardown.called) # pylint: disable=no-member # _teardown succeeds -> _post_teardown diff --git a/tests/unit_tests/formats_tests/swap_test.py b/tests/unit_tests/formats_tests/swap_test.py index 1970776dd..207c804ea 100644 --- a/tests/unit_tests/formats_tests/swap_test.py +++ b/tests/unit_tests/formats_tests/swap_test.py @@ -1,4 +1,3 @@ -import six import unittest from blivet.devices.storage import StorageDevice @@ -17,7 +16,7 @@ def test_swap_max_size(self): StorageDevice("dev", size=Size("15 TiB"), fmt=get_format("swap")) - with six.assertRaisesRegex(self, DeviceError, "device is too large for new format"): + with self.assertRaisesRegex(DeviceError, "device is too large for new format"): StorageDevice("dev", size=Size("17 TiB"), fmt=get_format("swap")) diff --git a/tests/unit_tests/populator_test.py b/tests/unit_tests/populator_test.py index febdf92ce..a4fea735d 100644 --- a/tests/unit_tests/populator_test.py +++ b/tests/unit_tests/populator_test.py @@ -4,7 +4,6 @@ from mock import call, patch, sentinel, Mock, PropertyMock import gi -import six import unittest gi.require_version("BlockDev", "3.0") @@ -1061,7 +1060,7 @@ def test_run(self, *args): def gdbu(uuid, **kwargs): # pylint: disable=unused-argument # This version doesn't check format UUIDs - return six.next((d for d in devicetree.devices if d.uuid == uuid), None) + return next((d for d in devicetree.devices if d.uuid == uuid), None) get_device_by_uuid.side_effect = gdbu with patch("blivet.static_data.lvm_info.PVsInfo.cache", new_callable=PropertyMock) as mock_pvs_cache: diff --git a/tests/unit_tests/size_test.py b/tests/unit_tests/size_test.py index 5e4ea37d4..6fc3fa81f 100644 --- a/tests/unit_tests/size_test.py +++ b/tests/unit_tests/size_test.py @@ -26,10 +26,9 @@ import locale import os +import pickle import unittest -from six.moves import cPickle # pylint: disable=import-error - from decimal import Decimal # use libbytesize's translations for Size instances @@ -212,7 +211,7 @@ def test_leading_zero(self): def test_pickling(self): s = Size("10 MiB") - self.assertEqual(s, cPickle.loads(cPickle.dumps(s))) + self.assertEqual(s, pickle.loads(pickle.dumps(s))) def test_ensure_percent_reserve(self): s = Size("8 GiB") diff --git a/tests/unit_tests/util_test.py b/tests/unit_tests/util_test.py index aeef6e052..61e3c1d10 100644 --- a/tests/unit_tests/util_test.py +++ b/tests/unit_tests/util_test.py @@ -5,7 +5,6 @@ import mock import os -import six import tempfile import unittest from unittest.mock import patch @@ -152,12 +151,9 @@ def _test_dependency_guard_non_critical(self): def test_dependency_guard(self): guard = TestDependencyGuard() - if six.PY3: - with self.assertLogs("blivet", level="WARNING") as cm: - self.assertEqual(self._test_dependency_guard_non_critical(), None) - self.assertTrue(TestDependencyGuard.error_msg in "\n".join(cm.output)) - else: + with self.assertLogs("blivet", level="WARNING") as cm: self.assertEqual(self._test_dependency_guard_non_critical(), None) + self.assertTrue(TestDependencyGuard.error_msg in "\n".join(cm.output)) with self.assertRaises(errors.DependencyError): self._test_dependency_guard_critical() From 4581964640d6f55c47435cac1a8f391b9e12d431 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Thu, 1 Feb 2024 17:30:40 +0100 Subject: [PATCH 2/5] Remove util.stringize and unicodeize functions These are needed only for the Pytho 2/3 compatibility and we no longer support Python 2. unicodeize can be removed without replacement and the default str constructor can replace stringize. --- blivet/deviceaction.py | 5 +---- blivet/devices/device.py | 5 +---- blivet/partitioning.py | 12 +++------- blivet/util.py | 48 ---------------------------------------- blivet/zfcp.py | 6 +---- 5 files changed, 6 insertions(+), 70 deletions(-) diff --git a/blivet/deviceaction.py b/blivet/deviceaction.py index db9fd483a..b22e00c36 100644 --- a/blivet/deviceaction.py +++ b/blivet/deviceaction.py @@ -292,10 +292,7 @@ def _to_string(self): return s def __str__(self): - return util.stringize(self._to_string()) - - def __unicode__(self): - return util.unicodeize(self._to_string()) + return self._to_string() def requires(self, action): """ Return True if self requires action. """ diff --git a/blivet/devices/device.py b/blivet/devices/device.py index cd7f515ee..3ec571932 100644 --- a/blivet/devices/device.py +++ b/blivet/devices/device.py @@ -116,10 +116,7 @@ def _to_string(self): return s def __str__(self): - return util.stringize(self._to_string()) - - def __unicode__(self): - return util.unicodeize(self._to_string()) + return self._to_string() def _add_parent(self, parent): """ Called before adding a parent to this device. diff --git a/blivet/partitioning.py b/blivet/partitioning.py index 7fc2ed0f1..ec9918d41 100644 --- a/blivet/partitioning.py +++ b/blivet/partitioning.py @@ -35,7 +35,7 @@ from .devices import Device, PartitionDevice, device_path_to_name from .size import Size from .i18n import _ -from .util import stringize, unicodeize, compare +from .util import compare import logging log = logging.getLogger("blivet") @@ -1177,10 +1177,7 @@ def _to_string(self): return s def __str__(self): - return stringize(self._to_string()) - - def __unicode__(self): - return unicodeize(self._to_string()) + return self._to_string() def add_request(self, req): """ Add a request to this chunk. @@ -1413,10 +1410,7 @@ def _to_string(self): return s def __str__(self): - return stringize(self._to_string()) - - def __unicode__(self): - return unicodeize(self._to_string()) + return self._to_string() def add_request(self, req): """ Add a request to this chunk. diff --git a/blivet/util.py b/blivet/util.py index 9dfe684d7..ffe87c950 100644 --- a/blivet/util.py +++ b/blivet/util.py @@ -671,54 +671,6 @@ def canonicalize_UUID(a_uuid): """ return str(uuid.UUID(a_uuid.replace(':', ''))) -# Most Python 2/3 compatibility code equates python 2 str with python 3 bytes, -# but the equivalence that we actually need to avoid return type surprises is -# str/str. - - -def stringize(inputstr): - """ Convert strings to a format compatible with Python 2's str. - - :param str inputstr: the string to convert - - :returns: a string with the correct type - :rtype: str - - This method is for use in __str__ calls to ensure that they always - return a str. In Python 3, this method simply inputstr as a string. In - Python 2, it converts unicode into str. The returned str in python 2 is - encoded using utf-8. - """ - if six.PY2: - # pylint: disable=undefined-variable - if isinstance(inputstr, unicode): - inputstr = inputstr.encode('utf-8') - - return str(inputstr) - -# Like six.u, but without the part where it raises an exception on unicode -# objects - - -def unicodeize(inputstr): - """ Convert strings to a format compatible with Python 2's unicode. - - :param str inputstr: the string to convert - - :returns: a string with the correct type - :rtype: unicode - - This method is for use in __unicode__ calls to ensure that they always - return a unicode. This method does not handle non-ASCII characters - in str parameters, but non-ASCII characters in unicode parameters will - be correctly passed through. - """ - if six.PY2: - # pylint: disable=undefined-variable - return unicode(inputstr) - else: - return str(inputstr) - def compare(first, second): """ Compare two objects. diff --git a/blivet/zfcp.py b/blivet/zfcp.py index 080201172..002620745 100644 --- a/blivet/zfcp.py +++ b/blivet/zfcp.py @@ -26,7 +26,6 @@ from . import udev from . import util from .i18n import _ -from .util import stringize, unicodeize import gi gi.require_version("BlockDev", "3.0") @@ -112,10 +111,7 @@ def _to_string(self): return str(self.devnum) def __str__(self): - return stringize(self._to_string()) - - def __unicode__(self): - return unicodeize(self._to_string()) + return self._to_string() def _free_device(self): """Remove the device from the I/O ignore list to make it visible to the system. From ad73c8748e9eec3d721afba5c8d631aedb2605d6 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Thu, 1 Feb 2024 15:17:25 +0100 Subject: [PATCH 3/5] tests: Do not try to import mock and patch from mock We no longer support older versions of Python so we can import everything only from the unittest module. --- tests/storage_tests/devices_test/misc_test.py | 5 +-- .../devices_test/partition_test.py | 5 +-- tests/storage_tests/partitioning_test.py | 6 +--- .../unsupported_disklabel_test.py | 6 +--- tests/unit_tests/action_test.py | 6 +--- tests/unit_tests/blivettestcase.py | 5 +-- tests/unit_tests/dbus_test.py | 6 +--- tests/unit_tests/devicefactory_test.py | 10 ++---- tests/unit_tests/devicelibs_test/disk_test.py | 6 +--- tests/unit_tests/devicelibs_test/edd_test.py | 13 +++---- tests/unit_tests/devices_test/btrfs_test.py | 6 +--- .../devices_test/device_dependencies_test.py | 9 ++--- .../devices_test/device_methods_test.py | 6 +--- .../devices_test/device_names_test.py | 6 +--- .../devices_test/device_properties_test.py | 6 +--- tests/unit_tests/devices_test/disk_test.py | 5 +-- tests/unit_tests/devices_test/lvm_test.py | 6 +--- tests/unit_tests/devices_test/md_test.py | 6 +--- .../unit_tests/devices_test/partition_test.py | 6 +--- tests/unit_tests/devices_test/stratis_test.py | 6 +--- tests/unit_tests/devicetree_test.py | 6 +--- tests/unit_tests/events_test.py | 6 +--- .../formats_tests/disklabel_test.py | 36 ++++++++----------- tests/unit_tests/formats_tests/luks_test.py | 6 +--- tests/unit_tests/formats_tests/lvmpv_test.py | 8 ++--- .../unit_tests/formats_tests/methods_test.py | 6 +--- .../unit_tests/formats_tests/selinux_test.py | 6 +--- tests/unit_tests/fstab_test.py | 8 ++--- tests/unit_tests/gpt_test.py | 6 +--- tests/unit_tests/misc_test.py | 6 +--- tests/unit_tests/nvme_test.py | 6 +--- tests/unit_tests/populator_test.py | 8 ++--- tests/unit_tests/tags_test.py | 6 +--- tests/unit_tests/udev_test.py | 6 +--- tests/unit_tests/util_test.py | 6 +--- 35 files changed, 60 insertions(+), 196 deletions(-) diff --git a/tests/storage_tests/devices_test/misc_test.py b/tests/storage_tests/devices_test/misc_test.py index 5791fc2ad..575cd3eea 100644 --- a/tests/storage_tests/devices_test/misc_test.py +++ b/tests/storage_tests/devices_test/misc_test.py @@ -1,10 +1,7 @@ import os import unittest -try: - from unittest.mock import patch -except ImportError: - from mock import patch +from unittest.mock import patch from ..storagetestcase import StorageTestCase diff --git a/tests/storage_tests/devices_test/partition_test.py b/tests/storage_tests/devices_test/partition_test.py index 2bff60659..451e9c28b 100644 --- a/tests/storage_tests/devices_test/partition_test.py +++ b/tests/storage_tests/devices_test/partition_test.py @@ -5,10 +5,7 @@ from uuid import UUID import parted -try: - from unittest.mock import patch -except ImportError: - from mock import patch +from unittest.mock import patch from blivet.devices import DiskFile from blivet.devices import PartitionDevice diff --git a/tests/storage_tests/partitioning_test.py b/tests/storage_tests/partitioning_test.py index 1be5046fa..746d8ec71 100644 --- a/tests/storage_tests/partitioning_test.py +++ b/tests/storage_tests/partitioning_test.py @@ -1,9 +1,5 @@ -try: - from unittest.mock import patch, Mock -except ImportError: - from mock import patch, Mock - import unittest +from unittest.mock import patch, Mock import parted diff --git a/tests/storage_tests/unsupported_disklabel_test.py b/tests/storage_tests/unsupported_disklabel_test.py index 1737af261..5fde19a18 100644 --- a/tests/storage_tests/unsupported_disklabel_test.py +++ b/tests/storage_tests/unsupported_disklabel_test.py @@ -1,9 +1,5 @@ -try: - from unittest.mock import patch, sentinel, DEFAULT -except ImportError: - from mock import patch, sentinel, DEFAULT - import unittest +from unittest.mock import patch, sentinel, DEFAULT from blivet.actionlist import ActionList from blivet.deviceaction import ActionDestroyFormat diff --git a/tests/unit_tests/action_test.py b/tests/unit_tests/action_test.py index 013b19896..8aefad2f0 100644 --- a/tests/unit_tests/action_test.py +++ b/tests/unit_tests/action_test.py @@ -1,9 +1,5 @@ import unittest - -try: - from unittest.mock import Mock, patch -except ImportError: - from mock import Mock, patch +from unittest.mock import Mock, patch from .blivettestcase import BlivetTestCase import blivet diff --git a/tests/unit_tests/blivettestcase.py b/tests/unit_tests/blivettestcase.py index 3df5768e5..80b17efaf 100644 --- a/tests/unit_tests/blivettestcase.py +++ b/tests/unit_tests/blivettestcase.py @@ -1,9 +1,6 @@ import unittest -try: - from unittest.mock import Mock, patch -except ImportError: - from mock import Mock, patch +from unittest.mock import Mock, patch import parted diff --git a/tests/unit_tests/dbus_test.py b/tests/unit_tests/dbus_test.py index 29636c593..7e1d802c9 100644 --- a/tests/unit_tests/dbus_test.py +++ b/tests/unit_tests/dbus_test.py @@ -1,10 +1,6 @@ import random -try: - from unittest.mock import patch, Mock, call -except ImportError: - from mock import patch, Mock, call - +from unittest.mock import patch, Mock, call from unittest import TestCase import dbus diff --git a/tests/unit_tests/devicefactory_test.py b/tests/unit_tests/devicefactory_test.py index 9c1906845..0a5e6a839 100644 --- a/tests/unit_tests/devicefactory_test.py +++ b/tests/unit_tests/devicefactory_test.py @@ -1,12 +1,8 @@ - -import unittest -from decimal import Decimal import os +import unittest +from unittest.mock import patch -try: - from unittest.mock import patch -except ImportError: - from mock import patch +from decimal import Decimal import blivet diff --git a/tests/unit_tests/devicelibs_test/disk_test.py b/tests/unit_tests/devicelibs_test/disk_test.py index b55f4e909..64d6e9e98 100644 --- a/tests/unit_tests/devicelibs_test/disk_test.py +++ b/tests/unit_tests/devicelibs_test/disk_test.py @@ -1,10 +1,6 @@ # pylint: skip-file -try: - from unittest.mock import Mock, patch, sentinel -except ImportError: - from mock import Mock, patch, sentinel - import unittest +from unittest.mock import Mock, patch, sentinel from blivet.devicelibs import disk as disklib from blivet.size import Size diff --git a/tests/unit_tests/devicelibs_test/edd_test.py b/tests/unit_tests/devicelibs_test/edd_test.py index 0db1fd16e..d76cbc73c 100644 --- a/tests/unit_tests/devicelibs_test/edd_test.py +++ b/tests/unit_tests/devicelibs_test/edd_test.py @@ -1,12 +1,9 @@ -try: - from unittest import mock -except ImportError: - import mock - -import unittest -import os -import logging import copy +import logging +import os +import unittest + +from unittest import mock from blivet import arch from blivet.devicelibs import edd diff --git a/tests/unit_tests/devices_test/btrfs_test.py b/tests/unit_tests/devices_test/btrfs_test.py index fe6692c0a..71fe639d6 100644 --- a/tests/unit_tests/devices_test/btrfs_test.py +++ b/tests/unit_tests/devices_test/btrfs_test.py @@ -1,9 +1,5 @@ import unittest - -try: - from unittest.mock import patch -except ImportError: - from mock import patch +from unittest.mock import patch import blivet diff --git a/tests/unit_tests/devices_test/device_dependencies_test.py b/tests/unit_tests/devices_test/device_dependencies_test.py index d7adbabcf..6e7c8df51 100644 --- a/tests/unit_tests/devices_test/device_dependencies_test.py +++ b/tests/unit_tests/devices_test/device_dependencies_test.py @@ -1,10 +1,7 @@ -try: - from unittest.mock import patch, PropertyMock -except ImportError: - from mock import patch, PropertyMock - -import unittest import os +import unittest +from unittest.mock import patch, PropertyMock + import blivet import gi gi.require_version("BlockDev", "3.0") diff --git a/tests/unit_tests/devices_test/device_methods_test.py b/tests/unit_tests/devices_test/device_methods_test.py index 4470f51dc..093c0066f 100644 --- a/tests/unit_tests/devices_test/device_methods_test.py +++ b/tests/unit_tests/devices_test/device_methods_test.py @@ -1,9 +1,5 @@ import unittest - -try: - from unittest.mock import patch, Mock, PropertyMock -except ImportError: - from mock import patch, PropertyMock +from unittest.mock import patch, Mock, PropertyMock from blivet.devices import StorageDevice from blivet.devices import DiskDevice, PartitionDevice diff --git a/tests/unit_tests/devices_test/device_names_test.py b/tests/unit_tests/devices_test/device_names_test.py index 7a49c5050..70bd2f83e 100644 --- a/tests/unit_tests/devices_test/device_names_test.py +++ b/tests/unit_tests/devices_test/device_names_test.py @@ -1,10 +1,6 @@ # vim:set fileencoding=utf-8 -try: - from unittest.mock import patch -except ImportError: - from mock import patch - import unittest +from unittest.mock import patch from blivet.devices import LVMVolumeGroupDevice from blivet.devices import LVMLogicalVolumeDevice diff --git a/tests/unit_tests/devices_test/device_properties_test.py b/tests/unit_tests/devices_test/device_properties_test.py index 60f9e17fa..8a16bc316 100644 --- a/tests/unit_tests/devices_test/device_properties_test.py +++ b/tests/unit_tests/devices_test/device_properties_test.py @@ -1,15 +1,11 @@ import unittest +from unittest.mock import patch, Mock import gi gi.require_version("BlockDev", "3.0") from gi.repository import BlockDev as blockdev -try: - from unittest.mock import patch, Mock -except ImportError: - from mock import patch, Mock - import blivet from blivet.errors import BTRFSValueError diff --git a/tests/unit_tests/devices_test/disk_test.py b/tests/unit_tests/devices_test/disk_test.py index cc8454e14..7ee015a45 100644 --- a/tests/unit_tests/devices_test/disk_test.py +++ b/tests/unit_tests/devices_test/disk_test.py @@ -1,9 +1,6 @@ # pylint: skip-file -try: - from unittest.mock import patch -except ImportError: - from mock import patch import unittest +from unittest.mock import patch from blivet.devices import DiskDevice from blivet.devicelibs import disk as disklib diff --git a/tests/unit_tests/devices_test/lvm_test.py b/tests/unit_tests/devices_test/lvm_test.py index c8ee902c5..680c41a85 100644 --- a/tests/unit_tests/devices_test/lvm_test.py +++ b/tests/unit_tests/devices_test/lvm_test.py @@ -1,9 +1,5 @@ -try: - from unittest.mock import patch, PropertyMock -except ImportError: - from mock import patch, PropertyMock - import unittest +from unittest.mock import patch, PropertyMock import blivet diff --git a/tests/unit_tests/devices_test/md_test.py b/tests/unit_tests/devices_test/md_test.py index a522b0d19..56e95b340 100644 --- a/tests/unit_tests/devices_test/md_test.py +++ b/tests/unit_tests/devices_test/md_test.py @@ -1,9 +1,5 @@ import unittest - -try: - from unittest.mock import patch -except ImportError: - from mock import patch +from unittest.mock import patch import blivet diff --git a/tests/unit_tests/devices_test/partition_test.py b/tests/unit_tests/devices_test/partition_test.py index b17da9dc3..0031e58e2 100644 --- a/tests/unit_tests/devices_test/partition_test.py +++ b/tests/unit_tests/devices_test/partition_test.py @@ -1,10 +1,6 @@ from collections import namedtuple import unittest - -try: - from unittest.mock import patch, Mock -except ImportError: - from mock import patch, Mock +from unittest.mock import patch, Mock from blivet.devices import PartitionDevice from blivet.devices import StorageDevice diff --git a/tests/unit_tests/devices_test/stratis_test.py b/tests/unit_tests/devices_test/stratis_test.py index 35fb6b049..47b1a4365 100644 --- a/tests/unit_tests/devices_test/stratis_test.py +++ b/tests/unit_tests/devices_test/stratis_test.py @@ -1,9 +1,5 @@ import unittest - -try: - from unittest.mock import patch -except ImportError: - from mock import patch +from unittest.mock import patch import blivet diff --git a/tests/unit_tests/devicetree_test.py b/tests/unit_tests/devicetree_test.py index 0eeb93844..b67d3416e 100644 --- a/tests/unit_tests/devicetree_test.py +++ b/tests/unit_tests/devicetree_test.py @@ -1,9 +1,5 @@ -try: - from unittest.mock import patch, Mock, PropertyMock, sentinel -except ImportError: - from mock import patch, Mock, PropertyMock, sentinel - import unittest +from unittest.mock import patch, Mock, PropertyMock, sentinel from blivet.actionlist import ActionList from blivet.errors import DeviceTreeError, DuplicateUUIDError, InvalidMultideviceSelection diff --git a/tests/unit_tests/events_test.py b/tests/unit_tests/events_test.py index 22666f6dc..27d3b3728 100644 --- a/tests/unit_tests/events_test.py +++ b/tests/unit_tests/events_test.py @@ -1,10 +1,6 @@ -try: - from unittest.mock import patch, Mock -except ImportError: - from mock import patch, Mock - import time from unittest import TestCase +from unittest.mock import patch, Mock from blivet.events.manager import Event, EventManager diff --git a/tests/unit_tests/formats_tests/disklabel_test.py b/tests/unit_tests/formats_tests/disklabel_test.py index a7f5e7779..9f6e4542e 100644 --- a/tests/unit_tests/formats_tests/disklabel_test.py +++ b/tests/unit_tests/formats_tests/disklabel_test.py @@ -1,24 +1,18 @@ -try: - from unittest import mock -except ImportError: - import mock - import parted import unittest +from unittest.mock import Mock, PropertyMock, patch import blivet from blivet.size import Size -patch = mock.patch - class DiskLabelTestCase(unittest.TestCase): @patch("blivet.formats.disklabel.DiskLabel.fresh_parted_disk", None) def test_get_alignment(self): dl = blivet.formats.disklabel.DiskLabel() - dl._parted_disk = mock.Mock() - dl._parted_device = mock.Mock() + dl._parted_disk = Mock() + dl._parted_device = Mock() dl._parted_device.sectorSize = 512 # 512 byte grain sze @@ -111,11 +105,11 @@ def test_platform_label_types(self, arch): def test_label_type_size_check(self): dl = blivet.formats.disklabel.DiskLabel() - dl._parted_disk = mock.Mock() - dl._parted_device = mock.Mock() + dl._parted_disk = Mock() + dl._parted_device = Mock() with patch("blivet.formats.disklabel.parted") as patched_parted: - patched_parted.freshDisk.return_value = mock.Mock(name="parted.Disk", maxPartitionStartSector=10) + patched_parted.freshDisk.return_value = Mock(name="parted.Disk", maxPartitionStartSector=10) dl._parted_device.length = 100 self.assertEqual(dl._label_type_size_check("foo"), False) @@ -125,7 +119,7 @@ def test_label_type_size_check(self): dl._parted_device.length = 9 self.assertEqual(dl._label_type_size_check("foo"), True) - with patch.object(blivet.formats.disklabel.DiskLabel, "parted_device", new=mock.PropertyMock(return_value=None)): + with patch.object(blivet.formats.disklabel.DiskLabel, "parted_device", new=PropertyMock(return_value=None)): # no parted device -> no passing size check self.assertEqual(dl._label_type_size_check("msdos"), False) @@ -138,8 +132,8 @@ def test_best_label_type(self, arch): 4. is dasd for non-fba dasd on S390 """ dl = blivet.formats.disklabel.DiskLabel() - dl._parted_disk = mock.Mock() - dl._parted_device = mock.Mock() + dl._parted_disk = Mock() + dl._parted_device = Mock() dl._device = "labeltypefakedev" arch.is_s390.return_value = False @@ -149,7 +143,7 @@ def test_best_label_type(self, arch): arch.is_pmac.return_value = False arch.is_x86.return_value = False - with mock.patch.object(dl, '_label_type_size_check') as size_check: + with patch.object(dl, '_label_type_size_check') as size_check: # size check passes for first type ("msdos") size_check.return_value = True self.assertEqual(dl._get_best_label_type(), "msdos") @@ -163,23 +157,23 @@ def test_best_label_type(self, arch): self.assertEqual(dl._get_best_label_type(), "gpt") arch.is_pmac.return_value = True - with mock.patch.object(dl, '_label_type_size_check') as size_check: + with patch.object(dl, '_label_type_size_check') as size_check: size_check.return_value = True self.assertEqual(dl._get_best_label_type(), "mac") arch.is_pmac.return_value = False arch.is_efi.return_value = True - with mock.patch.object(dl, '_label_type_size_check') as size_check: + with patch.object(dl, '_label_type_size_check') as size_check: size_check.return_value = True self.assertEqual(dl._get_best_label_type(), "gpt") arch.is_efi.return_value = False arch.is_s390.return_value = True - with mock.patch('blivet.util.detect_virt') as virt: + with patch('blivet.util.detect_virt') as virt: virt.return_value = False - with mock.patch.object(dl, '_label_type_size_check') as size_check: + with patch.object(dl, '_label_type_size_check') as size_check: size_check.return_value = True - with mock.patch("blivet.formats.disklabel.blockdev.s390") as _s390: + with patch("blivet.formats.disklabel.blockdev.s390") as _s390: _s390.dasd_is_fba.return_value = False self.assertEqual(dl._get_best_label_type(), "msdos") diff --git a/tests/unit_tests/formats_tests/luks_test.py b/tests/unit_tests/formats_tests/luks_test.py index 1dd597be3..d4322f118 100644 --- a/tests/unit_tests/formats_tests/luks_test.py +++ b/tests/unit_tests/formats_tests/luks_test.py @@ -1,9 +1,5 @@ -try: - from unittest.mock import patch -except ImportError: - from mock import patch - import unittest +from unittest.mock import patch from blivet.formats.luks import LUKS from blivet.size import Size diff --git a/tests/unit_tests/formats_tests/lvmpv_test.py b/tests/unit_tests/formats_tests/lvmpv_test.py index 2d22d2f1d..8d410f4fd 100644 --- a/tests/unit_tests/formats_tests/lvmpv_test.py +++ b/tests/unit_tests/formats_tests/lvmpv_test.py @@ -1,12 +1,8 @@ -try: - from unittest.mock import patch -except ImportError: - from mock import patch +import unittest +from unittest.mock import patch from contextlib import contextmanager -import unittest - from blivet.formats.lvmpv import LVMPhysicalVolume from blivet.flags import flags diff --git a/tests/unit_tests/formats_tests/methods_test.py b/tests/unit_tests/formats_tests/methods_test.py index 8a9b84603..f40486734 100644 --- a/tests/unit_tests/formats_tests/methods_test.py +++ b/tests/unit_tests/formats_tests/methods_test.py @@ -1,9 +1,5 @@ -try: - from unittest.mock import patch, sentinel, PropertyMock -except ImportError: - from mock import patch, sentinel, PropertyMock - import unittest +from unittest.mock import patch, sentinel, PropertyMock from blivet.errors import DeviceFormatError from blivet.formats import DeviceFormat diff --git a/tests/unit_tests/formats_tests/selinux_test.py b/tests/unit_tests/formats_tests/selinux_test.py index 98883e37a..484e745a4 100644 --- a/tests/unit_tests/formats_tests/selinux_test.py +++ b/tests/unit_tests/formats_tests/selinux_test.py @@ -1,12 +1,8 @@ # pylint: disable=unused-import import os -try: - from unittest.mock import patch, ANY -except ImportError: - from mock import patch, ANY - import unittest +from unittest.mock import patch, ANY import blivet import blivet.formats.fs as fs diff --git a/tests/unit_tests/fstab_test.py b/tests/unit_tests/fstab_test.py index 8e8f388aa..ab959a346 100644 --- a/tests/unit_tests/fstab_test.py +++ b/tests/unit_tests/fstab_test.py @@ -1,11 +1,7 @@ -try: - from unittest.mock import Mock -except ImportError: - from mock import Mock - +import copy import os import unittest -import copy +from unittest.mock import Mock from blivet.fstab import FSTabManager, FSTabEntry from blivet.devices import DiskDevice diff --git a/tests/unit_tests/gpt_test.py b/tests/unit_tests/gpt_test.py index 753b4913a..199ccc999 100644 --- a/tests/unit_tests/gpt_test.py +++ b/tests/unit_tests/gpt_test.py @@ -20,11 +20,7 @@ import unittest from uuid import UUID - -try: - from unittest import mock -except ImportError: - import mock +from unittest import mock from blivet.devicelibs import gpt from blivet.errors import GPTVolUUIDError diff --git a/tests/unit_tests/misc_test.py b/tests/unit_tests/misc_test.py index 9bf5f487d..0d3b7dd27 100644 --- a/tests/unit_tests/misc_test.py +++ b/tests/unit_tests/misc_test.py @@ -1,9 +1,5 @@ import unittest - -try: - from unittest.mock import patch, Mock -except ImportError: - from mock import patch, Mock +from unittest.mock import patch, Mock import blivet diff --git a/tests/unit_tests/nvme_test.py b/tests/unit_tests/nvme_test.py index cb948687f..bbe4f1daf 100644 --- a/tests/unit_tests/nvme_test.py +++ b/tests/unit_tests/nvme_test.py @@ -1,9 +1,5 @@ import unittest - -try: - from unittest.mock import patch -except ImportError: - from mock import patch +from unittest.mock import patch from blivet.nvme import nvme diff --git a/tests/unit_tests/populator_test.py b/tests/unit_tests/populator_test.py index a4fea735d..d9b129521 100644 --- a/tests/unit_tests/populator_test.py +++ b/tests/unit_tests/populator_test.py @@ -1,11 +1,7 @@ -try: - from unittest.mock import call, patch, sentinel, Mock, PropertyMock -except ImportError: - from mock import call, patch, sentinel, Mock, PropertyMock - -import gi import unittest +from unittest.mock import call, patch, sentinel, Mock, PropertyMock +import gi gi.require_version("BlockDev", "3.0") from gi.repository import BlockDev as blockdev diff --git a/tests/unit_tests/tags_test.py b/tests/unit_tests/tags_test.py index 15fa2a407..126658c33 100644 --- a/tests/unit_tests/tags_test.py +++ b/tests/unit_tests/tags_test.py @@ -1,9 +1,5 @@ -try: - from unittest.mock import patch -except ImportError: - from mock import patch - import unittest +from unittest.mock import patch from blivet.devices import DiskDevice, FcoeDiskDevice, iScsiDiskDevice, MultipathDevice, StorageDevice, ZFCPDiskDevice from blivet.devices.lib import Tags diff --git a/tests/unit_tests/udev_test.py b/tests/unit_tests/udev_test.py index b208efa86..857b3a06f 100644 --- a/tests/unit_tests/udev_test.py +++ b/tests/unit_tests/udev_test.py @@ -1,10 +1,6 @@ import unittest - -try: - from unittest import mock -except ImportError: - import mock +from unittest import mock from .udev_data import raid_data diff --git a/tests/unit_tests/util_test.py b/tests/unit_tests/util_test.py index 61e3c1d10..3496b29b2 100644 --- a/tests/unit_tests/util_test.py +++ b/tests/unit_tests/util_test.py @@ -1,12 +1,8 @@ # pylint: skip-file -try: - from unittest import mock -except ImportError: - import mock - import os import tempfile import unittest +from unittest import mock from unittest.mock import patch from decimal import Decimal from textwrap import dedent From b4975176558dffea334bcc63c752a1643e968c3a Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Thu, 1 Feb 2024 15:23:20 +0100 Subject: [PATCH 4/5] tests: Do not ignore entire test files in pylint --- tests/unit_tests/devicelibs_test/disk_test.py | 3 +-- tests/unit_tests/devices_test/disk_test.py | 1 - tests/unit_tests/util_test.py | 4 ++-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/unit_tests/devicelibs_test/disk_test.py b/tests/unit_tests/devicelibs_test/disk_test.py index 64d6e9e98..8a57c77e2 100644 --- a/tests/unit_tests/devicelibs_test/disk_test.py +++ b/tests/unit_tests/devicelibs_test/disk_test.py @@ -1,4 +1,3 @@ -# pylint: skip-file import unittest from unittest.mock import Mock, patch, sentinel @@ -106,7 +105,7 @@ def system_by_id(sys_id): "volume_raid_info.side_effect": client_volume_raid_info}) _lsm.Client = client_mock disklib.update_volume_info() - for (i, lvol) in enumerate(_client_volumes): + for (_i, lvol) in enumerate(_client_volumes): bvol = disklib.volumes[lvol.nodes[0]] system = system_by_id(lvol.system_id) self.assertEqual(bvol.system, system.name) diff --git a/tests/unit_tests/devices_test/disk_test.py b/tests/unit_tests/devices_test/disk_test.py index 7ee015a45..e414aeb4c 100644 --- a/tests/unit_tests/devices_test/disk_test.py +++ b/tests/unit_tests/devices_test/disk_test.py @@ -1,4 +1,3 @@ -# pylint: skip-file import unittest from unittest.mock import patch diff --git a/tests/unit_tests/util_test.py b/tests/unit_tests/util_test.py index 3496b29b2..d4bddcedc 100644 --- a/tests/unit_tests/util_test.py +++ b/tests/unit_tests/util_test.py @@ -123,7 +123,7 @@ def test_requires_property(self): self.assertEqual(t.good_news, "Everything okay!") with self.assertRaises(ValueError): - t.bad_news + t.bad_news # pylint: disable=pointless-statement class TestDependencyGuard(util.DependencyGuard): @@ -146,7 +146,7 @@ def _test_dependency_guard_non_critical(self): return True def test_dependency_guard(self): - guard = TestDependencyGuard() + _guard = TestDependencyGuard() with self.assertLogs("blivet", level="WARNING") as cm: self.assertEqual(self._test_dependency_guard_non_critical(), None) self.assertTrue(TestDependencyGuard.error_msg in "\n".join(cm.output)) From d212b7bc99fb1c5f9fb52ffe17c6d028deb2e526 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Thu, 1 Feb 2024 17:15:33 +0100 Subject: [PATCH 5/5] Remove vim formatting comments --- blivet/fcoe.py | 2 -- blivet/iscsi.py | 2 -- blivet/zfcp.py | 2 -- tests/storage_tests/devices_test/partition_test.py | 2 -- tests/unit_tests/devices_test/device_names_test.py | 1 - tests/unit_tests/devices_test/device_packages_test.py | 2 -- tests/unit_tests/devices_test/network_test.py | 2 -- 7 files changed, 13 deletions(-) diff --git a/blivet/fcoe.py b/blivet/fcoe.py index 371f8c201..00a425d5a 100644 --- a/blivet/fcoe.py +++ b/blivet/fcoe.py @@ -244,5 +244,3 @@ def write_nic_fcoe_cfg(self, nic, dcb=True, auto_vlan=True, enable=True, mode=No # Create FCoE singleton fcoe = FCoE() - -# vim:tw=78:ts=4:et:sw=4 diff --git a/blivet/iscsi.py b/blivet/iscsi.py index b63468e9b..95674665b 100644 --- a/blivet/iscsi.py +++ b/blivet/iscsi.py @@ -621,5 +621,3 @@ def get_node_disks(self, node, storage): # Create iscsi singleton iscsi = iSCSI() """ An instance of :class:`iSCSI` """ - -# vim:tw=78:ts=4:et:sw=4 diff --git a/blivet/zfcp.py b/blivet/zfcp.py index 002620745..a2b7facb2 100644 --- a/blivet/zfcp.py +++ b/blivet/zfcp.py @@ -562,5 +562,3 @@ def write(self, root): # Create ZFCP singleton zfcp = zFCP() - -# vim:tw=78:ts=4:et:sw=4 diff --git a/tests/storage_tests/devices_test/partition_test.py b/tests/storage_tests/devices_test/partition_test.py index 451e9c28b..73da87b43 100644 --- a/tests/storage_tests/devices_test/partition_test.py +++ b/tests/storage_tests/devices_test/partition_test.py @@ -1,5 +1,3 @@ -# vim:set fileencoding=utf-8 - import os import unittest from uuid import UUID diff --git a/tests/unit_tests/devices_test/device_names_test.py b/tests/unit_tests/devices_test/device_names_test.py index 70bd2f83e..97de97bf7 100644 --- a/tests/unit_tests/devices_test/device_names_test.py +++ b/tests/unit_tests/devices_test/device_names_test.py @@ -1,4 +1,3 @@ -# vim:set fileencoding=utf-8 import unittest from unittest.mock import patch diff --git a/tests/unit_tests/devices_test/device_packages_test.py b/tests/unit_tests/devices_test/device_packages_test.py index ab708d126..41d0dd7f9 100644 --- a/tests/unit_tests/devices_test/device_packages_test.py +++ b/tests/unit_tests/devices_test/device_packages_test.py @@ -1,5 +1,3 @@ -# vim:set fileencoding=utf-8 - import unittest from blivet.devices import DiskDevice diff --git a/tests/unit_tests/devices_test/network_test.py b/tests/unit_tests/devices_test/network_test.py index 9fca6c120..0453848c1 100644 --- a/tests/unit_tests/devices_test/network_test.py +++ b/tests/unit_tests/devices_test/network_test.py @@ -1,5 +1,3 @@ -# vim:set fileencoding=utf-8 - import unittest from blivet.devices import NetworkStorageDevice