More tests.

This commit is contained in:
Dan Helfman
2026-05-30 13:58:04 -07:00
parent 3a4bdfb3c5
commit f832a361ed
2 changed files with 43 additions and 0 deletions
@@ -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('~')
@@ -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'