diff --git a/borgmatic/actions/browse/archive.py b/borgmatic/actions/browse/archive.py index 5e3cc8f8..d474969e 100644 --- a/borgmatic/actions/browse/archive.py +++ b/borgmatic/actions/browse/archive.py @@ -3,16 +3,14 @@ import collections import enum import json import logging -import os + +import binaryornot.helpers import borgmatic.borg.extract import borgmatic.borg.list import borgmatic.borg.repo_list import borgmatic.borg.version -import binaryornot.helpers - - logger = logging.getLogger(__name__) @@ -69,7 +67,7 @@ def get_repository_archives(config, repository): def get_archive_paths(config, repository, archive_name): ''' Given a configuration dict, a repository dict, and an archive name in that repository, get a - list of files, directories, symlinks, etc. found in the archive, each as an Archive_path + generator of files, directories, symlinks, etc. found in the archive, each as an Archive_path instance. ''' with borgmatic.logger.Log_prefix(repository.get('label', repository['path'])): diff --git a/borgmatic/actions/browse/archives_list.py b/borgmatic/actions/browse/archives_list.py index 84098c84..9182849a 100644 --- a/borgmatic/actions/browse/archives_list.py +++ b/borgmatic/actions/browse/archives_list.py @@ -1,7 +1,3 @@ -import contextlib -import os - -import textual.binding import textual.widgets import borgmatic.actions.browse.bindings @@ -50,7 +46,6 @@ class Archives_list(textual.widgets.OptionList): archive_loaded=self.archive_loaded, config=self.config, repository=self.repository, - loading_timer=self.loading_timer, ) def on_archive_loaded(self, archive_name): diff --git a/borgmatic/actions/browse/bindings.py b/borgmatic/actions/browse/bindings.py index f42422c5..b2bfc4e9 100644 --- a/borgmatic/actions/browse/bindings.py +++ b/borgmatic/actions/browse/bindings.py @@ -1,7 +1,6 @@ import textual.binding import textual.widgets - OPTION_LIST_BINDINGS = ( *textual.widgets.OptionList.BINDINGS, textual.binding.Binding( diff --git a/borgmatic/actions/browse/carousel.py b/borgmatic/actions/browse/carousel.py index 6c5bdec9..9890dfdd 100644 --- a/borgmatic/actions/browse/carousel.py +++ b/borgmatic/actions/browse/carousel.py @@ -5,8 +5,8 @@ import textual.containers import borgmatic.actions.browse.archive import borgmatic.actions.browse.archives_list -import borgmatic.actions.browse.directory_list import borgmatic.actions.browse.configuration_files_list +import borgmatic.actions.browse.directory_list import borgmatic.actions.browse.file_preview import borgmatic.actions.browse.icons import borgmatic.actions.browse.repositories_list @@ -53,7 +53,8 @@ def make_next_panel(focused_panel, option_id): path_loaded=focused_panel.path_loaded, path_components=(*focused_panel.path_components, option_id), ) - elif option.prompt.startswith( + + if option.prompt.startswith( borgmatic.actions.browse.icons.PATH_TYPE_ICONS[ borgmatic.actions.browse.archive.Path_type.FILE.value ] diff --git a/borgmatic/actions/browse/configuration_files_list.py b/borgmatic/actions/browse/configuration_files_list.py index 0c21748f..90e451c2 100644 --- a/borgmatic/actions/browse/configuration_files_list.py +++ b/borgmatic/actions/browse/configuration_files_list.py @@ -1,12 +1,8 @@ -import contextlib import os -import textual.binding import textual.widgets import borgmatic.actions.browse.bindings -import borgmatic.actions.browse.loading -import borgmatic.actions.browse.workers class Configuration_files_list(textual.widgets.OptionList): diff --git a/borgmatic/actions/browse/directory_list.py b/borgmatic/actions/browse/directory_list.py index 95a8b747..1cfe36ec 100644 --- a/borgmatic/actions/browse/directory_list.py +++ b/borgmatic/actions/browse/directory_list.py @@ -1,10 +1,7 @@ -import contextlib import os -import textual.binding import textual.widgets -import borgmatic.actions.browse.archive import borgmatic.actions.browse.bindings import borgmatic.actions.browse.icons import borgmatic.actions.browse.loading @@ -86,7 +83,7 @@ def add_archive_paths( ), ) if relative_path_components - if not relative_path_components[0] in directory_list._id_to_option + if relative_path_components[0] not in directory_list._id_to_option ), ), # The loading indicator "option" always goes to the bottom. diff --git a/borgmatic/actions/browse/file_preview.py b/borgmatic/actions/browse/file_preview.py index edae0b46..6ea37903 100644 --- a/borgmatic/actions/browse/file_preview.py +++ b/borgmatic/actions/browse/file_preview.py @@ -1,6 +1,4 @@ import logging -import contextlib -import os import rich.syntax import textual.binding @@ -9,7 +7,6 @@ import textual.widgets import borgmatic.actions.browse.loading import borgmatic.actions.browse.workers - logger = logging.getLogger('__name__') @@ -18,7 +15,7 @@ class File_preview(textual.widgets.RichLog): A widget for extracting and previewing the contents of a file stored in a Borg archive. ''' - BINDINGS = [ + BINDINGS = ( *textual.widgets.RichLog.BINDINGS, textual.binding.Binding( key='up,k', action='scroll_up', description='scroll up', show=True, priority=True @@ -32,7 +29,7 @@ class File_preview(textual.widgets.RichLog): textual.binding.Binding( key='pagedown', action='page_down', description='page down', show=True, priority=True ), - ] + ) def __init__(self, config, repository, archive_name, file_path): ''' @@ -46,7 +43,7 @@ class File_preview(textual.widgets.RichLog): self.file_path = file_path super().__init__(classes='panel') - self.border_title = ' '.join(('📄', self.file_path, 'preview')) + self.border_title = f'📄 {self.file_path} preview' self.auto_scroll = False self.file_preview_loaded = borgmatic.actions.browse.workers.File_preview_loaded( self, 'file preview loaded' @@ -71,7 +68,6 @@ class File_preview(textual.widgets.RichLog): repository=self.repository, archive_name=self.archive_name, file_path=self.file_path, - loading_timer=self.loading_timer, ) def on_file_preview_loaded(self, file_contents): diff --git a/borgmatic/actions/browse/icons.py b/borgmatic/actions/browse/icons.py index 2d621d38..57d400af 100644 --- a/borgmatic/actions/browse/icons.py +++ b/borgmatic/actions/browse/icons.py @@ -1,6 +1,5 @@ import borgmatic.actions.browse.archive - PATH_TYPE_ICONS = { borgmatic.actions.browse.archive.Path_type.DIRECTORY.value: '📁', borgmatic.actions.browse.archive.Path_type.LINK.value: '🔗', diff --git a/borgmatic/actions/browse/loading.py b/borgmatic/actions/browse/loading.py index 351014e7..24414c89 100644 --- a/borgmatic/actions/browse/loading.py +++ b/borgmatic/actions/browse/loading.py @@ -1,5 +1,6 @@ import contextlib import functools +import logging import textual.widgets import textual.widgets.option_list @@ -7,8 +8,6 @@ import textual.widgets.option_list LOADING_DOT_INTERVAL_SECONDS = 0.3 -import logging - logger = logging.getLogger('__name__') diff --git a/borgmatic/actions/browse/repositories_list.py b/borgmatic/actions/browse/repositories_list.py index 8985c78f..57ddc803 100644 --- a/borgmatic/actions/browse/repositories_list.py +++ b/borgmatic/actions/browse/repositories_list.py @@ -1,12 +1,6 @@ -import contextlib -import os - -import textual.binding import textual.widgets import borgmatic.actions.browse.bindings -import borgmatic.actions.browse.loading -import borgmatic.actions.browse.workers class Repositories_list(textual.widgets.OptionList): diff --git a/borgmatic/actions/browse/workers.py b/borgmatic/actions/browse/workers.py index bf80cf4c..338ac8c8 100644 --- a/borgmatic/actions/browse/workers.py +++ b/borgmatic/actions/browse/workers.py @@ -1,14 +1,11 @@ -import contextlib import logging import os import textual import textual.signal -import textual.widgets.option_list import borgmatic.actions.browse.archive - logger = logging.getLogger('__name__') @@ -26,25 +23,22 @@ class Archive_loaded(textual.signal.Signal): Archive_loaded instance per repository. ''' - pass - @textual.work(thread=True) -def add_repository_archives(browse_app, archive_loaded, config, repository, loading_timer): +def add_repository_archives(browse_app, archive_loaded, config, repository): ''' - Given a running Browse_app instance, an Archive_loaded instance, a configuration dict, a - repository dict, and a loading indicator timer, load a list of the archives from the repository - and add them as options in the archives list. Reverse the order so the most recent archive is - first. + Given a running Browse_app instance, an Archive_loaded instance, a configuration dict, and a + repository dict, load a list of the archives from the repository and add them as options in the + archives list. Reverse the order so the most recent archive is first. - This function runs in a separate thread from the main UI. When loading is complete, remove the - loading indicator and stop its timer. + This function runs in a separate thread from the main UI. When loading is complete, publish a + loading done signal. ''' archives_data = borgmatic.actions.browse.archive.get_repository_archives(config, repository) # Reverse the archives, so the common case of accessing the latest archive is easy because it's # at the top. - for index, archive in enumerate(reversed(archives_data['archives'])): + for archive in reversed(archives_data['archives']): archive_loaded.publish(archive['archive']) archive_loaded.publish(LOADING_DONE) @@ -72,35 +66,42 @@ def record_path(archive_path, hierarchy, path_components): def get_paths(hierarchy, path_components, full_path_components=None): ''' Given a dict capturing a filesystem hierarchy of paths (or a subset thereof), a tuple of path - components for an archive path relative to the hierarchy root, and an optional tuple of - *absolute* path components for the same archive path (if different), return the corresponding - Archive_path from the hierarchy. + components for a directory path relative to the hierarchy root, and an optional tuple of + *absolute* path components for the same path (if different), return a generator of the + contained file and directory Archive_path instances from the hierarchy. For instance, given the following hierarchy: - {'foo': {'bar': {'baz.txt': Archive_path('-', 'foo/bar/baz.txt', '')}}} + {'foo': {'bar': {'baz.txt': Archive_path('-', 'foo/bar/baz.txt', ''), 'quux': {}}}} - ... and path components of ('foo', 'bar', 'baz.txt'), return the Archive_path instance above. + ... and path components of ('foo', 'bar'), return a generator with the following: - Or in the case of path components of only ('foo', 'bar'), return a directory with the absolute - path: + * Archive_path('-', 'foo/bar/baz.txt', '') + * Archive_path('d', 'foo/bar/quux', '') - Archive_path('d', 'foo/bar', '') + The given absolute path components are use to construct directory paths like that last archive + path. ''' if full_path_components is None: full_path_components = path_components if len(path_components) == 1: - return ( - archive_path - if isinstance(archive_path, borgmatic.actions.browse.archive.Archive_path) - else borgmatic.actions.browse.archive.Archive_path( - 'd', os.path.join(*full_path_components, component), '' + try: + return ( + archive_path + if isinstance(archive_path, borgmatic.actions.browse.archive.Archive_path) + else borgmatic.actions.browse.archive.Archive_path( + 'd', os.path.join(*full_path_components, component), '' + ) + for component, archive_path in hierarchy[path_components[0]].items() ) - for component, archive_path in hierarchy[path_components[0]].items() - ) + except KeyError: + raise ValueError(f'Unknown file or directory: {path_components[0]}') - return get_paths(hierarchy[path_components[0]], path_components[1:], full_path_components) + try: + return get_paths(hierarchy[path_components[0]], path_components[1:], full_path_components) + except KeyError: + raise ValueError(f'Unknown directory: {path_components[0]}') class Archive_path_loaded(textual.signal.Signal): @@ -122,13 +123,19 @@ class Archive_path_loaded(textual.signal.Signal): super().__init__(owner, name) - def publish(self, data): - super().publish(data) + def publish(self, archive_path): + ''' + Publish the given archive path to subscribers and record its path locally. But if the + archive path is actually LOADING_DONE, then record loading as complete. + ''' + super().publish(archive_path) - if data is LOADING_DONE: + if archive_path is LOADING_DONE: self.complete = True else: - record_path(data, self.path_hierarchy, data.file_path.split(os.path.sep)) + record_path( + archive_path, self.path_hierarchy, archive_path.file_path.split(os.path.sep) + ) @textual.work(thread=True) @@ -139,7 +146,8 @@ def load_archive_paths(browse_app, path_loaded, config, repository, archive_name the Archive_path_loaded signal, so interested widgets can subscribe. Also send a "loading done" signal when loading completes. - This function runs in a separate thread from the main UI. + This function runs in a separate thread from the main UI. When loading is complete, publish a + loading done signal. ''' for archive_path in borgmatic.actions.browse.archive.get_archive_paths( config, repository, archive_name @@ -159,17 +167,23 @@ class File_preview_loaded(textual.signal.Signal): Archive_loaded instance per previewed file. ''' - pass - @textual.work(thread=True) def load_file_preview( - browse_app, file_preview_loaded, config, repository, archive_name, file_path, loading_timer + browse_app, + file_preview_loaded, + config, + repository, + archive_name, + file_path, ): ''' Given a running Browse_app instance, a File_preview_loaded instance, a configuration dict, a - repository dict, an archive name, the path of a file in that archive, and a loading indicator - timer, load the contents of the file and write it into the given file preview widget. + repository dict, an archive name, and the path of a file in that archive, load the contents of + the file and write it into the given file preview widget. + + This function runs in a separate thread from the main UI. When loading is complete, publish a + loading done signal. ''' file_contents = borgmatic.actions.browse.archive.get_archive_file_content( config, repository, archive_name, file_path diff --git a/borgmatic/borg/borg.py b/borgmatic/borg/borg.py index 20af8e11..dd46f687 100644 --- a/borgmatic/borg/borg.py +++ b/borgmatic/borg/borg.py @@ -31,7 +31,7 @@ def run_arbitrary_borg( borgmatic.logger.add_custom_log_levels() lock_wait = config.get('lock_wait', None) - try: + try: # noqa: PLW0717 options = options[1:] if options[0] == '--' else options # Borg commands like "key" have a sub-command ("export", etc.) that must follow it. diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index f2a3b613..1d4837c9 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -212,7 +212,7 @@ def run_configuration(config_filename, config, config_paths, arguments): # noqa f"Skipping {'/'.join(skip_actions)} action{'s' if len(skip_actions) > 1 else ''} due to configured skip_actions", ) - try: # noqa: PLR1702 + try: # noqa: PLR1702, PLW0717 with ( Monitoring_hooks(config_filename, config, arguments, global_arguments), borgmatic.hooks.command.Before_after_hooks( @@ -823,7 +823,7 @@ def collect_highlander_action_summary_logs(configs, arguments, configuration_par ''' add_custom_log_levels() - try: + try: # noqa: PLW0717 if 'bootstrap' in arguments: try: local_borg_version = borg_version.local_borg_version( diff --git a/borgmatic/logger.py b/borgmatic/logger.py index 09414615..28e5f423 100644 --- a/borgmatic/logger.py +++ b/borgmatic/logger.py @@ -109,7 +109,7 @@ class JournaldHandler(logging.Handler): def emit(self, record): sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) - try: + try: # noqa: PLW0717 message_parts = [] entry = dict( MESSAGE=record.getMessage(), diff --git a/tests/end-to-end/hooks/credential/test_container.py b/tests/end-to-end/hooks/credential/test_container.py index 6279f522..ea12fb21 100644 --- a/tests/end-to-end/hooks/credential/test_container.py +++ b/tests/end-to-end/hooks/credential/test_container.py @@ -40,7 +40,7 @@ def test_container_secret(): original_working_directory = os.getcwd() os.chdir(temporary_directory) - try: + try: # noqa: PLW0717 config_path = os.path.join(temporary_directory, 'test.yaml') generate_configuration(config_path, repository_path, secrets_directory=temporary_directory) diff --git a/tests/end-to-end/hooks/credential/test_file.py b/tests/end-to-end/hooks/credential/test_file.py index 0ae9b37a..6aa80f98 100644 --- a/tests/end-to-end/hooks/credential/test_file.py +++ b/tests/end-to-end/hooks/credential/test_file.py @@ -40,7 +40,7 @@ def test_file_credential(): original_working_directory = os.getcwd() os.chdir(temporary_directory) - try: + try: # noqa: PLW0717 config_path = os.path.join(temporary_directory, 'test.yaml') credential_path = os.path.join(temporary_directory, 'mycredential') generate_configuration(config_path, repository_path, credential_path) diff --git a/tests/end-to-end/hooks/credential/test_keepassxc.py b/tests/end-to-end/hooks/credential/test_keepassxc.py index e990458f..af02da7a 100644 --- a/tests/end-to-end/hooks/credential/test_keepassxc.py +++ b/tests/end-to-end/hooks/credential/test_keepassxc.py @@ -39,7 +39,7 @@ def test_keepassxc_password(): original_working_directory = os.getcwd() os.chdir(temporary_directory) - try: + try: # noqa: PLW0717 config_path = os.path.join(temporary_directory, 'test.yaml') generate_configuration(config_path, repository_path) diff --git a/tests/end-to-end/hooks/credential/test_systemd.py b/tests/end-to-end/hooks/credential/test_systemd.py index 375eb476..9710cdd0 100644 --- a/tests/end-to-end/hooks/credential/test_systemd.py +++ b/tests/end-to-end/hooks/credential/test_systemd.py @@ -38,7 +38,7 @@ def test_systemd_credential(): original_working_directory = os.getcwd() os.chdir(temporary_directory) - try: + try: # noqa: PLW0717 config_path = os.path.join(temporary_directory, 'test.yaml') generate_configuration(config_path, repository_path) diff --git a/tests/end-to-end/hooks/data_source/test_btrfs.py b/tests/end-to-end/hooks/data_source/test_btrfs.py index 15d8ec97..38773cde 100644 --- a/tests/end-to-end/hooks/data_source/test_btrfs.py +++ b/tests/end-to-end/hooks/data_source/test_btrfs.py @@ -35,7 +35,7 @@ def test_btrfs_create_and_list(): temporary_directory = tempfile.mkdtemp() repository_path = os.path.join(temporary_directory, 'test.borg') - try: + try: # noqa: PLW0717 config_path = os.path.join(temporary_directory, 'test.yaml') generate_configuration(config_path, repository_path) diff --git a/tests/end-to-end/hooks/data_source/test_database.py b/tests/end-to-end/hooks/data_source/test_database.py index aed8e0a7..32214198 100644 --- a/tests/end-to-end/hooks/data_source/test_database.py +++ b/tests/end-to-end/hooks/data_source/test_database.py @@ -443,7 +443,7 @@ def test_database_dump_and_restore(): original_working_directory = os.getcwd() - try: + try: # noqa: PLW0717 config_path = os.path.join(temporary_directory, 'test.yaml') config = write_configuration( temporary_directory, @@ -501,7 +501,7 @@ def test_database_dump_and_restore_with_restore_cli_flags(): original_working_directory = os.getcwd() - try: + try: # noqa: PLW0717 config_path = os.path.join(temporary_directory, 'test.yaml') config = write_simple_custom_restore_configuration( temporary_directory, @@ -582,7 +582,7 @@ def test_database_dump_and_restore_with_restore_configuration_options(): original_working_directory = os.getcwd() - try: + try: # noqa: PLW0717 config_path = os.path.join(temporary_directory, 'test.yaml') config = write_custom_restore_configuration( temporary_directory, @@ -641,7 +641,7 @@ def test_database_dump_and_restore_with_directory_format(): original_working_directory = os.getcwd() - try: + try: # noqa: PLW0717 config_path = os.path.join(temporary_directory, 'test.yaml') config = write_configuration( temporary_directory, @@ -737,7 +737,7 @@ def test_database_dump_and_restore_containers(): os.environ['PATH'] = f'/app/tests/end-to-end/commands:{original_path}' - try: + try: # noqa: PLW0717 config_path = os.path.join(temporary_directory, 'test.yaml') config = write_container_configuration( temporary_directory, diff --git a/tests/end-to-end/hooks/data_source/test_lvm.py b/tests/end-to-end/hooks/data_source/test_lvm.py index 5d30f869..dd9895c9 100644 --- a/tests/end-to-end/hooks/data_source/test_lvm.py +++ b/tests/end-to-end/hooks/data_source/test_lvm.py @@ -41,7 +41,7 @@ def test_lvm_create_and_list(): temporary_directory = tempfile.mkdtemp() repository_path = os.path.join(temporary_directory, 'test.borg') - try: + try: # noqa: PLW0717 config_path = os.path.join(temporary_directory, 'test.yaml') generate_configuration(config_path, repository_path) diff --git a/tests/end-to-end/hooks/data_source/test_zfs.py b/tests/end-to-end/hooks/data_source/test_zfs.py index 8f750e62..186f5575 100644 --- a/tests/end-to-end/hooks/data_source/test_zfs.py +++ b/tests/end-to-end/hooks/data_source/test_zfs.py @@ -37,7 +37,7 @@ def test_zfs_create_and_list(): temporary_directory = tempfile.mkdtemp() repository_path = os.path.join(temporary_directory, 'test.borg') - try: + try: # noqa: PLW0717 config_path = os.path.join(temporary_directory, 'test.yaml') generate_configuration(config_path, repository_path) diff --git a/tests/end-to-end/hooks/monitoring/test_monitoring.py b/tests/end-to-end/hooks/monitoring/test_monitoring.py index ec5b7b5c..7b40d836 100644 --- a/tests/end-to-end/hooks/monitoring/test_monitoring.py +++ b/tests/end-to-end/hooks/monitoring/test_monitoring.py @@ -129,7 +129,7 @@ def test_borgmatic_command(monitoring_hook_configuration, expected_request_count os.mkdir(extract_path) os.chdir(extract_path) - try: + try: # noqa: PLW0717 config_path = os.path.join(temporary_directory, 'test.yaml') generate_configuration(config_path, repository_path, monitoring_hook_configuration) diff --git a/tests/end-to-end/test_borgmatic.py b/tests/end-to-end/test_borgmatic.py index 766c39a9..51d87ae6 100644 --- a/tests/end-to-end/test_borgmatic.py +++ b/tests/end-to-end/test_borgmatic.py @@ -76,7 +76,7 @@ def test_borgmatic_command(generate_configuration): os.mkdir(extract_path) os.chdir(extract_path) - try: + try: # noqa: PLW0717 config_path = os.path.join(temporary_directory, 'test.yaml') generate_configuration(config_path, repository_path) diff --git a/tests/end-to-end/test_environment_variable.py b/tests/end-to-end/test_environment_variable.py index 83d87e8e..f91356d2 100644 --- a/tests/end-to-end/test_environment_variable.py +++ b/tests/end-to-end/test_environment_variable.py @@ -44,7 +44,7 @@ def test_borgmatic_command(): os.chdir(extract_path) environment = dict(os.environ, PASSPHRASE='test') - try: + try: # noqa: PLW0717 config_path = os.path.join(temporary_directory, 'test.yaml') generate_configuration(config_path, repository_path) diff --git a/tests/end-to-end/test_passcommand.py b/tests/end-to-end/test_passcommand.py index d650d82d..aeb61176 100644 --- a/tests/end-to-end/test_passcommand.py +++ b/tests/end-to-end/test_passcommand.py @@ -40,7 +40,7 @@ def test_borgmatic_command(): os.mkdir(extract_path) os.chdir(extract_path) - try: + try: # noqa: PLW0717 config_path = os.path.join(temporary_directory, 'test.yaml') generate_configuration(config_path, repository_path) diff --git a/tests/integration/actions/browse/test_app.py b/tests/integration/actions/browse/test_app.py index 8e620eac..a1ba36e5 100644 --- a/tests/integration/actions/browse/test_app.py +++ b/tests/integration/actions/browse/test_app.py @@ -1,11 +1,10 @@ +from flexmock import flexmock + import borgmatic.actions.browse.app import borgmatic.actions.browse.configuration_files_list import borgmatic.actions.browse.logs import borgmatic.actions.browse.repositories_list -import pytest -from flexmock import flexmock - async def test_browse_app_with_multiple_configs_uses_configuration_files_list(): app = borgmatic.actions.browse.app.Browse_app( @@ -16,9 +15,8 @@ async def test_browse_app_with_multiple_configs_uses_configuration_files_list(): ) flexmock(borgmatic.actions.browse.logs).should_receive('log_to_widget') - async with app.run_test() as pilot: - header = app.query_one(selector='Header') - header.name == 'borgmatic browse' + async with app.run_test(): + app.query_one(selector='Header') carousel = app.query_one(selector='Carousel') assert len(carousel.panels) == 1 @@ -40,9 +38,8 @@ async def test_browse_app_with_one_config_uses_repositories_list(): ) flexmock(borgmatic.actions.browse.logs).should_receive('log_to_widget') - async with app.run_test() as pilot: - header = app.query_one(selector='Header') - header.name == 'borgmatic browse' + async with app.run_test(): + app.query_one(selector='Header') carousel = app.query_one(selector='Carousel') assert len(carousel.panels) == 1 diff --git a/tests/integration/actions/browse/test_archives_list.py b/tests/integration/actions/browse/test_archives_list.py index ad28146f..d5839274 100644 --- a/tests/integration/actions/browse/test_archives_list.py +++ b/tests/integration/actions/browse/test_archives_list.py @@ -1,8 +1,8 @@ -from borgmatic.actions.browse import archives_list as module - -from flexmock import flexmock import textual.app import textual.widgets.option_list +from flexmock import flexmock + +from borgmatic.actions.browse import archives_list as module async def test_archives_list_on_mount_does_not_raise(): @@ -11,7 +11,7 @@ async def test_archives_list_on_mount_does_not_raise(): archives_list = module.Archives_list(config=flexmock(), repository=flexmock()) flexmock(archives_list.archive_loaded).should_receive('subscribe') - async with textual.app.App().run_test() as pilot: + async with textual.app.App().run_test(): archives_list.on_mount() @@ -63,7 +63,7 @@ def test_archives_list_on_option_list_option_highlighted_with_highlighted_zero_m assert archives_list.highlighted_option_changed is False -def test_archives_list_on_option_list_option_highlighted_with_highlighted_zero_marks_it_unchanged(): +def test_archives_list_on_option_list_option_highlighted_with_existing_option_and_highlighted_zero_marks_it_unchanged(): flexmock(module.borgmatic.actions.browse.loading).should_receive('add_inline_loading_indicator') archives_list = module.Archives_list(config=flexmock(), repository=flexmock()) diff --git a/tests/integration/actions/browse/test_carousel.py b/tests/integration/actions/browse/test_carousel.py index 438eeccc..2dfd2190 100644 --- a/tests/integration/actions/browse/test_carousel.py +++ b/tests/integration/actions/browse/test_carousel.py @@ -1,15 +1,13 @@ +import pytest +import textual.widgets.option_list +from flexmock import flexmock + import borgmatic.actions.browse.app import borgmatic.actions.browse.archive import borgmatic.actions.browse.carousel import borgmatic.actions.browse.loading import borgmatic.actions.browse.logs import borgmatic.actions.browse.workers - -import pytest -import pytest_asyncio -from flexmock import flexmock - -import textual.widgets.option_list from borgmatic.actions.browse import carousel as module @@ -392,7 +390,7 @@ async def test_carousel_next_action_and_previous_action_and_next_action_reuses_n assert app.focused == carousel.panels[1] -async def test_carousel_next_action_with_no_next_panel_does_not_advance(): +async def test_carousel_next_action_with_multiple_configs_and_no_next_panel_does_not_advance(): app = borgmatic.actions.browse.app.Browse_app( configs={ 'test1.yaml': {'repositories': [{'path': 'test1.borg'}]}, @@ -400,7 +398,7 @@ async def test_carousel_next_action_with_no_next_panel_does_not_advance(): } ) flexmock(borgmatic.actions.browse.logs).should_receive('log_to_widget') - flexmock(borgmatic.actions.browse.carousel).should_receive('make_next_panel').and_return(None) + flexmock(module).should_receive('make_next_panel').and_return(None) async with app.run_test() as pilot: await pilot.press('enter') diff --git a/tests/integration/actions/browse/test_configuration_files_list.py b/tests/integration/actions/browse/test_configuration_files_list.py index 1b657bc4..204cef5f 100644 --- a/tests/integration/actions/browse/test_configuration_files_list.py +++ b/tests/integration/actions/browse/test_configuration_files_list.py @@ -1,7 +1,7 @@ -from borgmatic.actions.browse import configuration_files_list as module - from flexmock import flexmock +from borgmatic.actions.browse import configuration_files_list as module + def test_configuration_files_list_adds_config_paths_as_options(): flexmock(module.os.path).should_receive('expanduser').and_return('/home/user') diff --git a/tests/integration/actions/browse/test_directory_list.py b/tests/integration/actions/browse/test_directory_list.py index 5b72b5af..103d0f4f 100644 --- a/tests/integration/actions/browse/test_directory_list.py +++ b/tests/integration/actions/browse/test_directory_list.py @@ -1,8 +1,8 @@ -from borgmatic.actions.browse import directory_list as module - -from flexmock import flexmock import textual.widgets import textual.widgets.option_list +from flexmock import flexmock + +from borgmatic.actions.browse import directory_list as module def test_add_archive_paths_with_only_duplicate_paths_bails(): diff --git a/tests/integration/actions/browse/test_file_preview.py b/tests/integration/actions/browse/test_file_preview.py index f35ff1b2..cebf1787 100644 --- a/tests/integration/actions/browse/test_file_preview.py +++ b/tests/integration/actions/browse/test_file_preview.py @@ -1,7 +1,7 @@ -from borgmatic.actions.browse import file_preview as module - -from flexmock import flexmock import textual.widgets.option_list +from flexmock import flexmock + +from borgmatic.actions.browse import file_preview as module def test_file_preview_does_not_raise(): @@ -20,26 +20,34 @@ async def test_file_preview_on_mount_does_not_raise(): ) flexmock(file_preview.file_preview_loaded).should_receive('subscribe') - async with textual.app.App().run_test() as pilot: + async with textual.app.App().run_test(): file_preview.on_mount() def test_file_preview_on_file_preview_loaded_with_none_file_contents_displays_error(): - flexmock(module.borgmatic.actions.browse.loading).should_receive('add_inline_loading_indicator').and_return(flexmock(stop=lambda: None)) + flexmock(module.borgmatic.actions.browse.loading).should_receive( + 'add_inline_loading_indicator' + ).and_return(flexmock(stop=lambda: None)) file_preview = module.File_preview( config=flexmock(), repository=flexmock(), archive_name='archive', file_path='foo.txt' ) - flexmock(file_preview).should_receive('write').with_args('Cannot display a preview for this file').once() + flexmock(file_preview).should_receive('write').with_args( + 'Cannot display a preview for this file' + ).once() file_preview.on_file_preview_loaded(None) def test_file_preview_on_file_preview_loaded_with_file_contents_displays_contents(): - flexmock(module.borgmatic.actions.browse.loading).should_receive('add_inline_loading_indicator').and_return(flexmock(stop=lambda: None)) + flexmock(module.borgmatic.actions.browse.loading).should_receive( + 'add_inline_loading_indicator' + ).and_return(flexmock(stop=lambda: None)) file_preview = module.File_preview( config=flexmock(), repository=flexmock(), archive_name='archive', file_path='foo.txt' ) - flexmock(file_preview).should_receive('write').with_args('Cannot display a preview for this file').never() + flexmock(file_preview).should_receive('write').with_args( + 'Cannot display a preview for this file' + ).never() flexmock(file_preview).should_receive('write').once() file_preview.on_file_preview_loaded('hi') diff --git a/tests/integration/actions/browse/test_loading.py b/tests/integration/actions/browse/test_loading.py index 0d4d12d9..b7f6e12c 100644 --- a/tests/integration/actions/browse/test_loading.py +++ b/tests/integration/actions/browse/test_loading.py @@ -1,9 +1,9 @@ -from borgmatic.actions.browse import loading as module - -from flexmock import flexmock import pytest import textual.app import textual.widgets +from flexmock import flexmock + +from borgmatic.actions.browse import loading as module def test_update_inline_loading_indicator_with_option_list_adds_a_dot(): @@ -35,7 +35,7 @@ def test_update_inline_loading_indicator_with_option_list_and_missing_indicator_ async def test_update_inline_loading_indicator_with_rich_log_adds_a_dot(): - async with textual.app.App().run_test() as pilot: + async with textual.app.App().run_test(): widget = textual.widgets.RichLog() widget._size_known = True widget.write('HOLD.') @@ -46,7 +46,7 @@ async def test_update_inline_loading_indicator_with_rich_log_adds_a_dot(): async def test_update_inline_loading_indicator_with_rich_log_wraps_dots_beyond_three(): - async with textual.app.App().run_test() as pilot: + async with textual.app.App().run_test(): widget = textual.widgets.RichLog() widget._size_known = True widget.write('HOLD...') @@ -82,7 +82,7 @@ def test_add_inline_loading_indicator_with_option_list_adds_loading_indicator_op async def test_add_inline_loading_indicator_with_rich_log_writes_loading_indicator_text(): - async with textual.app.App().run_test() as pilot: + async with textual.app.App().run_test(): widget = textual.widgets.RichLog() widget._size_known = True flexmock(widget).should_receive('set_interval') diff --git a/tests/integration/actions/browse/test_logs.py b/tests/integration/actions/browse/test_logs.py index 7ccd3e59..6149cca5 100644 --- a/tests/integration/actions/browse/test_logs.py +++ b/tests/integration/actions/browse/test_logs.py @@ -1,9 +1,9 @@ import contextlib -from borgmatic.actions.browse import logs as module - from flexmock import flexmock +from borgmatic.actions.browse import logs as module + def test_log_to_widget_adds_our_handler_and_removes_default_handler(): default_handler = module.borgmatic.logger.Multi_stream_handler({}) diff --git a/tests/integration/actions/browse/test_repositories_list.py b/tests/integration/actions/browse/test_repositories_list.py index b0916554..7786c53d 100644 --- a/tests/integration/actions/browse/test_repositories_list.py +++ b/tests/integration/actions/browse/test_repositories_list.py @@ -1,7 +1,5 @@ from borgmatic.actions.browse import repositories_list as module -from flexmock import flexmock - def test_repositories_list_populates_options(): config = {'repositories': [{'path': 'test1.borg'}, {'path': 'test2.borg', 'label': 'two'}]} diff --git a/tests/unit/actions/browse/test_directory_list.py b/tests/unit/actions/browse/test_directory_list.py index 76f8a1f6..5767a2f4 100644 --- a/tests/unit/actions/browse/test_directory_list.py +++ b/tests/unit/actions/browse/test_directory_list.py @@ -1,7 +1,7 @@ -from borgmatic.actions.browse import directory_list as module - from flexmock import flexmock +from borgmatic.actions.browse import directory_list as module + def test_get_relative_archive_path_components_strips_off_current_directory(): assert module.get_relative_archive_path_components( diff --git a/tests/unit/actions/browse/test_logs.py b/tests/unit/actions/browse/test_logs.py index b59526f7..583b81a9 100644 --- a/tests/unit/actions/browse/test_logs.py +++ b/tests/unit/actions/browse/test_logs.py @@ -1,7 +1,7 @@ -from borgmatic.actions.browse import logs as module - from flexmock import flexmock +from borgmatic.actions.browse import logs as module + def test_rich_color_formatter_format_colors_log_record_based_on_level(): formatted = module.Rich_color_formatter().format( diff --git a/tests/unit/actions/browse/test_run.py b/tests/unit/actions/browse/test_run.py index 0febc13f..6b451273 100644 --- a/tests/unit/actions/browse/test_run.py +++ b/tests/unit/actions/browse/test_run.py @@ -1,7 +1,7 @@ from flexmock import flexmock -from borgmatic.actions.browse import run as module import borgmatic.actions.browse.app +from borgmatic.actions.browse import run as module def test_run_browse_without_configs_bails(): diff --git a/tests/unit/borg/test_diff.py b/tests/unit/borg/test_diff.py index c8b3663f..70d3a7db 100644 --- a/tests/unit/borg/test_diff.py +++ b/tests/unit/borg/test_diff.py @@ -3,6 +3,7 @@ import logging from flexmock import flexmock from borgmatic.borg import diff as module + from ..test_verbosity import insert_logging_mock LOGGING_ANSWER = flexmock()