Complete tests.

This commit is contained in:
Dan Helfman
2026-06-01 11:54:28 -07:00
parent ec8e52944c
commit 5accda1a65
39 changed files with 136 additions and 146 deletions
@@ -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)
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
+6 -9
View File
@@ -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(
+2 -2
View File
@@ -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 -1
View File
@@ -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():
+1
View File
@@ -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()