Skip to content

Commit

Permalink
addded backend exception handler to reflex.app._process
Browse files Browse the repository at this point in the history
  • Loading branch information
maximvlah committed Jun 25, 2024
1 parent c68c428 commit 6cd628f
Show file tree
Hide file tree
Showing 298 changed files with 1,765 additions and 36 deletions.
1 change: 1 addition & 0 deletions benchmarks/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ def app_harness_env(request):
Returns:
The AppHarness class to use for the test.
"""
return request.param
10 changes: 10 additions & 0 deletions benchmarks/test_benchmark_compile_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def render_component(num: int):
Returns:
The rendered number of components.
"""
import reflex as rx

Expand Down Expand Up @@ -156,6 +157,7 @@ def app_with_10_components(
Yields:
running AppHarness instance
"""
root = tmp_path_factory.mktemp("app10components")

Expand All @@ -179,6 +181,7 @@ def app_with_100_components(
Yields:
running AppHarness instance
"""
root = tmp_path_factory.mktemp("app100components")

Expand All @@ -202,6 +205,7 @@ def app_with_1000_components(
Yields:
an AppHarness instance
"""
root = tmp_path_factory.mktemp("app1000components")

Expand All @@ -227,6 +231,7 @@ def test_app_10_compile_time_cold(benchmark, app_with_10_components):
Args:
benchmark: The benchmark fixture.
app_with_10_components: The app harness.
"""

def setup():
Expand Down Expand Up @@ -255,6 +260,7 @@ def test_app_10_compile_time_warm(benchmark, app_with_10_components):
Args:
benchmark: The benchmark fixture.
app_with_10_components: The app harness.
"""
with chdir(app_with_10_components.app_path):
app_with_10_components._initialize_app()
Expand All @@ -280,6 +286,7 @@ def test_app_100_compile_time_cold(benchmark, app_with_100_components):
Args:
benchmark: The benchmark fixture.
app_with_100_components: The app harness.
"""

def setup():
Expand Down Expand Up @@ -308,6 +315,7 @@ def test_app_100_compile_time_warm(benchmark, app_with_100_components):
Args:
benchmark: The benchmark fixture.
app_with_100_components: The app harness.
"""
with chdir(app_with_100_components.app_path):
app_with_100_components._initialize_app()
Expand All @@ -333,6 +341,7 @@ def test_app_1000_compile_time_cold(benchmark, app_with_1000_components):
Args:
benchmark: The benchmark fixture.
app_with_1000_components: The app harness.
"""

def setup():
Expand Down Expand Up @@ -361,6 +370,7 @@ def test_app_1000_compile_time_warm(benchmark, app_with_1000_components):
Args:
benchmark: The benchmark fixture.
app_with_1000_components: The app harness.
"""
with chdir(app_with_1000_components.app_path):
app_with_1000_components._initialize_app()
Expand Down
15 changes: 15 additions & 0 deletions benchmarks/test_benchmark_compile_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def app_with_one_page(
Yields:
an AppHarness instance
"""
root = tmp_path_factory.mktemp(f"app1")

Expand All @@ -223,6 +224,7 @@ def app_with_ten_pages(
Yields:
an AppHarness instance
"""
root = tmp_path_factory.mktemp(f"app10")
yield AppHarness.create(
Expand All @@ -245,6 +247,7 @@ def app_with_hundred_pages(
Yields:
an AppHarness instance
"""
root = tmp_path_factory.mktemp(f"app100")

Expand All @@ -268,6 +271,7 @@ def app_with_thousand_pages(
Yields:
an AppHarness instance
"""
root = tmp_path_factory.mktemp(f"app1000")

Expand All @@ -291,6 +295,7 @@ def app_with_ten_thousand_pages(
Yields:
running AppHarness instance
"""
root = tmp_path_factory.mktemp(f"app10000")

Expand All @@ -316,6 +321,7 @@ def test_app_1_compile_time_cold(benchmark, app_with_one_page):
Args:
benchmark: The benchmark fixture.
app_with_one_page: The app harness.
"""

def setup():
Expand Down Expand Up @@ -345,6 +351,7 @@ def test_app_1_compile_time_warm(benchmark, app_with_one_page):
Args:
benchmark: The benchmark fixture.
app_with_one_page: The app harness.
"""
with chdir(app_with_one_page.app_path):
app_with_one_page._initialize_app()
Expand All @@ -371,6 +378,7 @@ def test_app_10_compile_time_cold(benchmark, app_with_ten_pages):
Args:
benchmark: The benchmark fixture.
app_with_ten_pages: The app harness.
"""

def setup():
Expand Down Expand Up @@ -400,6 +408,7 @@ def test_app_10_compile_time_warm(benchmark, app_with_ten_pages):
Args:
benchmark: The benchmark fixture.
app_with_ten_pages: The app harness.
"""
with chdir(app_with_ten_pages.app_path):
app_with_ten_pages._initialize_app()
Expand All @@ -426,6 +435,7 @@ def test_app_100_compile_time_cold(benchmark, app_with_hundred_pages):
Args:
benchmark: The benchmark fixture.
app_with_hundred_pages: The app harness.
"""

def setup():
Expand Down Expand Up @@ -455,6 +465,7 @@ def test_app_100_compile_time_warm(benchmark, app_with_hundred_pages):
Args:
benchmark: The benchmark fixture.
app_with_hundred_pages: The app harness.
"""
with chdir(app_with_hundred_pages.app_path):
app_with_hundred_pages._initialize_app()
Expand All @@ -481,6 +492,7 @@ def test_app_1000_compile_time_cold(benchmark, app_with_thousand_pages):
Args:
benchmark: The benchmark fixture.
app_with_thousand_pages: The app harness.
"""

def setup():
Expand Down Expand Up @@ -510,6 +522,7 @@ def test_app_1000_compile_time_warm(benchmark, app_with_thousand_pages):
Args:
benchmark: The benchmark fixture.
app_with_thousand_pages: The app harness.
"""
with chdir(app_with_thousand_pages.app_path):
app_with_thousand_pages._initialize_app()
Expand All @@ -536,6 +549,7 @@ def test_app_10000_compile_time_cold(benchmark, app_with_ten_thousand_pages):
Args:
benchmark: The benchmark fixture.
app_with_ten_thousand_pages: The app harness.
"""

def setup():
Expand Down Expand Up @@ -566,6 +580,7 @@ def test_app_10000_compile_time_warm(benchmark, app_with_ten_thousand_pages):
Args:
benchmark: The benchmark fixture.
app_with_ten_thousand_pages: The app harness.
"""

def benchmark_fn():
Expand Down
3 changes: 3 additions & 0 deletions integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def xvfb():
Yields:
the pyvirtualdisplay object that the browser will be open on
"""
if os.environ.get("GITHUB_ACTIONS") and not os.environ.get("APP_HARNESS_HEADLESS"):
from pyvirtualdisplay.smartdisplay import ( # pyright: ignore [reportMissingImports]
Expand All @@ -41,6 +42,7 @@ def pytest_exception_interact(node, call, report):
node: The pytest item that failed.
call: The pytest call describing when/where the test was invoked.
report: The pytest log report object.
"""
screenshot_dir = os.environ.get("SCREENSHOT_DIR")
if DISPLAY is None or screenshot_dir is None:
Expand Down Expand Up @@ -73,5 +75,6 @@ def app_harness_env(request):
Returns:
The AppHarness class to use for the test.
"""
return request.param
1 change: 1 addition & 0 deletions integration/shared/state.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Simple module which contains one reusable reflex state class."""

import reflex as rx


Expand Down
4 changes: 4 additions & 0 deletions integration/test_background_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def background_task(
Yields:
running AppHarness instance
"""
with AppHarness.create(
root=tmp_path_factory.mktemp(f"background_task"),
Expand All @@ -125,6 +126,7 @@ def driver(background_task: AppHarness) -> Generator[WebDriver, None, None]:
Yields:
WebDriver instance.
"""
assert background_task.app_instance is not None, "app is not running"
driver = background_task.frontend()
Expand All @@ -144,6 +146,7 @@ def token(background_task: AppHarness, driver: WebDriver) -> str:
Returns:
The token for the connected client
"""
assert background_task.app_instance is not None
token_input = driver.find_element(By.ID, "token")
Expand All @@ -167,6 +170,7 @@ def test_background_task(
background_task: harness for BackgroundTask app.
driver: WebDriver instance.
token: The token for the connected client.
"""
assert background_task.app_instance is not None

Expand Down
5 changes: 5 additions & 0 deletions integration/test_call_script.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Integration tests for client side storage."""

from __future__ import annotations

from typing import Generator
Expand Down Expand Up @@ -239,6 +240,7 @@ def call_script(tmp_path_factory) -> Generator[AppHarness, None, None]:
Yields:
running AppHarness instance
"""
with AppHarness.create(
root=tmp_path_factory.mktemp("call_script"),
Expand All @@ -256,6 +258,7 @@ def driver(call_script: AppHarness) -> Generator[WebDriver, None, None]:
Yields:
WebDriver instance.
"""
assert call_script.app_instance is not None, "app is not running"
driver = call_script.frontend()
Expand All @@ -274,6 +277,7 @@ def assert_token(call_script: AppHarness, driver: WebDriver) -> str:
Returns:
The token visible in the driver browser.
"""
assert call_script.app_instance is not None
token_input = driver.find_element(By.ID, "token")
Expand All @@ -298,6 +302,7 @@ def test_call_script(
call_script: harness for CallScript app.
driver: WebDriver instance.
script: The type of script to test.
"""
assert_token(call_script, driver)
reset_button = driver.find_element(By.ID, "reset")
Expand Down
7 changes: 7 additions & 0 deletions integration/test_client_storage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Integration tests for client side storage."""

from __future__ import annotations

import time
Expand Down Expand Up @@ -121,6 +122,7 @@ def client_side(tmp_path_factory) -> Generator[AppHarness, None, None]:
Yields:
running AppHarness instance
"""
with AppHarness.create(
root=tmp_path_factory.mktemp("client_side"),
Expand All @@ -138,6 +140,7 @@ def driver(client_side: AppHarness) -> Generator[WebDriver, None, None]:
Yields:
WebDriver instance.
"""
assert client_side.app_instance is not None, "app is not running"
driver = client_side.frontend()
Expand All @@ -156,6 +159,7 @@ def local_storage(driver: WebDriver) -> Generator[utils.LocalStorage, None, None
Yields:
Local storage helper.
"""
ls = utils.LocalStorage(driver)
yield ls
Expand All @@ -171,6 +175,7 @@ def delete_all_cookies(driver: WebDriver) -> Generator[None, None, None]:
Yields:
None
"""
yield
driver.delete_all_cookies()
Expand All @@ -184,6 +189,7 @@ def cookie_info_map(driver: WebDriver) -> dict[str, dict[str, str]]:
Returns:
A map of cookie names to cookie info.
"""
return {cookie_info["name"]: cookie_info for cookie_info in driver.get_cookies()}

Expand All @@ -198,6 +204,7 @@ async def test_client_side_state(
client_side: harness for ClientSide app.
driver: WebDriver instance.
local_storage: Local storage helper.
"""
assert client_side.app_instance is not None
assert client_side.frontend_url is not None
Expand Down
2 changes: 2 additions & 0 deletions integration/test_component_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def component_state_app(tmp_path) -> Generator[AppHarness, None, None]:
Yields:
running AppHarness instance
"""
with AppHarness.create(
root=tmp_path,
Expand All @@ -74,6 +75,7 @@ async def test_component_state_app(component_state_app: AppHarness):
Args:
component_state_app: harness for ComponentStateApp app
"""
assert component_state_app.app_instance is not None, "app is not running"
driver = component_state_app.frontend()
Expand Down
Loading

0 comments on commit 6cd628f

Please sign in to comment.