From f832a361edcdc21b5edd1c108546dd4f66f41b2d Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sat, 30 May 2026 13:58:04 -0700 Subject: [PATCH] More tests. --- .../browse/configuration_files_list.py | 9 +++++ .../browse/test_configuration_files_list.py | 34 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/integration/actions/browse/test_configuration_files_list.py diff --git a/borgmatic/actions/browse/configuration_files_list.py b/borgmatic/actions/browse/configuration_files_list.py index c6da1390..95920ea9 100644 --- a/borgmatic/actions/browse/configuration_files_list.py +++ b/borgmatic/actions/browse/configuration_files_list.py @@ -10,9 +10,18 @@ import borgmatic.actions.browse.workers class Configuration_files_list(textual.widgets.OptionList): + ''' + A widget for selecting a single borgmatic configuration file from among available configuration + files. The item selection event is handled in a Carousel instance, the parent widget of an + Configuration_files_list. + ''' BINDINGS = borgmatic.actions.browse.bindings.OPTION_LIST_BINDINGS def __init__(self, configs): + ''' + Given a dict mapping from configuration path to corresponding configuration dict, add each + configuration path as an option to this widget. + ''' self.configs = configs home_directory = os.path.expanduser('~') diff --git a/tests/integration/actions/browse/test_configuration_files_list.py b/tests/integration/actions/browse/test_configuration_files_list.py new file mode 100644 index 00000000..1b657bc4 --- /dev/null +++ b/tests/integration/actions/browse/test_configuration_files_list.py @@ -0,0 +1,34 @@ +from borgmatic.actions.browse import configuration_files_list as module + +from flexmock import flexmock + + +def test_configuration_files_list_adds_config_paths_as_options(): + flexmock(module.os.path).should_receive('expanduser').and_return('/home/user') + + configuration_files_list = module.Configuration_files_list( + configs={ + 'test1.yaml': {'repositories': [{'path': 'test1.borg'}]}, + 'test2.yaml': {'repositories': [{'path': 'test2.borg'}]}, + } + ) + + assert len(configuration_files_list.options) == 2 + assert configuration_files_list.options[0].prompt == 'test1.yaml' + assert configuration_files_list.options[0].id == 'test1.yaml' + assert configuration_files_list.options[1].prompt == 'test2.yaml' + assert configuration_files_list.options[1].id == 'test2.yaml' + + +def test_configuration_files_list_collapses_home_directory_in_config_path_option(): + flexmock(module.os.path).should_receive('expanduser').and_return('/home/user') + + configuration_files_list = module.Configuration_files_list( + configs={ + '/home/user/test.yaml': {'repositories': [{'path': '/home/user/test.borg'}]}, + } + ) + + assert len(configuration_files_list.options) == 1 + assert configuration_files_list.options[0].prompt == '~/test.yaml' + assert configuration_files_list.options[0].id == '/home/user/test.yaml'