mirror of
https://github.com/borgmatic-collective/borgmatic.git
synced 2026-07-22 02:03:01 +02:00
Complete tests.
This commit is contained in:
@@ -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'])):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import textual.binding
|
||||
import textual.widgets
|
||||
|
||||
|
||||
OPTION_LIST_BINDINGS = (
|
||||
*textual.widgets.OptionList.BINDINGS,
|
||||
textual.binding.Binding(
|
||||
|
||||
@@ -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
|
||||
]
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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: '🔗',
|
||||
|
||||
@@ -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__')
|
||||
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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(
|
||||
|
||||
+1
-1
@@ -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(),
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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({})
|
||||
|
||||
@@ -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'}]}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user