Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide tests for run.io_bound and run.cpu_bound #2234

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions tests/test_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import asyncio
import time
from typing import Awaitable, Generator, Optional

import pytest

from nicegui import app, run, ui
from nicegui.testing import Screen


@pytest.fixture(scope='module', autouse=True)
def check_blocking_ui() -> Generator[None, None, None]:
loop: Optional[asyncio.AbstractEventLoop] = None

def configure() -> None:
loop = asyncio.get_running_loop()
loop.set_debug(True)
loop.slow_callback_duration = 0.02
app.on_startup(configure)
app.on_shutdown(lambda: loop and loop.set_debug(False))
yield


def delayed_hello() -> str:
"""Test function that blocks for 1 second."""
time.sleep(1)
return 'hello'


@pytest.mark.parametrize('func', [run.cpu_bound, run.io_bound])
def test_delayed_hello(screen: Screen, func: Awaitable):

@ui.page('/')
async def index():
ui.label(await func(delayed_hello))

screen.open('/')
screen.should_contain('hello')
Loading