From 78f0874c644d1e8daaa33376a1ac22449bf4d7b4 Mon Sep 17 00:00:00 2001 From: Giulio Calacoci Date: Tue, 29 Oct 2024 18:24:29 +0000 Subject: [PATCH] Run isort on code to remove unused imports and blank lines Execute isort on the whole projet cleaning up and sorting imports in both tests and code. References: bar-429 Signed-off-by: Giulio Calacoci --- barman/annotations.py | 1 - barman/backup.py | 16 +++---- barman/backup_executor.py | 6 +-- barman/backup_manifest.py | 2 +- barman/cli.py | 42 ++++++++----------- barman/clients/cloud_backup.py | 17 +++++--- barman/clients/cloud_backup_delete.py | 6 +-- barman/clients/cloud_backup_keep.py | 2 +- barman/clients/cloud_backup_list.py | 2 +- barman/clients/cloud_backup_show.py | 2 +- barman/clients/cloud_check_wal_archive.py | 8 ++-- barman/clients/cloud_cli.py | 1 - barman/clients/cloud_restore.py | 6 +-- barman/clients/cloud_walarchive.py | 6 +-- barman/clients/cloud_walrestore.py | 11 +++-- barman/cloud.py | 13 +++--- barman/cloud_providers/aws_s3.py | 7 ++-- barman/cloud_providers/azure_blob_storage.py | 7 ++-- .../cloud_providers/google_cloud_storage.py | 5 +-- barman/compression.py | 5 ++- barman/config.py | 2 +- barman/diagnose.py | 3 +- barman/fs.py | 2 +- barman/lockfile.py | 2 +- barman/output.py | 2 +- barman/postgres.py | 26 +++++++----- barman/recovery_executor.py | 21 +++++----- barman/server.py | 20 +++++---- barman/storage/file_manager.py | 1 + barman/storage/local_file_manager.py | 1 + barman/utils.py | 8 ++-- barman/wal_archiver.py | 2 +- barman/xlog.py | 2 +- scripts/prepare_snapshot_recovery.py | 12 +++--- tests/conftest.py | 3 +- tests/storage/test_local_file_manager.py | 1 + tests/test_annotations.py | 5 ++- tests/test_backup.py | 12 +++--- tests/test_backup_strategy.py | 12 +++--- tests/test_barman_cloud_backup.py | 3 +- tests/test_barman_cloud_backup_delete.py | 2 +- tests/test_barman_cloud_backup_list.py | 1 + tests/test_barman_cloud_backup_show.py | 3 +- tests/test_barman_cloud_restore.py | 2 +- tests/test_barman_cloud_wal_archive.py | 3 +- tests/test_cli.py | 16 +++---- tests/test_cloud.py | 29 +++++++------ tests/test_cloud_snapshot_interface.py | 16 +++---- tests/test_command_wrappers.py | 2 +- tests/test_compressor.py | 29 ++++++------- tests/test_config.py | 8 ++-- tests/test_copy_controller.py | 6 +-- tests/test_executor.py | 10 ++--- tests/test_fs.py | 3 +- tests/test_infofile.py | 10 ++--- tests/test_lockfile.py | 2 +- tests/test_output.py | 9 ++-- tests/test_postgres.py | 20 ++++----- tests/test_recovery_executor.py | 16 +++---- tests/test_retention_policies.py | 2 +- tests/test_server.py | 8 ++-- tests/test_sync.py | 4 +- tests/test_utils.py | 9 ++-- tests/test_wal_archiver.py | 12 ++++-- tests/testing_helpers.py | 9 +++- 65 files changed, 281 insertions(+), 255 deletions(-) diff --git a/barman/annotations.py b/barman/annotations.py index 4eb39e9e8..ce16f14e0 100644 --- a/barman/annotations.py +++ b/barman/annotations.py @@ -19,7 +19,6 @@ import errno import io import os - from abc import ABCMeta, abstractmethod from barman.exceptions import ArchivalBackupException diff --git a/barman/backup.py b/barman/backup.py index bbbf4a604..dd9a29653 100644 --- a/barman/backup.py +++ b/barman/backup.py @@ -37,19 +37,21 @@ PassiveBackupExecutor, PostgresBackupExecutor, RsyncBackupExecutor, - SnapshotBackupExecutor, + SnapshotBackupExecutor ) +from barman.backup_manifest import BackupManifest from barman.cloud_providers import get_snapshot_interface_from_backup_info +from barman.command_wrappers import PgVerifyBackup from barman.compression import CompressionManager from barman.config import BackupOptions from barman.exceptions import ( AbortedRetryHookScript, BackupException, + CommandFailedException, CompressionIncompatibility, LockFileBusy, SshCommandException, - UnknownBackupIdException, - CommandFailedException, + UnknownBackupIdException ) from barman.fs import unix_command_factory from barman.hooks import HookScriptRunner, RetryHookScriptRunner @@ -57,18 +59,16 @@ from barman.lockfile import ServerBackupIdLock, ServerBackupSyncLock from barman.recovery_executor import recovery_executor_factory from barman.remote_status import RemoteStatusMixin +from barman.storage.local_file_manager import LocalFileManager from barman.utils import ( + SHA256, force_str, fsync_dir, fsync_file, get_backup_info_from_name, human_readable_timedelta, - pretty_size, - SHA256, + pretty_size ) -from barman.command_wrappers import PgVerifyBackup -from barman.storage.local_file_manager import LocalFileManager -from barman.backup_manifest import BackupManifest _logger = logging.getLogger(__name__) diff --git a/barman/backup_executor.py b/barman/backup_executor.py index 96318552c..03e8fea95 100644 --- a/barman/backup_executor.py +++ b/barman/backup_executor.py @@ -49,13 +49,13 @@ BackupException, CommandFailedException, DataTransferFailure, + FileNotFoundException, FsOperationFailed, PostgresConnectionError, PostgresConnectionLost, PostgresIsInRecovery, SnapshotBackupException, - SshCommandException, - FileNotFoundException, + SshCommandException ) from barman.fs import UnixLocalCommand, UnixRemoteCommand, unix_command_factory from barman.infofile import BackupInfo @@ -67,7 +67,7 @@ human_readable_timedelta, mkpath, total_seconds, - with_metaclass, + with_metaclass ) _logger = logging.getLogger(__name__) diff --git a/barman/backup_manifest.py b/barman/backup_manifest.py index 2bf154d37..8629250a2 100644 --- a/barman/backup_manifest.py +++ b/barman/backup_manifest.py @@ -16,8 +16,8 @@ # You should have received a copy of the GNU General Public License # along with Barman. If not, see . -import os import json +import os from barman.exceptions import BackupManifestException diff --git a/barman/cli.py b/barman/cli.py index 83d6f2e9f..ac381ed3b 100644 --- a/barman/cli.py +++ b/barman/cli.py @@ -25,45 +25,35 @@ import logging import os import sys -from argparse import ( - SUPPRESS, - ArgumentTypeError, - ArgumentParser, - HelpFormatter, -) - -from barman.lockfile import ConfigUpdateLock - -if sys.version_info.major < 3: - from argparse import Action, _SubParsersAction, _ActionsContainer -try: - import argcomplete -except ImportError: - argcomplete = None +from argparse import SUPPRESS, ArgumentParser, ArgumentTypeError, HelpFormatter from collections import OrderedDict from contextlib import closing - import barman.config import barman.diagnose import barman.utils from barman import output from barman.annotations import KeepManager +from barman.backup_manifest import BackupManifest from barman.config import ( ConfigChangesProcessor, RecoveryOptions, - parse_staging_path, + parse_staging_path ) from barman.exceptions import ( BadXlogSegmentName, LockFileBusy, RecoveryException, SyncError, - WalArchiveContentError, + WalArchiveContentError ) from barman.infofile import BackupInfo, WalFileInfo +from barman.lockfile import ConfigUpdateLock from barman.server import Server +from barman.storage.local_file_manager import LocalFileManager from barman.utils import ( + RESERVED_BACKUP_IDS, + SHA256, BarmanEncoder, check_backup_name, check_non_negative, @@ -72,15 +62,19 @@ configure_logging, drop_privileges, force_str, - get_log_levels, get_backup_id_using_shortcut, - parse_log_level, - RESERVED_BACKUP_IDS, - SHA256, + get_log_levels, + parse_log_level ) from barman.xlog import check_archive_usable -from barman.backup_manifest import BackupManifest -from barman.storage.local_file_manager import LocalFileManager + +if sys.version_info.major < 3: + from argparse import Action, _SubParsersAction, _ActionsContainer +try: + import argcomplete +except ImportError: + argcomplete = None + _logger = logging.getLogger(__name__) diff --git a/barman/clients/cloud_backup.py b/barman/clients/cloud_backup.py index 7ec654b54..9ed9e57fd 100755 --- a/barman/clients/cloud_backup.py +++ b/barman/clients/cloud_backup.py @@ -24,28 +24,33 @@ from shutil import rmtree from barman.clients.cloud_cli import ( - add_tag_argument, - create_argument_parser, GeneralErrorExit, NetworkErrorExit, OperationErrorExit, UrlArgumentType, + add_tag_argument, + create_argument_parser ) from barman.cloud import ( CloudBackupSnapshot, - CloudBackupUploaderBarman, CloudBackupUploader, - configure_logging, + CloudBackupUploaderBarman, + configure_logging ) from barman.cloud_providers import get_cloud_interface, get_snapshot_interface from barman.exceptions import ( BarmanException, ConfigurationException, PostgresConnectionError, - UnrecoverableHookScriptError, + UnrecoverableHookScriptError ) from barman.postgres import PostgreSQLConnection -from barman.utils import check_backup_name, check_positive, check_size, force_str +from barman.utils import ( + check_backup_name, + check_positive, + check_size, + force_str +) _find_space = re.compile(r"[\s]").search diff --git a/barman/clients/cloud_backup_delete.py b/barman/clients/cloud_backup_delete.py index 6c29193ce..c7f3c46e8 100644 --- a/barman/clients/cloud_backup_delete.py +++ b/barman/clients/cloud_backup_delete.py @@ -21,23 +21,23 @@ from contextlib import closing from operator import attrgetter +from barman import xlog from barman.backup import BackupManager from barman.clients.cloud_cli import ( - create_argument_parser, CLIErrorExit, GeneralErrorExit, NetworkErrorExit, OperationErrorExit, + create_argument_parser ) from barman.cloud import CloudBackupCatalog, configure_logging from barman.cloud_providers import ( get_cloud_interface, - get_snapshot_interface_from_backup_info, + get_snapshot_interface_from_backup_info ) from barman.exceptions import BadXlogPrefix, InvalidRetentionPolicy from barman.retention_policies import RetentionPolicyFactory from barman.utils import check_non_negative, force_str -from barman import xlog def _get_files_for_backup(catalog, backup_info): diff --git a/barman/clients/cloud_backup_keep.py b/barman/clients/cloud_backup_keep.py index f30d363e4..5a787bab2 100644 --- a/barman/clients/cloud_backup_keep.py +++ b/barman/clients/cloud_backup_keep.py @@ -21,10 +21,10 @@ from barman.annotations import KeepManager from barman.clients.cloud_cli import ( - create_argument_parser, GeneralErrorExit, NetworkErrorExit, OperationErrorExit, + create_argument_parser ) from barman.cloud import CloudBackupCatalog, configure_logging from barman.cloud_providers import get_cloud_interface diff --git a/barman/clients/cloud_backup_list.py b/barman/clients/cloud_backup_list.py index f26186a51..b5cba7bb5 100644 --- a/barman/clients/cloud_backup_list.py +++ b/barman/clients/cloud_backup_list.py @@ -21,10 +21,10 @@ from contextlib import closing from barman.clients.cloud_cli import ( - create_argument_parser, GeneralErrorExit, NetworkErrorExit, OperationErrorExit, + create_argument_parser ) from barman.cloud import CloudBackupCatalog, configure_logging from barman.cloud_providers import get_cloud_interface diff --git a/barman/clients/cloud_backup_show.py b/barman/clients/cloud_backup_show.py index 25bce54a4..e5d94223f 100644 --- a/barman/clients/cloud_backup_show.py +++ b/barman/clients/cloud_backup_show.py @@ -23,10 +23,10 @@ from contextlib import closing from barman.clients.cloud_cli import ( - create_argument_parser, GeneralErrorExit, NetworkErrorExit, OperationErrorExit, + create_argument_parser ) from barman.cloud import CloudBackupCatalog, configure_logging from barman.cloud_providers import get_cloud_interface diff --git a/barman/clients/cloud_check_wal_archive.py b/barman/clients/cloud_check_wal_archive.py index af44a211d..4ff75c929 100644 --- a/barman/clients/cloud_check_wal_archive.py +++ b/barman/clients/cloud_check_wal_archive.py @@ -19,16 +19,16 @@ import logging from barman.clients.cloud_cli import ( - create_argument_parser, GeneralErrorExit, - OperationErrorExit, NetworkErrorExit, + OperationErrorExit, UrlArgumentType, + create_argument_parser ) -from barman.cloud import configure_logging, CloudBackupCatalog +from barman.cloud import CloudBackupCatalog, configure_logging from barman.cloud_providers import get_cloud_interface from barman.exceptions import WalArchiveContentError -from barman.utils import force_str, check_positive +from barman.utils import check_positive, force_str from barman.xlog import check_archive_usable diff --git a/barman/clients/cloud_cli.py b/barman/clients/cloud_cli.py index 2ff7ef2e4..b583aae21 100644 --- a/barman/clients/cloud_cli.py +++ b/barman/clients/cloud_cli.py @@ -17,7 +17,6 @@ # along with Barman. If not, see . import argparse - import csv import logging diff --git a/barman/clients/cloud_restore.py b/barman/clients/cloud_restore.py index f2a3975bf..7e11cd689 100644 --- a/barman/clients/cloud_restore.py +++ b/barman/clients/cloud_restore.py @@ -15,22 +15,22 @@ # # You should have received a copy of the GNU General Public License # along with Barman. If not, see . -from abc import ABCMeta, abstractmethod import logging import os +from abc import ABCMeta, abstractmethod from contextlib import closing from barman.clients.cloud_cli import ( CLIErrorExit, - create_argument_parser, GeneralErrorExit, NetworkErrorExit, OperationErrorExit, + create_argument_parser ) from barman.cloud import CloudBackupCatalog, configure_logging from barman.cloud_providers import ( get_cloud_interface, - get_snapshot_interface_from_backup_info, + get_snapshot_interface_from_backup_info ) from barman.exceptions import ConfigurationException from barman.fs import UnixLocalCommand diff --git a/barman/clients/cloud_walarchive.py b/barman/clients/cloud_walarchive.py index e69b00fef..ca07ff3ca 100755 --- a/barman/clients/cloud_walarchive.py +++ b/barman/clients/cloud_walarchive.py @@ -22,15 +22,15 @@ from contextlib import closing from barman.clients.cloud_cli import ( - add_tag_argument, - create_argument_parser, CLIErrorExit, GeneralErrorExit, NetworkErrorExit, UrlArgumentType, + add_tag_argument, + create_argument_parser ) -from barman.cloud import configure_logging from barman.clients.cloud_compression import compress +from barman.cloud import configure_logging from barman.cloud_providers import get_cloud_interface from barman.exceptions import BarmanException from barman.utils import check_positive, check_size, force_str diff --git a/barman/clients/cloud_walrestore.py b/barman/clients/cloud_walrestore.py index d118ad073..43a6ca201 100644 --- a/barman/clients/cloud_walrestore.py +++ b/barman/clients/cloud_walrestore.py @@ -22,17 +22,22 @@ from contextlib import closing from barman.clients.cloud_cli import ( - create_argument_parser, CLIErrorExit, GeneralErrorExit, NetworkErrorExit, OperationErrorExit, + create_argument_parser ) -from barman.cloud import configure_logging, ALLOWED_COMPRESSIONS +from barman.cloud import ALLOWED_COMPRESSIONS, configure_logging from barman.cloud_providers import get_cloud_interface from barman.exceptions import BarmanException from barman.utils import force_str -from barman.xlog import hash_dir, is_any_xlog_file, is_backup_file, is_partial_file +from barman.xlog import ( + hash_dir, + is_any_xlog_file, + is_backup_file, + is_partial_file +) def main(args=None): diff --git a/barman/cloud.py b/barman/cloud.py index 2c4ac4506..2d98768fc 100644 --- a/barman/cloud.py +++ b/barman/cloud.py @@ -34,15 +34,19 @@ from io import BytesIO, RawIOBase from tempfile import NamedTemporaryFile +from barman import xlog from barman.annotations import KeepManagerMixinCloud -from barman.backup_executor import ConcurrentBackupStrategy, SnapshotBackupExecutor +from barman.backup_executor import ( + ConcurrentBackupStrategy, + SnapshotBackupExecutor +) from barman.clients import cloud_compression from barman.clients.cloud_cli import get_missing_attrs from barman.exceptions import ( + BackupException, BackupPreconditionException, BarmanException, - BackupException, - ConfigurationException, + ConfigurationException ) from barman.fs import UnixLocalCommand, path_allowed from barman.infofile import BackupInfo @@ -56,9 +60,8 @@ pretty_size, range_fun, total_seconds, - with_metaclass, + with_metaclass ) -from barman import xlog try: # Python 3.x diff --git a/barman/cloud_providers/aws_s3.py b/barman/cloud_providers/aws_s3.py index 7cf4cb330..97ac690b3 100644 --- a/barman/cloud_providers/aws_s3.py +++ b/barman/cloud_providers/aws_s3.py @@ -23,22 +23,21 @@ from barman.clients.cloud_compression import decompress_to_file from barman.cloud import ( + DEFAULT_DELIMITER, CloudInterface, CloudProviderError, CloudSnapshotInterface, DecompressingStreamingIO, - DEFAULT_DELIMITER, SnapshotMetadata, SnapshotsInfo, - VolumeMetadata, + VolumeMetadata ) from barman.exceptions import ( CommandException, SnapshotBackupException, - SnapshotInstanceNotFoundException, + SnapshotInstanceNotFoundException ) - try: # Python 3.x from urllib.parse import urlencode, urlparse diff --git a/barman/cloud_providers/azure_blob_storage.py b/barman/cloud_providers/azure_blob_storage.py index 018bc356e..b820797f2 100644 --- a/barman/cloud_providers/azure_blob_storage.py +++ b/barman/cloud_providers/azure_blob_storage.py @@ -19,19 +19,20 @@ import logging import os import re +from io import SEEK_END, BytesIO, RawIOBase + import requests -from io import BytesIO, RawIOBase, SEEK_END from barman.clients.cloud_compression import decompress_to_file from barman.cloud import ( + DEFAULT_DELIMITER, CloudInterface, CloudProviderError, CloudSnapshotInterface, DecompressingStreamingIO, - DEFAULT_DELIMITER, SnapshotMetadata, SnapshotsInfo, - VolumeMetadata, + VolumeMetadata ) from barman.exceptions import CommandException, SnapshotBackupException diff --git a/barman/cloud_providers/google_cloud_storage.py b/barman/cloud_providers/google_cloud_storage.py index 767cfe248..e4a7a6cbd 100644 --- a/barman/cloud_providers/google_cloud_storage.py +++ b/barman/cloud_providers/google_cloud_storage.py @@ -22,16 +22,15 @@ from barman.clients.cloud_compression import decompress_to_file from barman.cloud import ( + DEFAULT_DELIMITER, CloudInterface, CloudProviderError, CloudSnapshotInterface, DecompressingStreamingIO, - DEFAULT_DELIMITER, SnapshotMetadata, SnapshotsInfo, - VolumeMetadata, + VolumeMetadata ) - from barman.exceptions import CommandException, SnapshotBackupException try: diff --git a/barman/compression.py b/barman/compression.py index c9dcf8462..381ec707e 100644 --- a/barman/compression.py +++ b/barman/compression.py @@ -27,17 +27,18 @@ import shutil from abc import ABCMeta, abstractmethod, abstractproperty from contextlib import closing + from distutils.version import LooseVersion as Version import barman.infofile from barman.command_wrappers import Command -from barman.fs import unix_command_factory from barman.exceptions import ( CommandFailedException, CompressionException, CompressionIncompatibility, - FileNotFoundException, + FileNotFoundException ) +from barman.fs import unix_command_factory from barman.utils import force_str, with_metaclass _logger = logging.getLogger(__name__) diff --git a/barman/config.py b/barman/config.py index b569e0241..5945c64a2 100644 --- a/barman/config.py +++ b/barman/config.py @@ -21,7 +21,6 @@ Barman configuration, such as parsing configuration file. """ -from copy import deepcopy import collections import datetime import inspect @@ -30,6 +29,7 @@ import os import re import sys +from copy import deepcopy from glob import iglob from typing import List diff --git a/barman/diagnose.py b/barman/diagnose.py index ff3d4fd59..82c28373f 100644 --- a/barman/diagnose.py +++ b/barman/diagnose.py @@ -21,10 +21,11 @@ """ import datetime -from dateutil import tz import json import logging +from dateutil import tz + import barman from barman import fs, output from barman.backup import BackupInfo diff --git a/barman/fs.py b/barman/fs.py index 502103388..82c6ce176 100644 --- a/barman/fs.py +++ b/barman/fs.py @@ -16,10 +16,10 @@ # You should have received a copy of the GNU General Public License # along with Barman. If not, see . -import sys import logging import re import shutil +import sys from abc import ABCMeta, abstractmethod from barman import output diff --git a/barman/lockfile.py b/barman/lockfile.py index 8d584488b..8834f513a 100644 --- a/barman/lockfile.py +++ b/barman/lockfile.py @@ -28,7 +28,7 @@ from barman.exceptions import ( LockFileBusy, LockFileParsingError, - LockFilePermissionDenied, + LockFilePermissionDenied ) diff --git a/barman/output.py b/barman/output.py index 119411aea..88aeec4dc 100644 --- a/barman/output.py +++ b/barman/output.py @@ -37,7 +37,7 @@ human_readable_timedelta, pretty_size, redact_passwords, - timestamp, + timestamp ) from barman.xlog import diff_lsn diff --git a/barman/postgres.py b/barman/postgres.py index 21df0e3d4..bac59ae39 100644 --- a/barman/postgres.py +++ b/barman/postgres.py @@ -23,26 +23,27 @@ import atexit import datetime import logging -from abc import ABCMeta -from multiprocessing import Process, Queue import os import signal import threading import time - -try: - from queue import Empty -except ImportError: - from Queue import Empty +from abc import ABCMeta +from multiprocessing import Process, Queue import psycopg2 -from psycopg2.errorcodes import DUPLICATE_OBJECT, OBJECT_IN_USE, UNDEFINED_OBJECT +from psycopg2.errorcodes import ( + DUPLICATE_OBJECT, + OBJECT_IN_USE, + UNDEFINED_OBJECT +) from psycopg2.extensions import STATUS_IN_TRANSACTION, STATUS_READY from psycopg2.extras import DictCursor, NamedTupleCursor from barman.exceptions import ( + BackupFunctionsAccessRequired, ConninfoException, PostgresAppNameError, + PostgresCheckpointPrivilegesRequired, PostgresConnectionError, PostgresConnectionLost, PostgresDuplicateReplicationSlot, @@ -52,15 +53,18 @@ PostgresObsoleteFeature, PostgresReplicationSlotInUse, PostgresReplicationSlotsFull, - BackupFunctionsAccessRequired, - PostgresCheckpointPrivilegesRequired, - PostgresUnsupportedFeature, + PostgresUnsupportedFeature ) from barman.infofile import Tablespace from barman.postgres_plumbing import function_name_map from barman.remote_status import RemoteStatusMixin from barman.utils import force_str, simplify_version, with_metaclass +try: + from queue import Empty +except ImportError: + from Queue import Empty + # This is necessary because the CONFIGURATION_LIMIT_EXCEEDED constant # has been added in psycopg2 2.5, but Barman supports version 2.4.2+ so # in case of import error we declare a constant providing the correct value. diff --git a/barman/recovery_executor.py b/barman/recovery_executor.py index 4df0a7ad6..167027b64 100644 --- a/barman/recovery_executor.py +++ b/barman/recovery_executor.py @@ -24,22 +24,28 @@ import collections import datetime - -from functools import partial import logging import os import re import shutil import socket import tempfile +from functools import partial from io import BytesIO import dateutil.parser import dateutil.tz +import barman.fs as fs from barman import output, xlog from barman.cloud_providers import get_snapshot_interface_from_backup_info from barman.command_wrappers import PgCombineBackup, RsyncPgData +from barman.compression import ( + GZipCompression, + LZ4Compression, + NoneCompression, + ZSTDCompression +) from barman.config import RecoveryOptions from barman.copy_controller import RsyncCopyController from barman.exceptions import ( @@ -48,18 +54,11 @@ DataTransferFailure, FsOperationFailed, RecoveryInvalidTargetException, + RecoveryPreconditionException, RecoveryStandbyModeException, RecoveryTargetActionException, - RecoveryPreconditionException, - SnapshotBackupException, -) -from barman.compression import ( - GZipCompression, - LZ4Compression, - ZSTDCompression, - NoneCompression, + SnapshotBackupException ) -import barman.fs as fs from barman.infofile import BackupInfo, LocalBackupInfo, SyntheticBackupInfo from barman.utils import force_str, mkpath, total_seconds diff --git a/barman/server.py b/barman/server.py index b04a587eb..53f5657ed 100644 --- a/barman/server.py +++ b/barman/server.py @@ -52,6 +52,7 @@ LockFileBusy, LockFileException, LockFilePermissionDenied, + PostgresCheckpointPrivilegesRequired, PostgresDuplicateReplicationSlot, PostgresException, PostgresInvalidReplicationSlot, @@ -60,13 +61,12 @@ PostgresReplicationSlotInUse, PostgresReplicationSlotsFull, PostgresSuperuserRequired, - PostgresCheckpointPrivilegesRequired, PostgresUnsupportedFeature, SyncError, SyncNothingToDo, SyncToBeDeleted, TimeoutError, - UnknownBackupIdException, + UnknownBackupIdException ) from barman.infofile import BackupInfo, LocalBackupInfo, WalFileInfo from barman.lockfile import ( @@ -77,17 +77,17 @@ ServerWalArchiveLock, ServerWalReceiveLock, ServerWalSyncLock, - ServerXLOGDBLock, + ServerXLOGDBLock ) from barman.postgres import ( + PostgreSQL, PostgreSQLConnection, StandbyPostgreSQLConnection, - StreamingConnection, - PostgreSQL, + StreamingConnection ) from barman.process import ProcessManager from barman.remote_status import RemoteStatusMixin -from barman.retention_policies import RetentionPolicyFactory, RetentionPolicy +from barman.retention_policies import RetentionPolicy, RetentionPolicyFactory from barman.utils import ( BarmanEncoder, file_md5, @@ -98,9 +98,13 @@ is_power_of_two, mkpath, pretty_size, - timeout, + timeout +) +from barman.wal_archiver import ( + FileWalArchiver, + StreamingWalArchiver, + WalArchiver ) -from barman.wal_archiver import FileWalArchiver, StreamingWalArchiver, WalArchiver PARTIAL_EXTENSION = ".partial" PRIMARY_INFO_FILE = "primary.info" diff --git a/barman/storage/file_manager.py b/barman/storage/file_manager.py index cb36e58e0..de8eda6cb 100644 --- a/barman/storage/file_manager.py +++ b/barman/storage/file_manager.py @@ -17,6 +17,7 @@ # along with Barman. If not, see . from abc import ABCMeta, abstractmethod + from barman.utils import with_metaclass diff --git a/barman/storage/local_file_manager.py b/barman/storage/local_file_manager.py index f3da43af5..660812ae6 100644 --- a/barman/storage/local_file_manager.py +++ b/barman/storage/local_file_manager.py @@ -17,6 +17,7 @@ # along with Barman. If not, see . import os + from .file_manager import FileManager from .file_stats import FileStats diff --git a/barman/utils.py b/barman/utils.py index 08752e67d..41da515bd 100644 --- a/barman/utils.py +++ b/barman/utils.py @@ -23,7 +23,6 @@ import datetime import decimal import errno -from glob import glob import grp import hashlib import json @@ -34,14 +33,15 @@ import re import signal import sys -from argparse import ArgumentTypeError from abc import ABCMeta, abstractmethod +from argparse import ArgumentTypeError from contextlib import contextmanager -from dateutil import tz +from glob import glob +from dateutil import tz from distutils.version import Version -from barman import lockfile +from barman import lockfile from barman.exceptions import TimeoutError _logger = logging.getLogger(__name__) diff --git a/barman/wal_archiver.py b/barman/wal_archiver.py index 205b046ad..e90657ff8 100644 --- a/barman/wal_archiver.py +++ b/barman/wal_archiver.py @@ -34,7 +34,7 @@ AbortedRetryHookScript, ArchiverFailure, DuplicateWalFile, - MatchingDuplicateWalFile, + MatchingDuplicateWalFile ) from barman.hooks import HookScriptRunner, RetryHookScriptRunner from barman.infofile import WalFileInfo diff --git a/barman/xlog.py b/barman/xlog.py index 8415d5ec1..f94e1cf5f 100644 --- a/barman/xlog.py +++ b/barman/xlog.py @@ -32,7 +32,7 @@ BadXlogPrefix, BadXlogSegmentName, CommandException, - WalArchiveContentError, + WalArchiveContentError ) # xlog file segment name parser (regular expression) diff --git a/scripts/prepare_snapshot_recovery.py b/scripts/prepare_snapshot_recovery.py index 600fc42c8..4d81b79aa 100755 --- a/scripts/prepare_snapshot_recovery.py +++ b/scripts/prepare_snapshot_recovery.py @@ -23,14 +23,16 @@ import sys from typing import Any, NamedTuple -from barman.cli import get_server, global_config, parse_backup_id -from barman.fs import unix_command_factory -from barman.cloud_providers.google_cloud_storage import GcpCloudSnapshotInterface - -from google.api_core.exceptions import NotFound, GoogleAPICallError +from google.api_core.exceptions import GoogleAPICallError, NotFound from google.api_core.extended_operation import ExtendedOperation from google.cloud import compute +from barman.cli import get_server, global_config, parse_backup_id +from barman.cloud_providers.google_cloud_storage import ( + GcpCloudSnapshotInterface +) +from barman.fs import unix_command_factory + if sys.version_info.major < 3 or sys.version_info.minor < 7: print("Minimal python version is 3.7") exit(1) diff --git a/tests/conftest.py b/tests/conftest.py index d5210a24b..973b3f2ec 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,9 +17,10 @@ # along with Barman. If not, see . import logging + +import mock import psycopg2 import pytest -import mock @pytest.fixture(scope="session", autouse=True) diff --git a/tests/storage/test_local_file_manager.py b/tests/storage/test_local_file_manager.py index 121e51270..88b38e6d3 100644 --- a/tests/storage/test_local_file_manager.py +++ b/tests/storage/test_local_file_manager.py @@ -18,6 +18,7 @@ import pytest from mock import patch + from barman.storage.local_file_manager import LocalFileManager diff --git a/tests/test_annotations.py b/tests/test_annotations.py index 827430d0d..d59b356a5 100644 --- a/tests/test_annotations.py +++ b/tests/test_annotations.py @@ -17,8 +17,9 @@ # along with Barman. If not, see . import io -import mock import os + +import mock import pytest from barman.annotations import ( @@ -26,7 +27,7 @@ AnnotationManagerFile, KeepManager, KeepManagerMixin, - KeepManagerMixinCloud, + KeepManagerMixinCloud ) from barman.exceptions import ArchivalBackupException diff --git a/tests/test_backup.py b/tests/test_backup.py index 541b5f872..7d588ec45 100644 --- a/tests/test_backup.py +++ b/tests/test_backup.py @@ -26,20 +26,20 @@ import dateutil.tz import mock import pytest -from mock import Mock, patch, call -from barman.backup import BackupManager -from barman.lockfile import ServerBackupIdLock +from mock import Mock, call, patch import barman.utils from barman.annotations import KeepManager +from barman.backup import BackupManager from barman.config import BackupOptions from barman.exceptions import ( BackupException, - CompressionIncompatibility, - RecoveryInvalidTargetException, CommandFailedException, + CompressionIncompatibility, + RecoveryInvalidTargetException ) from barman.infofile import BackupInfo +from barman.lockfile import ServerBackupIdLock from barman.retention_policies import RetentionPolicyFactory from testing_helpers import ( build_backup_directories, @@ -47,7 +47,7 @@ build_mocked_server, build_test_backup_info, caplog_reset, - interpolate_wals, + interpolate_wals ) diff --git a/tests/test_backup_strategy.py b/tests/test_backup_strategy.py index ab4c5e175..99092831a 100644 --- a/tests/test_backup_strategy.py +++ b/tests/test_backup_strategy.py @@ -16,22 +16,20 @@ # You should have received a copy of the GNU General Public License # along with Barman. If not, see . -import mock import os -import pytest - from io import BytesIO from tarfile import TarFile, TarInfo +import mock +import pytest + from barman.backup_executor import PostgresBackupStrategy from barman.compression import ( - PgBaseBackupCompression, GZipPgBaseBackupCompressionOption, + PgBaseBackupCompression ) -from barman.exceptions import FileNotFoundException -from barman.exceptions import BackupException +from barman.exceptions import BackupException, FileNotFoundException from barman.infofile import LocalBackupInfo - from testing_helpers import build_mocked_server, get_compression_config diff --git a/tests/test_barman_cloud_backup.py b/tests/test_barman_cloud_backup.py index 67ec1b38e..455878f2e 100644 --- a/tests/test_barman_cloud_backup.py +++ b/tests/test_barman_cloud_backup.py @@ -16,8 +16,9 @@ # You should have received a copy of the GNU General Public License # along with Barman. If not, see . -import mock import os + +import mock import pytest from barman.clients import cloud_backup diff --git a/tests/test_barman_cloud_backup_delete.py b/tests/test_barman_cloud_backup_delete.py index d9bc9400f..bc2f3755e 100644 --- a/tests/test_barman_cloud_backup_delete.py +++ b/tests/test_barman_cloud_backup_delete.py @@ -17,6 +17,7 @@ # along with Barman. If not, see . import datetime + import mock import pytest @@ -25,7 +26,6 @@ from barman.clients.cloud_cli import OperationErrorExit from barman.cloud import CloudBackupCatalog from barman.utils import is_backup_id - from testing_helpers import interpolate_wals diff --git a/tests/test_barman_cloud_backup_list.py b/tests/test_barman_cloud_backup_list.py index a062a3109..24f4d3655 100644 --- a/tests/test_barman_cloud_backup_list.py +++ b/tests/test_barman_cloud_backup_list.py @@ -17,6 +17,7 @@ # along with Barman. If not, see . import datetime + import mock from barman.annotations import KeepManager diff --git a/tests/test_barman_cloud_backup_show.py b/tests/test_barman_cloud_backup_show.py index 51b547866..afe6338f2 100644 --- a/tests/test_barman_cloud_backup_show.py +++ b/tests/test_barman_cloud_backup_show.py @@ -18,6 +18,7 @@ import datetime import json + import mock import pytest @@ -25,7 +26,7 @@ from barman.clients.cloud_cli import OperationErrorExit from barman.cloud_providers.google_cloud_storage import ( GcpSnapshotMetadata, - GcpSnapshotsInfo, + GcpSnapshotsInfo ) from testing_helpers import build_test_backup_info diff --git a/tests/test_barman_cloud_restore.py b/tests/test_barman_cloud_restore.py index 7d0754e95..a9b316b78 100644 --- a/tests/test_barman_cloud_restore.py +++ b/tests/test_barman_cloud_restore.py @@ -23,7 +23,7 @@ from barman.clients.cloud_cli import OperationErrorExit from barman.clients.cloud_restore import ( CloudBackupDownloaderObjectStore, - CloudBackupDownloaderSnapshot, + CloudBackupDownloaderSnapshot ) from barman.cloud import BackupFileInfo from barman.exceptions import RecoveryPreconditionException diff --git a/tests/test_barman_cloud_wal_archive.py b/tests/test_barman_cloud_wal_archive.py index aaecb9465..767c7997c 100644 --- a/tests/test_barman_cloud_wal_archive.py +++ b/tests/test_barman_cloud_wal_archive.py @@ -20,10 +20,10 @@ import gzip import logging import os -import snappy import mock import pytest +import snappy from barman.clients import cloud_walarchive from barman.clients.cloud_walarchive import CloudWalUploader @@ -32,7 +32,6 @@ from barman.exceptions import BarmanException from barman.xlog import hash_dir - EXAMPLE_WAL_PATH = "wal_dir/000000080000ABFF000000C1" diff --git a/tests/test_cli.py b/tests/test_cli.py index a11d6ef95..1d9f191f5 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -16,38 +16,38 @@ # You should have received a copy of the GNU General Public License # along with Barman. If not, see . -from argparse import ArgumentTypeError - import json import os -import pytest import sys +from argparse import ArgumentTypeError + +import pytest from mock import MagicMock, Mock, patch import barman.config from barman import output from barman.cli import ( ArgumentParser, + OrderedHelpFormatter, argument, backup, check_target_action, check_wal_archive, command, + config_switch, generate_manifest, get_model, get_models_list, get_server, get_server_list, + keep, manage_model_command, manage_server_command, - OrderedHelpFormatter, parse_backup_id, receive_wal, recover, replication_status, - keep, - show_servers, - config_switch, + show_servers ) from barman.exceptions import WalArchiveContentError from barman.infofile import BackupInfo @@ -57,7 +57,7 @@ build_config_from_dicts, build_mocked_server, build_real_server, - build_test_backup_info, + build_test_backup_info ) diff --git a/tests/test_cloud.py b/tests/test_cloud.py index 48203ff6e..95883bfc0 100644 --- a/tests/test_cloud.py +++ b/tests/test_cloud.py @@ -28,26 +28,22 @@ from io import BytesIO from tarfile import TarFile, TarInfo from tarfile import open as open_tar -from azure.core.exceptions import ResourceNotFoundError, ServiceRequestError -from azure.identity import AzureCliCredential, ManagedIdentityCredential -from azure.storage.blob import PartialBatchErrorException +from unittest import TestCase import mock -from mock.mock import MagicMock import pytest import snappy - -from barman.exceptions import BackupPreconditionException -from barman.infofile import BackupInfo - -if sys.version_info.major > 2: - from unittest.mock import patch as unittest_patch -from unittest import TestCase +from azure.core.exceptions import ResourceNotFoundError, ServiceRequestError +from azure.identity import AzureCliCredential, ManagedIdentityCredential +from azure.storage.blob import PartialBatchErrorException from boto3.exceptions import Boto3Error from botocore.exceptions import ClientError, EndpointConnectionError +from google.api_core.exceptions import Conflict, GoogleAPIError +from mock.mock import MagicMock from barman.annotations import KeepManager from barman.cloud import ( + DEFAULT_DELIMITER, CloudBackupCatalog, CloudBackupSnapshot, CloudBackupUploader, @@ -56,19 +52,22 @@ CloudTarUploader, CloudUploadController, CloudUploadingError, - FileUploadStatistics, - DEFAULT_DELIMITER, + FileUploadStatistics ) from barman.cloud_providers import ( CloudProviderOptionUnsupported, CloudProviderUnsupported, - get_cloud_interface, + get_cloud_interface ) from barman.cloud_providers.aws_s3 import S3CloudInterface from barman.cloud_providers.azure_blob_storage import AzureCloudInterface from barman.cloud_providers.google_cloud_storage import GoogleCloudInterface +from barman.exceptions import BackupPreconditionException +from barman.infofile import BackupInfo + +if sys.version_info.major > 2: + from unittest.mock import patch as unittest_patch -from google.api_core.exceptions import GoogleAPIError, Conflict try: from queue import Queue diff --git a/tests/test_cloud_snapshot_interface.py b/tests/test_cloud_snapshot_interface.py index 17993bf06..ec8a88073 100644 --- a/tests/test_cloud_snapshot_interface.py +++ b/tests/test_cloud_snapshot_interface.py @@ -17,36 +17,38 @@ # along with Barman. If not, see . import logging + import mock import pytest - from azure.core.exceptions import ResourceNotFoundError from botocore.exceptions import ClientError from google.api_core.exceptions import NotFound from barman.cloud import CloudProviderError - from barman.cloud_providers import ( CloudProviderUnsupported, get_snapshot_interface, get_snapshot_interface_from_backup_info, - get_snapshot_interface_from_server_config, + get_snapshot_interface_from_server_config +) +from barman.cloud_providers.aws_s3 import ( + AwsCloudSnapshotInterface, + AwsVolumeMetadata ) -from barman.cloud_providers.aws_s3 import AwsCloudSnapshotInterface, AwsVolumeMetadata from barman.cloud_providers.azure_blob_storage import ( AzureCloudSnapshotInterface, - AzureVolumeMetadata, + AzureVolumeMetadata ) from barman.cloud_providers.google_cloud_storage import ( GcpCloudSnapshotInterface, - GcpVolumeMetadata, + GcpVolumeMetadata ) from barman.exceptions import ( BarmanException, CommandException, ConfigurationException, SnapshotBackupException, - SnapshotInstanceNotFoundException, + SnapshotInstanceNotFoundException ) diff --git a/tests/test_command_wrappers.py b/tests/test_command_wrappers.py index 57ff70c9e..a8c19f4ed 100644 --- a/tests/test_command_wrappers.py +++ b/tests/test_command_wrappers.py @@ -31,7 +31,7 @@ PgReceiveXlog, StreamLineProcessor, full_command_quote, - shell_quote, + shell_quote ) from barman.exceptions import CommandFailedException, CommandMaxRetryExceeded from testing_helpers import u diff --git a/tests/test_compressor.py b/tests/test_compressor.py index 63a38c112..dc2259826 100644 --- a/tests/test_compressor.py +++ b/tests/test_compressor.py @@ -17,37 +17,38 @@ # along with Barman. If not, see . import base64 +import io import os +import tarfile import mock import pytest -import tarfile -import io + from barman.compression import ( BZip2Compressor, CommandCompressor, CompressionManager, Compressor, CustomCompressor, + GZipCompression, GZipCompressor, - PyBZip2Compressor, - PyGZipCompressor, - get_pg_basebackup_compression, - PgBaseBackupCompression, - PgBaseBackupCompressionOption, GZipPgBaseBackupCompressionOption, - GZipCompression, - LZ4PgBaseBackupCompressionOption, LZ4Compression, - ZSTDPgBaseBackupCompressionOption, - ZSTDCompression, - NonePgBaseBackupCompressionOption, + LZ4PgBaseBackupCompressionOption, NoneCompression, + NonePgBaseBackupCompressionOption, + PgBaseBackupCompression, + PgBaseBackupCompressionOption, + PyBZip2Compressor, + PyGZipCompressor, + ZSTDCompression, + ZSTDPgBaseBackupCompressionOption, + get_pg_basebackup_compression ) from barman.exceptions import ( - CompressionException, - FileNotFoundException, CommandFailedException, + CompressionException, + FileNotFoundException ) from testing_helpers import build_mocked_server, get_compression_config diff --git a/tests/test_config.py b/tests/test_config.py index 23c065fb6..8c5286269 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -21,18 +21,18 @@ import mock import pytest -import testing_helpers from mock import MagicMock, Mock, call, mock_open, patch +import testing_helpers from barman.config import ( BackupOptions, BaseConfig, - ConfigMapping, Config, ConfigChange, ConfigChangeSet, ConfigChangesProcessor, ConfigChangesQueue, + ConfigMapping, CsvOption, ModelConfig, RecoveryOptions, @@ -40,10 +40,10 @@ parse_backup_compression_format, parse_backup_compression_location, parse_si_suffix, - parse_staging_path, parse_slot_name, parse_snapshot_disks, - parse_time_interval, + parse_staging_path, + parse_time_interval ) try: diff --git a/tests/test_copy_controller.py b/tests/test_copy_controller.py index 6c90f9ad6..e89af57b5 100644 --- a/tests/test_copy_controller.py +++ b/tests/test_copy_controller.py @@ -18,8 +18,8 @@ import multiprocessing.dummy import os -from datetime import datetime import time +from datetime import datetime import dateutil.tz import mock @@ -30,13 +30,13 @@ BUCKET_SIZE, RsyncCopyController, _FileItem, - _RsyncCopyItem, + _RsyncCopyItem ) from barman.exceptions import CommandFailedException, RsyncListFilesFailure from testing_helpers import ( build_backup_manager, build_real_server, - build_test_backup_info, + build_test_backup_info ) diff --git a/tests/test_executor.py b/tests/test_executor.py index c63eda03d..3c44b3d40 100644 --- a/tests/test_executor.py +++ b/tests/test_executor.py @@ -17,21 +17,21 @@ # along with Barman. If not, see . import datetime -from functools import partial import logging import os +from functools import partial import mock import pytest from dateutil import tz -from mock import Mock, PropertyMock, patch, call +from mock import Mock, PropertyMock, call, patch from barman.backup_executor import ( ExclusiveBackupStrategy, PostgresBackupExecutor, PostgresBackupStrategy, RsyncBackupExecutor, - SnapshotBackupExecutor, + SnapshotBackupExecutor ) from barman.config import BackupOptions from barman.exceptions import ( @@ -41,7 +41,7 @@ FsOperationFailed, PostgresConnectionError, SnapshotBackupException, - SshCommandException, + SshCommandException ) from barman.infofile import BackupInfo, LocalBackupInfo, Tablespace from barman.postgres_plumbing import EXCLUDE_LIST, PGDATA_EXCLUDE_LIST @@ -49,7 +49,7 @@ from testing_helpers import ( build_backup_manager, build_mocked_server, - build_test_backup_info, + build_test_backup_info ) diff --git a/tests/test_fs.py b/tests/test_fs.py index 0fd07e6da..ffd08d8e7 100644 --- a/tests/test_fs.py +++ b/tests/test_fs.py @@ -17,6 +17,7 @@ # along with Barman. If not, see . import sys + import pytest from mock import call, patch @@ -26,7 +27,7 @@ _match_path, _translate_to_regexp, _wildcard_match_path, - path_allowed, + path_allowed ) diff --git a/tests/test_infofile.py b/tests/test_infofile.py index d19ad589c..662885d89 100644 --- a/tests/test_infofile.py +++ b/tests/test_infofile.py @@ -26,16 +26,16 @@ import pytest from dateutil.tz import tzlocal, tzoffset from mock import PropertyMock, patch + from barman.cloud_providers.aws_s3 import AwsSnapshotMetadata, AwsSnapshotsInfo from barman.cloud_providers.azure_blob_storage import ( AzureSnapshotMetadata, - AzureSnapshotsInfo, + AzureSnapshotsInfo ) from barman.cloud_providers.google_cloud_storage import ( GcpSnapshotMetadata, - GcpSnapshotsInfo, + GcpSnapshotsInfo ) - from barman.infofile import ( BackupInfo, Field, @@ -43,15 +43,15 @@ LocalBackupInfo, SyntheticBackupInfo, WalFileInfo, - load_datetime_tz, dump_backup_ids, load_backup_ids, + load_datetime_tz ) from testing_helpers import ( build_backup_manager, build_mocked_server, build_real_server, - build_test_backup_info, + build_test_backup_info ) BASE_BACKUP_INFO = """backup_label=None diff --git a/tests/test_lockfile.py b/tests/test_lockfile.py index 9a060a2b0..3d8cd70ae 100644 --- a/tests/test_lockfile.py +++ b/tests/test_lockfile.py @@ -32,7 +32,7 @@ ServerCronLock, ServerWalReceiveLock, ServerWalSyncLock, - ServerXLOGDBLock, + ServerXLOGDBLock ) diff --git a/tests/test_output.py b/tests/test_output.py index 203e4806c..6611de67c 100644 --- a/tests/test_output.py +++ b/tests/test_output.py @@ -16,19 +16,18 @@ # You should have received a copy of the GNU General Public License # along with Barman. If not, see . +import datetime import json import mock -from mock import PropertyMock import pytest - -import datetime from dateutil import tz +from mock import PropertyMock from barman import output from barman.cloud_providers.google_cloud_storage import ( GcpSnapshotMetadata, - GcpSnapshotsInfo, + GcpSnapshotsInfo ) from barman.infofile import BackupInfo from barman.utils import BarmanEncoder, human_readable_timedelta, pretty_size @@ -36,7 +35,7 @@ build_backup_manager, build_test_backup_info, find_by_attr, - mock_backup_ext_info, + mock_backup_ext_info ) # Color output constants diff --git a/tests/test_postgres.py b/tests/test_postgres.py index 0384607ab..a788dc2ac 100644 --- a/tests/test_postgres.py +++ b/tests/test_postgres.py @@ -21,36 +21,36 @@ from multiprocessing import Queue from unittest.mock import MagicMock -try: - from queue import Queue as SyncQueue -except ImportError: - from Queue import Queue as SyncQueue - import psycopg2 import pytest from mock import Mock, PropertyMock, call, patch from psycopg2.errorcodes import DUPLICATE_OBJECT, UNDEFINED_OBJECT from barman.exceptions import ( + BackupFunctionsAccessRequired, + PostgresCheckpointPrivilegesRequired, PostgresConnectionError, PostgresConnectionLost, PostgresDuplicateReplicationSlot, PostgresException, PostgresInvalidReplicationSlot, PostgresIsInRecovery, - BackupFunctionsAccessRequired, PostgresObsoleteFeature, - PostgresCheckpointPrivilegesRequired, - PostgresUnsupportedFeature, + PostgresUnsupportedFeature ) from barman.postgres import ( - PostgreSQLConnection, PostgresKeepAlive, - StandbyPostgreSQLConnection, PostgreSQL, + PostgreSQLConnection, + StandbyPostgreSQLConnection ) from testing_helpers import build_real_server +try: + from queue import Queue as SyncQueue +except ImportError: + from Queue import Queue as SyncQueue + class MockProgrammingError(psycopg2.ProgrammingError): """ diff --git a/tests/test_recovery_executor.py b/tests/test_recovery_executor.py index 0873684b4..fd0e3e362 100644 --- a/tests/test_recovery_executor.py +++ b/tests/test_recovery_executor.py @@ -16,10 +16,10 @@ # You should have received a copy of the GNU General Public License # along with Barman. If not, see . -from functools import partial import os import shutil from contextlib import closing +from functools import partial import dateutil import dateutil.tz @@ -36,22 +36,18 @@ RecoveryPreconditionException, RecoveryStandbyModeException, RecoveryTargetActionException, - SnapshotBackupException, -) -from barman.infofile import ( - BackupInfo, - WalFileInfo, - SyntheticBackupInfo, + SnapshotBackupException ) +from barman.infofile import BackupInfo, SyntheticBackupInfo, WalFileInfo from barman.recovery_executor import ( Assertion, + ConfigurationFileMangeler, + IncrementalRecoveryExecutor, RecoveryExecutor, RemoteConfigRecoveryExecutor, SnapshotRecoveryExecutor, TarballRecoveryExecutor, - ConfigurationFileMangeler, - recovery_executor_factory, - IncrementalRecoveryExecutor, + recovery_executor_factory ) diff --git a/tests/test_retention_policies.py b/tests/test_retention_policies.py index 097781bc2..e1e360cd7 100644 --- a/tests/test_retention_policies.py +++ b/tests/test_retention_policies.py @@ -30,7 +30,7 @@ from barman.retention_policies import ( RecoveryWindowRetentionPolicy, RedundancyRetentionPolicy, - RetentionPolicyFactory, + RetentionPolicyFactory ) from testing_helpers import build_mocked_server, build_test_backup_info diff --git a/tests/test_server.py b/tests/test_server.py index 9bfe0787f..1f414c695 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -23,9 +23,9 @@ import tarfile import time from collections import namedtuple -import dateutil.tz from io import BytesIO +import dateutil.tz import mock import pytest from mock import MagicMock, Mock, PropertyMock, patch @@ -40,14 +40,14 @@ PostgresInvalidReplicationSlot, PostgresReplicationSlotsFull, PostgresSuperuserRequired, - PostgresUnsupportedFeature, + PostgresUnsupportedFeature ) from barman.infofile import BackupInfo, WalFileInfo from barman.lockfile import ( ServerBackupLock, ServerCronLock, ServerWalArchiveLock, - ServerWalReceiveLock, + ServerWalReceiveLock ) from barman.postgres import PostgreSQLConnection from barman.process import ProcessInfo @@ -55,7 +55,7 @@ from testing_helpers import ( build_config_from_dicts, build_real_server, - build_test_backup_info, + build_test_backup_info ) diff --git a/tests/test_sync.py b/tests/test_sync.py index 9c6406723..b8d637a6e 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -29,14 +29,14 @@ CommandFailedException, SyncError, SyncNothingToDo, - SyncToBeDeleted, + SyncToBeDeleted ) from barman.infofile import BackupInfo, LocalBackupInfo from barman.lockfile import LockFileBusy from testing_helpers import ( build_config_from_dicts, build_real_server, - build_test_backup_info, + build_test_backup_info ) # expected result of the sync --status command diff --git a/tests/test_utils.py b/tests/test_utils.py index 24a94f7a4..22c4f895e 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -19,21 +19,20 @@ import decimal import json import logging +import os +import re import signal import sys -import re -import os from argparse import ArgumentTypeError from datetime import datetime, timedelta -from dateutil import tz import mock import pytest +from dateutil import tz from distutils.version import LooseVersion -from barman.lockfile import LockFile import barman.utils - +from barman.lockfile import LockFile LOGFILE_NAME = "logfile.log" diff --git a/tests/test_wal_archiver.py b/tests/test_wal_archiver.py index 66f4e50c9..94423b65f 100644 --- a/tests/test_wal_archiver.py +++ b/tests/test_wal_archiver.py @@ -21,12 +21,12 @@ from mock import ANY, MagicMock, patch import barman.xlog -from barman.compression import PyGZipCompressor, CompressionManager +from barman.compression import CompressionManager, PyGZipCompressor from barman.exceptions import ( ArchiverFailure, CommandFailedException, DuplicateWalFile, - MatchingDuplicateWalFile, + MatchingDuplicateWalFile ) from barman.infofile import WalFileInfo from barman.process import ProcessInfo @@ -34,9 +34,13 @@ from barman.wal_archiver import ( FileWalArchiver, StreamingWalArchiver, - WalArchiverQueue, + WalArchiverQueue +) +from testing_helpers import ( + build_backup_manager, + build_test_backup_info, + caplog_reset ) -from testing_helpers import build_backup_manager, build_test_backup_info, caplog_reset # noinspection PyMethodMayBeStatic diff --git a/tests/testing_helpers.py b/tests/testing_helpers.py index a97bf0214..dc45da603 100644 --- a/tests/testing_helpers.py +++ b/tests/testing_helpers.py @@ -24,9 +24,14 @@ from dateutil import tz from barman.backup import BackupManager -from barman.config import BackupOptions, Config from barman.compression import PgBaseBackupCompressionConfig -from barman.infofile import BackupInfo, LocalBackupInfo, Tablespace, WalFileInfo +from barman.config import BackupOptions, Config +from barman.infofile import ( + BackupInfo, + LocalBackupInfo, + Tablespace, + WalFileInfo +) from barman.server import Server from barman.utils import mkpath from barman.xlog import DEFAULT_XLOG_SEG_SIZE