ソースを参照

remove helmet pyi and make the tests wait for token

Khaleel Al-Adhami 3 週間 前
コミット
4e0899e598

+ 4 - 3
pyi_hashes.json

@@ -4,20 +4,21 @@
   "reflex/components/base/__init__.pyi": "d0139bd2c41c28d837b91fa8949e2494",
   "reflex/components/base/app_wrap.pyi": "387fc7a0c2da8760d9449e2893e44eec",
   "reflex/components/base/body.pyi": "2d16002f24c8ee0007b46ff2bf1f2c78",
-  "reflex/components/base/document.pyi": "30377cdfb02b564f8de29b0473d2346c",
+  "reflex/components/base/document.pyi": "851cb54842f3df1e5f44ba1fb72e12af",
   "reflex/components/base/error_boundary.pyi": "c56b591d14a92b99a1e97e04afe167d7",
   "reflex/components/base/fragment.pyi": "603ee8e03af88d4a8ff6bc1fbce4e022",
   "reflex/components/base/head.pyi": "893047aa32da553711db8f1345adb6b0",
   "reflex/components/base/link.pyi": "e96179dc7823f354fb73a6c03e31028c",
   "reflex/components/base/meta.pyi": "da52c3212fac6b50560863146a7afcc3",
-  "reflex/components/base/script.pyi": "530cf8f47eb90082bf65942e8b5d745f",
+  "reflex/components/base/script.pyi": "d3743541fd968e9b6aaa123da6a11c3c",
   "reflex/components/base/strict_mode.pyi": "d972e0ff2a6f961e7df90fc27b8bb51b",
   "reflex/components/core/__init__.pyi": "d99fbfd4207d8a3f7013221f428e0ed8",
   "reflex/components/core/auto_scroll.pyi": "d3012d2a4ccaab8dfebf9aa484020f59",
   "reflex/components/core/banner.pyi": "48d0eb86ae09e806ebe20d0edcc3cdb3",
-  "reflex/components/core/client_side_routing.pyi": "9be638a2b0e00b8181697e5dd6b45e4e",
+  "reflex/components/core/client_side_routing.pyi": "919944e006257c6ee7eecd772e476dc6",
   "reflex/components/core/clipboard.pyi": "4098368af3c32dbde77fc74599f8799a",
   "reflex/components/core/debounce.pyi": "affda049624c266c7d5620efa3b7041b",
+  "reflex/components/core/helmet.pyi": "835ea00c34746b334d33af448dce7422",
   "reflex/components/core/html.pyi": "b12117b42ef79ee90b6b4dec50baeb86",
   "reflex/components/core/sticky.pyi": "c65131cf7c2312c68e1fddaa0cc27150",
   "reflex/components/core/upload.pyi": "4680da6f7b3df704a682cc6441b1ac18",

+ 0 - 63
reflex/components/core/helmet.pyi

@@ -1,63 +0,0 @@
-"""Stub file for reflex/components/core/helmet.py"""
-
-# ------------------- DO NOT EDIT ----------------------
-# This file was generated by `reflex/utils/pyi_generator.py`!
-# ------------------------------------------------------
-from typing import Any, Mapping, Optional, Sequence, overload
-
-from reflex.components.component import Component
-from reflex.components.core.breakpoints import Breakpoints
-from reflex.event import EventType
-from reflex.vars.base import Var
-
-class Helmet(Component):
-    @overload
-    @classmethod
-    def create(  # type: ignore
-        cls,
-        *children,
-        style: Sequence[Mapping[str, Any]]
-        | Mapping[str, Any]
-        | Var[Mapping[str, Any]]
-        | Breakpoints
-        | None = None,
-        key: Any | None = None,
-        id: Any | None = None,
-        class_name: Any | None = None,
-        autofocus: bool | None = None,
-        custom_attrs: dict[str, Var | Any] | None = None,
-        on_blur: Optional[EventType[()]] = None,
-        on_click: Optional[EventType[()]] = None,
-        on_context_menu: Optional[EventType[()]] = None,
-        on_double_click: Optional[EventType[()]] = None,
-        on_focus: Optional[EventType[()]] = None,
-        on_mount: Optional[EventType[()]] = None,
-        on_mouse_down: Optional[EventType[()]] = None,
-        on_mouse_enter: Optional[EventType[()]] = None,
-        on_mouse_leave: Optional[EventType[()]] = None,
-        on_mouse_move: Optional[EventType[()]] = None,
-        on_mouse_out: Optional[EventType[()]] = None,
-        on_mouse_over: Optional[EventType[()]] = None,
-        on_mouse_up: Optional[EventType[()]] = None,
-        on_scroll: Optional[EventType[()]] = None,
-        on_unmount: Optional[EventType[()]] = None,
-        **props,
-    ) -> "Helmet":
-        """Create the component.
-
-        Args:
-            *children: The children of the component.
-            style: The style of the component.
-            key: A unique key for the component.
-            id: The id for the component.
-            class_name: The class name for the component.
-            autofocus: Whether the component should take the focus once the page is loaded
-            custom_attrs: custom attribute
-            **props: The props of the component.
-
-        Returns:
-            The component.
-        """
-        ...
-
-helmet = Helmet.create

+ 30 - 0
reflex/testing.py

@@ -822,6 +822,36 @@ class AppHarness:
             raise TimeoutError("No states were observed while polling.")
         return state_manager.states
 
+    @staticmethod
+    def poll_for_result(
+        f: Callable[[], T],
+        exception: type[Exception] = Exception,
+        max_attempts: int = 5,
+        seconds_between_attempts: int = 1,
+    ) -> T:
+        """Poll for a result from a function.
+
+        Args:
+            f: function to call
+            exception: exception to catch
+            max_attempts: maximum number of attempts
+            seconds_between_attempts: seconds to wait between
+
+        Returns:
+            Result of the function
+
+        Raises:
+            AssertionError: if the function does not return a value
+        """
+        attempts = 0
+        while attempts < max_attempts:
+            try:
+                return f()
+            except exception:  # noqa: PERF203
+                attempts += 1
+                time.sleep(seconds_between_attempts)
+        raise AssertionError("Function did not return a value")
+
 
 class SimpleHTTPRequestHandlerCustomErrors(SimpleHTTPRequestHandler):
     """SimpleHTTPRequestHandler with custom error page handling."""

+ 3 - 1
tests/integration/test_background_task.py

@@ -241,7 +241,9 @@ def token(background_task: AppHarness, driver: WebDriver) -> str:
         The token for the connected client
     """
     assert background_task.app_instance is not None
-    token_input = driver.find_element(By.ID, "token")
+    token_input = background_task.poll_for_result(
+        lambda: driver.find_element(By.ID, "token")
+    )
     assert token_input
 
     # wait for the backend connection to send the token

+ 9 - 3
tests/integration/test_client_storage.py

@@ -243,7 +243,9 @@ async def test_client_side_state(
     assert client_side.frontend_url is not None
 
     def poll_for_token():
-        token_input = driver.find_element(By.ID, "token")
+        token_input = client_side.poll_for_result(
+            lambda: driver.find_element(By.ID, "token")
+        )
         assert token_input
 
         # wait for the backend connection to send the token
@@ -518,7 +520,9 @@ async def test_client_side_state(
     driver.refresh()
 
     # wait for the backend connection to send the token (again)
-    token_input = driver.find_element(By.ID, "token")
+    token_input = client_side.poll_for_result(
+        lambda: driver.find_element(By.ID, "token")
+    )
     assert token_input
     token = client_side.poll_for_value(token_input)
     assert token is not None
@@ -724,7 +728,9 @@ async def test_client_side_state(
     driver.refresh()
 
     # wait for the backend connection to send the token (again)
-    token_input = driver.find_element(By.ID, "token")
+    token_input = client_side.poll_for_result(
+        lambda: driver.find_element(By.ID, "token")
+    )
     assert token_input
     token = client_side.poll_for_value(token_input)
     assert token is not None

+ 3 - 1
tests/integration/test_computed_vars.py

@@ -172,7 +172,9 @@ def token(computed_vars: AppHarness, driver: WebDriver) -> str:
         The token for the connected client
     """
     assert computed_vars.app_instance is not None
-    token_input = driver.find_element(By.ID, "token")
+    token_input = computed_vars.poll_for_result(
+        lambda: driver.find_element(By.ID, "token")
+    )
     assert token_input
 
     # wait for the backend connection to send the token

+ 10 - 32
tests/integration/test_dynamic_components.py

@@ -1,7 +1,6 @@
 """Integration tests for var operations."""
 
-import time
-from collections.abc import Callable, Generator
+from collections.abc import Generator
 from typing import TypeVar
 
 import pytest
@@ -96,33 +95,6 @@ def dynamic_components(tmp_path_factory) -> Generator[AppHarness, None, None]:
 T = TypeVar("T")
 
 
-def poll_for_result(
-    f: Callable[[], T], exception=Exception, max_attempts=5, seconds_between_attempts=1
-) -> T:
-    """Poll for a result from a function.
-
-    Args:
-        f: function to call
-        exception: exception to catch
-        max_attempts: maximum number of attempts
-        seconds_between_attempts: seconds to wait between
-
-    Returns:
-        Result of the function
-
-    Raises:
-        AssertionError: if the function does not return a value
-    """
-    attempts = 0
-    while attempts < max_attempts:
-        try:
-            return f()
-        except exception:
-            attempts += 1
-            time.sleep(seconds_between_attempts)
-    raise AssertionError("Function did not return a value")
-
-
 @pytest.fixture
 def driver(dynamic_components: AppHarness):
     """Get an instance of the browser open to the dynamic components app.
@@ -135,7 +107,9 @@ def driver(dynamic_components: AppHarness):
     """
     driver = dynamic_components.frontend()
     try:
-        token_input = poll_for_result(lambda: driver.find_element(By.ID, "token"))
+        token_input = dynamic_components.poll_for_result(
+            lambda: driver.find_element(By.ID, "token")
+        )
         assert token_input
         # wait for the backend connection to send the token
         token = dynamic_components.poll_for_value(token_input)
@@ -153,7 +127,9 @@ def test_dynamic_components(driver, dynamic_components: AppHarness):
         driver: selenium WebDriver open to the app
         dynamic_components: AppHarness for the dynamic components
     """
-    button = poll_for_result(lambda: driver.find_element(By.ID, "button"))
+    button = dynamic_components.poll_for_result(
+        lambda: driver.find_element(By.ID, "button")
+    )
     assert button
     assert button.text == "Click me"
 
@@ -166,6 +142,8 @@ def test_dynamic_components(driver, dynamic_components: AppHarness):
         == "Clicked"
     )
 
-    factorial = poll_for_result(lambda: driver.find_element(By.ID, "factorial"))
+    factorial = dynamic_components.poll_for_result(
+        lambda: driver.find_element(By.ID, "factorial")
+    )
     assert factorial
     assert factorial.text == "3628800"

+ 3 - 1
tests/integration/test_dynamic_routes.py

@@ -198,7 +198,9 @@ def token(dynamic_route: AppHarness, driver: WebDriver) -> str:
         The token visible in the driver browser.
     """
     assert dynamic_route.app_instance is not None
-    token_input = driver.find_element(By.ID, "token")
+    token_input = dynamic_route.poll_for_result(
+        lambda: driver.find_element(By.ID, "token")
+    )
     assert token_input
 
     # wait for the backend connection to send the token

+ 3 - 1
tests/integration/test_event_actions.py

@@ -230,7 +230,9 @@ def token(event_action: AppHarness, driver: WebDriver) -> str:
         The token visible in the driver browser.
     """
     assert event_action.app_instance is not None
-    token_input = driver.find_element(By.ID, "token")
+    token_input = event_action.poll_for_result(
+        lambda: driver.find_element(By.ID, "token")
+    )
     assert token_input
 
     # wait for the backend connection to send the token

+ 3 - 1
tests/integration/test_event_chain.py

@@ -310,7 +310,9 @@ def assert_token(event_chain: AppHarness, driver: WebDriver) -> str:
         The token visible in the driver browser.
     """
     assert event_chain.app_instance is not None
-    token_input = driver.find_element(By.ID, "token")
+    token_input = event_chain.poll_for_result(
+        lambda: driver.find_element(By.ID, "token")
+    )
     assert token_input
 
     # wait for the backend connection to send the token

+ 3 - 1
tests/integration/test_extra_overlay_function.py

@@ -58,7 +58,9 @@ def driver(extra_overlay: AppHarness):
     """
     driver = extra_overlay.frontend()
     try:
-        token_input = driver.find_element(By.ID, "token")
+        token_input = extra_overlay.poll_for_result(
+            lambda: driver.find_element(By.ID, "token")
+        )
         assert token_input
         # wait for the backend connection to send the token
         token = extra_overlay.poll_for_value(token_input)

+ 3 - 1
tests/integration/test_form_submit.py

@@ -192,7 +192,9 @@ async def test_submit(driver, form_submit: AppHarness):
     by = By.ID if form_submit.app_source is FormSubmit else By.NAME
 
     # get a reference to the connected client
-    token_input = driver.find_element(By.ID, "token")
+    token_input = form_submit.poll_for_result(
+        lambda: driver.find_element(By.ID, "token")
+    )
     assert token_input
 
     # wait for the backend connection to send the token

+ 2 - 3
tests/integration/test_icon.py

@@ -7,7 +7,6 @@ from selenium.webdriver.common.by import By
 
 from reflex.components.lucide.icon import LUCIDE_ICON_LIST
 from reflex.testing import AppHarness
-from tests.integration.test_dynamic_components import poll_for_result
 
 
 def Icons():
@@ -69,7 +68,7 @@ def driver(icons: AppHarness):
     """
     driver = icons.frontend()
     try:
-        token_input = poll_for_result(
+        token_input = icons.poll_for_result(
             lambda: driver.find_element(By.ID, "token"), max_attempts=30
         )
         assert token_input
@@ -90,7 +89,7 @@ def test_icons(driver, icons: AppHarness):
         icons: AppHarness for the dynamic components
     """
     for icon_name in LUCIDE_ICON_LIST:
-        icon = poll_for_result(
+        icon = icons.poll_for_result(
             lambda icon_name=icon_name: driver.find_element(By.ID, icon_name)
         )
         assert icon

+ 3 - 1
tests/integration/test_input.py

@@ -79,7 +79,9 @@ async def test_fully_controlled_input(fully_controlled_input: AppHarness):
     driver = fully_controlled_input.frontend()
 
     # get a reference to the connected client
-    token_input = driver.find_element(By.ID, "token")
+    token_input = fully_controlled_input.poll_for_result(
+        lambda: driver.find_element(By.ID, "token")
+    )
     assert token_input
 
     # wait for the backend connection to send the token

+ 1 - 1
tests/integration/test_media.py

@@ -103,7 +103,7 @@ async def test_media_app(media_app: AppHarness):
     driver = media_app.frontend()
 
     # wait for the backend connection to send the token
-    token_input = driver.find_element(By.ID, "token")
+    token_input = media_app.poll_for_result(lambda: driver.find_element(By.ID, "token"))
     token = media_app.poll_for_value(token_input)
     assert token
 

+ 3 - 1
tests/integration/test_server_side_event.py

@@ -111,7 +111,9 @@ def driver(server_side_event: AppHarness):
     assert server_side_event.app_instance is not None, "app is not running"
     driver = server_side_event.frontend()
     try:
-        token_input = driver.find_element(By.ID, "token")
+        token_input = server_side_event.poll_for_result(
+            lambda: driver.find_element(By.ID, "token")
+        )
         assert token_input
         # wait for the backend connection to send the token
         token = server_side_event.poll_for_value(token_input)

+ 3 - 1
tests/integration/test_state_inheritance.py

@@ -254,7 +254,9 @@ def token(state_inheritance: AppHarness, driver: WebDriver) -> str:
         The token for the connected client
     """
     assert state_inheritance.app_instance is not None
-    token_input = driver.find_element(By.ID, "token")
+    token_input = state_inheritance.poll_for_result(
+        lambda: driver.find_element(By.ID, "token")
+    )
     assert token_input
 
     # wait for the backend connection to send the token

+ 3 - 1
tests/integration/test_upload.py

@@ -240,7 +240,9 @@ def poll_for_token(driver: WebDriver, upload_file: AppHarness) -> str:
     Returns:
         token value
     """
-    token_input = driver.find_element(By.ID, "token")
+    token_input = upload_file.poll_for_result(
+        lambda: driver.find_element(By.ID, "token")
+    )
     assert token_input
     # wait for the backend connection to send the token
     token = upload_file.poll_for_value(token_input)

+ 3 - 1
tests/integration/test_var_operations.py

@@ -780,7 +780,9 @@ def driver(var_operations: AppHarness):
     """
     driver = var_operations.frontend()
     try:
-        token_input = driver.find_element(By.ID, "token")
+        token_input = var_operations.poll_for_result(
+            lambda: driver.find_element(By.ID, "token")
+        )
         assert token_input
         # wait for the backend connection to send the token
         token = var_operations.poll_for_value(token_input)