mirror of
https://github.com/borgmatic-collective/borgmatic.git
synced 2026-07-22 02:03:01 +02:00
More tests!
This commit is contained in:
@@ -40,8 +40,8 @@ class Archives_list(textual.widgets.OptionList):
|
||||
When this widget gets mounted in the DOM, subscribe to archive loaded events so that we can
|
||||
find out about archives as they load. Also start loading archives from the repository.
|
||||
|
||||
Loading is started *after* subscribing to archive loaded signals so that there's not a gap
|
||||
where we might miss out on signal publishes.
|
||||
Loading is started *after* subscribing to the archive loaded signal so that there's not a
|
||||
gap where we might miss out on signal publishes.
|
||||
'''
|
||||
self.archive_loaded.subscribe(self, self.on_archive_loaded)
|
||||
|
||||
|
||||
@@ -59,8 +59,8 @@ class File_preview(textual.widgets.RichLog):
|
||||
When this widget gets mounted in the DOM, subscribe to archive loaded events so that we can
|
||||
find out about archives as they load. Also start loading file contents from the archive.
|
||||
|
||||
Loading is started *after* subscribing to file preview loaded signals so that there's not a
|
||||
gap where we might miss out on signal publishes.
|
||||
Loading is started *after* subscribing to the file preview loaded signal so that there's not
|
||||
a gap where we might miss out on signal publishes.
|
||||
'''
|
||||
self.file_preview_loaded.subscribe(self, self.on_file_preview_loaded)
|
||||
|
||||
@@ -75,6 +75,9 @@ class File_preview(textual.widgets.RichLog):
|
||||
)
|
||||
|
||||
def on_file_preview_loaded(self, file_contents):
|
||||
'''
|
||||
When a file loads, write its contents (syntax highlighted) to this file preview widget.
|
||||
'''
|
||||
self.loading_timer.stop()
|
||||
self.clear()
|
||||
|
||||
|
||||
@@ -42,6 +42,13 @@ change that last line to:
|
||||
uv tool install --editable .[dev,Apprise]
|
||||
```
|
||||
|
||||
Or to work on the [browse
|
||||
action](https://torsion.org/borgmatic/reference/command-line/actions/browse/):
|
||||
|
||||
```bash
|
||||
uv tool install --editable .[dev,browse]
|
||||
```
|
||||
|
||||
To get oriented with the borgmatic source code, have a look at the [source
|
||||
code reference](https://torsion.org/borgmatic/reference/source-code/).
|
||||
|
||||
|
||||
@@ -1,9 +1,48 @@
|
||||
from borgmatic.actions.browse import archives_list as module
|
||||
|
||||
from flexmock import flexmock
|
||||
import textual.app
|
||||
import textual.widgets.option_list
|
||||
|
||||
|
||||
async def test_archives_list_on_mount_does_not_raise():
|
||||
flexmock(module.borgmatic.actions.browse.loading).should_receive('add_inline_loading_indicator')
|
||||
flexmock(module.borgmatic.actions.browse.workers).should_receive('add_repository_archives')
|
||||
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:
|
||||
archives_list.on_mount()
|
||||
|
||||
|
||||
def test_archives_list_on_archive_loaded_with_loading_done_removes_loading_indicator():
|
||||
loading_timer = flexmock()
|
||||
flexmock(module.borgmatic.actions.browse.loading).should_receive(
|
||||
'add_inline_loading_indicator'
|
||||
).and_return(loading_timer)
|
||||
archives_list = module.Archives_list(config=flexmock(), repository=flexmock())
|
||||
flexmock(loading_timer).should_receive('stop')
|
||||
flexmock(archives_list).should_receive('remove_option').with_args('loading-indicator').once()
|
||||
flexmock(archives_list).should_receive('add_options').never()
|
||||
|
||||
archives_list.on_archive_loaded(module.borgmatic.actions.browse.workers.LOADING_DONE)
|
||||
|
||||
|
||||
def test_archives_list_on_archive_loaded_adds_archive_name():
|
||||
loading_timer = flexmock()
|
||||
flexmock(module.borgmatic.actions.browse.loading).should_receive(
|
||||
'add_inline_loading_indicator'
|
||||
).and_return(loading_timer)
|
||||
archives_list = module.Archives_list(config=flexmock(), repository=flexmock())
|
||||
flexmock(loading_timer).should_receive('stop').never()
|
||||
loading_indicator = flexmock()
|
||||
flexmock(archives_list).should_receive('get_option').and_return(loading_indicator)
|
||||
flexmock(archives_list).should_receive('remove_option').with_args('loading-indicator').once()
|
||||
flexmock(archives_list).should_receive('add_options').once()
|
||||
|
||||
archives_list.on_archive_loaded('archive')
|
||||
|
||||
|
||||
def test_archives_list_on_option_list_option_highlighted_with_highlighted_none_marks_it_unchanged():
|
||||
flexmock(module.borgmatic.actions.browse.loading).should_receive('add_inline_loading_indicator')
|
||||
|
||||
|
||||
@@ -10,3 +10,36 @@ def test_file_preview_does_not_raise():
|
||||
module.File_preview(
|
||||
config=flexmock(), repository=flexmock(), archive_name='archive', file_path='foo/bar.txt'
|
||||
)
|
||||
|
||||
|
||||
async def test_file_preview_on_mount_does_not_raise():
|
||||
flexmock(module.borgmatic.actions.browse.loading).should_receive('add_inline_loading_indicator')
|
||||
flexmock(module.borgmatic.actions.browse.workers).should_receive('load_file_preview')
|
||||
file_preview = module.File_preview(
|
||||
config=flexmock(), repository=flexmock(), archive_name='archive', file_path='foo.txt'
|
||||
)
|
||||
flexmock(file_preview.file_preview_loaded).should_receive('subscribe')
|
||||
|
||||
async with textual.app.App().run_test() as pilot:
|
||||
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))
|
||||
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()
|
||||
|
||||
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))
|
||||
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').once()
|
||||
|
||||
file_preview.on_file_preview_loaded('hi')
|
||||
|
||||
Reference in New Issue
Block a user