
* upgrade to latest ruff * try to fix dep review * try to fix dep review (2) * upgrade black * upgrade black (2) * update allowed dependencies * update allowed dependencies (2) * update allowed dependencies (3) * wait between interim and final in yield test * remove previous commit, increase delay between yield * forgot to save on the time.sleep(1) removal * fix integration (maybe?) * fix pyi? * what even is going on * what is realityi? * test another fix for app harness * try to wait even longer? * force uvloop to be optional * downpin fastapi < 0.111, remove changes to test
78 lines
1.6 KiB
Python
78 lines
1.6 KiB
Python
"""Test shared state."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Generator
|
|
|
|
import pytest
|
|
|
|
from reflex.testing import AppHarness, WebDriver
|
|
|
|
|
|
def SharedStateApp():
|
|
"""Test that shared state works as expected."""
|
|
import reflex as rx
|
|
from integration.shared.state import SharedState
|
|
|
|
class State(SharedState):
|
|
pass
|
|
|
|
def index() -> rx.Component:
|
|
return rx.vstack()
|
|
|
|
app = rx.App()
|
|
app.add_page(index)
|
|
|
|
|
|
@pytest.fixture
|
|
def shared_state(
|
|
tmp_path_factory,
|
|
) -> Generator[AppHarness, None, None]:
|
|
"""Start SharedStateApp at tmp_path via AppHarness.
|
|
|
|
Args:
|
|
tmp_path_factory: pytest tmp_path_factory fixture
|
|
|
|
Yields:
|
|
running AppHarness instance
|
|
|
|
"""
|
|
with AppHarness.create(
|
|
root=tmp_path_factory.mktemp("shared_state"),
|
|
app_source=SharedStateApp, # type: ignore
|
|
) as harness:
|
|
yield harness
|
|
|
|
|
|
@pytest.fixture
|
|
def driver(shared_state: AppHarness) -> Generator[WebDriver, None, None]:
|
|
"""Get an instance of the browser open to the shared_state app.
|
|
|
|
Args:
|
|
shared_state: harness for SharedStateApp
|
|
|
|
Yields:
|
|
WebDriver instance.
|
|
|
|
"""
|
|
assert shared_state.app_instance is not None, "app is not running"
|
|
driver = shared_state.frontend()
|
|
try:
|
|
yield driver
|
|
finally:
|
|
driver.quit()
|
|
|
|
|
|
def test_shared_state(
|
|
shared_state: AppHarness,
|
|
driver: WebDriver,
|
|
):
|
|
"""Test that 2 AppHarness instances can share a state (f.e. from a library).
|
|
|
|
Args:
|
|
shared_state: harness for SharedStateApp.
|
|
driver: WebDriver instance.
|
|
|
|
"""
|
|
assert shared_state.app_instance is not None
|