def test_update(): """We test the ProgressExt update method""" # Given progress = ProgressExt() # When progress.update( 20, "hello again", ) # Then assert progress.value == 20 assert progress.message == "hello again"
def test_view_none(): """We test the view with no message or value - No progressbar is shown - No message is shown """ progress = ProgressExt( value=0, message="", ) return TestApp( test_view_none, progress.view(), )
def test_view_value_only(): """We test the view with a value only - The progressbar is shown with a value of 50 - No message is shown """ progress = ProgressExt( value=50, message="", ) return TestApp( test_view_value_only, progress.view(), )
def test_reset(): """We test the ProgressExt reset method""" # Given progress = ProgressExt( value=10, message="hello world", bar_color="primary", ) # When progress.reset() # Then assert progress.value == 0 assert progress.message == "" assert progress.bar_color == "primary"
def test_view_message_only(): """We test the view with a message only - The progress bar is active with no value - The message is stated - The bar color is the blue *info* color """ progress = ProgressExt( value=0, message="hello world", ) return TestApp( test_view_message_only, progress.view(), )
def test_view_value_and_message(): """We test the view with a value and a message - The progress bar is active with the value 50 - The message hello world is visible - The bar color is the blue *info* color """ progress = ProgressExt( value=50, message="hello world", ) return TestApp( test_view_value_and_message, progress.view(), )
def test_bar_color(): """We test the view with a value and a message - The progress bar is active with the value 50 - The message hello world is visible - The bar color is the green *success* color """ progress = ProgressExt( value=50, message="hello world", bar_color="success", ) return TestApp( test_bar_color, progress.view(), )
def test_constructor(): """We test the ProgressExt constructor""" # When progress = ProgressExt( value=10, message="hello world", bar_color="primary", ) # Then assert progress.value == 10 assert progress.message == "hello world" assert progress.bar_color == "primary"
def test_increment_as_decorator(): """We test that the `ProgressExt.report` function works as a context manager - Click the button multiple times and check that the progress is reset every 2 clicks """ progress = ProgressExt() run_button = pn.widgets.Button(name="Click me") @progress.increment( 50, "incrementing ...", ) def run(event, ): # pylint: disable=unused-argument time.sleep(0.5) run_button.on_click(run) return TestApp( test_increment_as_decorator, run_button, progress.view, )
def test_report_as_decorator(): """We test that the `ProgressExt.report` function works as a decorator - Click the button to see the progress reported for 1 secs """ progress = ProgressExt() run_button = pn.widgets.Button(name="Click me") @progress.report( 33, "calculation", ) def run(event, ): # pylint: disable=unused-argument time.sleep(1) run_button.on_click(run) return TestApp( test_report_as_decorator, run_button, progress.view, )
def test_report_as_context_manager(): """We test that the `ProgressExt.report` function works as a context manager - Click the button to see the progress reported for 1 secs """ progress = ProgressExt() run_button = pn.widgets.Button(name="Click me") def run(event, ): # pylint: disable=unused-argument with progress.report( 50, "running", ): time.sleep(1) run_button.on_click(run) return TestApp( test_report_as_context_manager, run_button, progress.view, )
"""In this module we define a view to report progress Use the `report` and `increment` methods of `progress` to report your progress and then include `progress.view` in your app. """ from awesome_panel.express import ProgressExt progress = ProgressExt() # pylint: disable=invalid-name