mirror of
https://github.com/borgmatic-collective/borgmatic.git
synced 2026-07-22 02:03:01 +02:00
Add additional tests.
This commit is contained in:
@@ -13,6 +13,10 @@ logger = logging.getLogger('__name__')
|
||||
|
||||
|
||||
def update_inline_loading_indicator(widget):
|
||||
'''
|
||||
Given a textual.widgets.OptionList or a textual.widgets.RichLog instance, animate the existing
|
||||
loading indicator inside it.
|
||||
'''
|
||||
if isinstance(widget, textual.widgets.OptionList):
|
||||
with contextlib.suppress(textual.widgets.option_list.OptionDoesNotExist):
|
||||
widget.replace_option_prompt(
|
||||
@@ -28,15 +32,20 @@ def update_inline_loading_indicator(widget):
|
||||
raise ValueError(f'Unsupported widget type: {type(widget)}')
|
||||
|
||||
|
||||
def add_inline_loading_indicator(widget):
|
||||
loading_message = '⏳ loading...'
|
||||
LOADING_MESSAGE = '⏳ loading...'
|
||||
|
||||
|
||||
def add_inline_loading_indicator(widget):
|
||||
'''
|
||||
Given a textual.widgets.OptionList or a textual.widgets.RichLog instance, add a loading
|
||||
indicator to it.
|
||||
'''
|
||||
if isinstance(widget, textual.widgets.OptionList):
|
||||
loading_option = textual.widgets.option_list.Option(loading_message, id='loading-indicator')
|
||||
loading_option = textual.widgets.option_list.Option(LOADING_MESSAGE, id='loading-indicator')
|
||||
widget.add_option(loading_option)
|
||||
widget.highlighted = None
|
||||
elif isinstance(widget, textual.widgets.RichLog):
|
||||
widget.write(loading_message)
|
||||
widget.write(LOADING_MESSAGE)
|
||||
else:
|
||||
raise ValueError(f'Unsupported widget type: {type(widget)}')
|
||||
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
from borgmatic.actions.browse import loading as module
|
||||
|
||||
from flexmock import flexmock
|
||||
import pytest
|
||||
import textual.app
|
||||
import textual.widgets
|
||||
|
||||
|
||||
def test_update_inline_loading_indicator_with_option_list_adds_a_dot():
|
||||
widget = textual.widgets.OptionList()
|
||||
widget.add_option(
|
||||
textual.widgets.option_list.Option('HOLD.', id='loading-indicator')
|
||||
)
|
||||
|
||||
module.update_inline_loading_indicator(widget)
|
||||
|
||||
assert len(widget.options) == 1
|
||||
assert widget.options[0].prompt == 'HOLD..'
|
||||
|
||||
|
||||
def test_update_inline_loading_indicator_with_option_list_wraps_dots_beyond_three():
|
||||
widget = textual.widgets.OptionList()
|
||||
widget.add_option(
|
||||
textual.widgets.option_list.Option('HOLD...', id='loading-indicator')
|
||||
)
|
||||
|
||||
module.update_inline_loading_indicator(widget)
|
||||
|
||||
assert len(widget.options) == 1
|
||||
assert widget.options[0].prompt == 'HOLD'
|
||||
|
||||
|
||||
def test_update_inline_loading_indicator_with_option_list_and_missing_indicator_does_not_raise():
|
||||
widget = textual.widgets.OptionList()
|
||||
|
||||
module.update_inline_loading_indicator(widget)
|
||||
|
||||
assert len(widget.options) == 0
|
||||
|
||||
|
||||
async def test_update_inline_loading_indicator_with_rich_log_adds_a_dot():
|
||||
async with textual.app.App().run_test() as pilot:
|
||||
widget = textual.widgets.RichLog()
|
||||
widget._size_known = True
|
||||
widget.write('HOLD.')
|
||||
|
||||
module.update_inline_loading_indicator(widget)
|
||||
|
||||
assert str(widget.lines[0].text) == 'HOLD..'
|
||||
|
||||
|
||||
async def test_update_inline_loading_indicator_with_rich_log_wraps_dots_beyond_three():
|
||||
async with textual.app.App().run_test() as pilot:
|
||||
widget = textual.widgets.RichLog()
|
||||
widget._size_known = True
|
||||
widget.write('HOLD...')
|
||||
|
||||
module.update_inline_loading_indicator(widget)
|
||||
|
||||
assert str(widget.lines[0].text) == 'HOLD'
|
||||
|
||||
|
||||
def test_update_inline_loading_indicator_with_rich_log_and_missing_indicator_does_not_raise():
|
||||
widget = textual.widgets.RichLog()
|
||||
|
||||
module.update_inline_loading_indicator(widget)
|
||||
|
||||
assert len(widget.lines) == 0
|
||||
|
||||
|
||||
def test_update_inline_loading_indicator_with_unsupported_widget_type_raises():
|
||||
with pytest.raises(ValueError):
|
||||
module.update_inline_loading_indicator(flexmock())
|
||||
|
||||
|
||||
def test_add_inline_loading_indicator_with_option_list_adds_loading_indicator_option():
|
||||
widget = textual.widgets.OptionList()
|
||||
flexmock(widget).should_receive('set_interval')
|
||||
|
||||
module.add_inline_loading_indicator(widget)
|
||||
|
||||
assert len(widget.options) == 1
|
||||
assert widget.options[0].prompt == module.LOADING_MESSAGE
|
||||
assert widget.options[0].id == 'loading-indicator'
|
||||
assert widget.highlighted is None
|
||||
|
||||
|
||||
async def test_add_inline_loading_indicator_with_rich_log_writes_loading_indicator_text():
|
||||
async with textual.app.App().run_test() as pilot:
|
||||
widget = textual.widgets.RichLog()
|
||||
widget._size_known = True
|
||||
flexmock(widget).should_receive('set_interval')
|
||||
|
||||
module.add_inline_loading_indicator(widget)
|
||||
|
||||
assert str(widget.lines[0].text) == module.LOADING_MESSAGE
|
||||
|
||||
|
||||
def test_add_inline_loading_indicator_with_unsupported_widget_type_raises():
|
||||
with pytest.raises(ValueError):
|
||||
module.add_inline_loading_indicator(flexmock())
|
||||
Reference in New Issue
Block a user