|
@@ -77,20 +77,6 @@ def test_setting_visibility(screen: Screen, once: bool):
|
|
screen.should_not_contain('Some Label')
|
|
screen.should_not_contain('Some Label')
|
|
|
|
|
|
|
|
|
|
-def test_awaiting_coroutine(screen: Screen):
|
|
|
|
- user = {'name': 'John Doe'}
|
|
|
|
-
|
|
|
|
- async def update_user():
|
|
|
|
- await asyncio.sleep(0.1)
|
|
|
|
- user['name'] = 'Jane Doe'
|
|
|
|
-
|
|
|
|
- ui.timer(1, update_user)
|
|
|
|
-
|
|
|
|
- screen.open('/')
|
|
|
|
- screen.wait(1)
|
|
|
|
- assert user['name'] == 'Jane Doe'
|
|
|
|
-
|
|
|
|
-
|
|
|
|
def test_timer_on_deleted_container(screen: Screen):
|
|
def test_timer_on_deleted_container(screen: Screen):
|
|
state = {'count': 0}
|
|
state = {'count': 0}
|
|
with ui.row() as outer_container:
|
|
with ui.row() as outer_container:
|
|
@@ -105,3 +91,27 @@ def test_timer_on_deleted_container(screen: Screen):
|
|
count = state['count']
|
|
count = state['count']
|
|
screen.wait(0.5)
|
|
screen.wait(0.5)
|
|
assert state['count'] == count, 'timer is not running anymore after deleting the container'
|
|
assert state['count'] == count, 'timer is not running anymore after deleting the container'
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def test_different_callbacks(screen: Screen):
|
|
|
|
+ def sync_function():
|
|
|
|
+ ui.label('a synchronous function')
|
|
|
|
+
|
|
|
|
+ async def async_function():
|
|
|
|
+ await asyncio.sleep(0.1)
|
|
|
|
+ ui.label('an asynchronous function')
|
|
|
|
+
|
|
|
|
+ async def async_lambda(msg: str):
|
|
|
|
+ await asyncio.sleep(0.1)
|
|
|
|
+ ui.label(f'an asynchronous lambda: {msg}')
|
|
|
|
+
|
|
|
|
+ ui.timer(0.1, sync_function, once=True)
|
|
|
|
+ ui.timer(0.1, async_function, once=True)
|
|
|
|
+ ui.timer(0.1, lambda: ui.label('a synchronous lambda'), once=True)
|
|
|
|
+ ui.timer(0.1, lambda: async_lambda('Hi!'), once=True)
|
|
|
|
+
|
|
|
|
+ screen.open('/')
|
|
|
|
+ screen.should_contain('a synchronous function')
|
|
|
|
+ screen.should_contain('an asynchronous function')
|
|
|
|
+ screen.should_contain('a synchronous lambda')
|
|
|
|
+ screen.should_contain('an asynchronous lambda: Hi!')
|