Bläddra i källkod

fix precommit

Khaleel Al-Adhami 1 dag sedan
förälder
incheckning
deafecb031

+ 1 - 1
pyi_hashes.json

@@ -46,7 +46,7 @@
   "reflex/components/next/image.pyi": "8c305c03019d37c07560c154a05bf5dd",
   "reflex/components/next/link.pyi": "cc438e48a9f31bf16f1cdb6e16017477",
   "reflex/components/next/video.pyi": "8f5694a4a2118c5297e2eba479b6f018",
-  "reflex/components/plotly/plotly.pyi": "4ac553adb23b0521e92f53475cc1a6e9",
+  "reflex/components/plotly/plotly.pyi": "addc41e30226783ac97dc774423fcfd1",
   "reflex/components/radix/__init__.pyi": "8d586cbff1d7130d09476ac72ee73400",
   "reflex/components/radix/primitives/__init__.pyi": "fe8715decf3e9ae471b56bba14e42cb3",
   "reflex/components/radix/primitives/accordion.pyi": "a31599f0b2a1a69a10917137dcb75a9d",

+ 2 - 2
reflex/components/plotly/plotly.py

@@ -12,9 +12,9 @@ from reflex.utils.imports import ImportDict, ImportVar
 from reflex.vars.base import LiteralVar, Var
 
 try:
-    from plotly.graph_objects import Figure, layout
+    from plotly.graph_objs import Figure
+    from plotly.graph_objs.layout import Template
 
-    Template = layout.Template
 except ImportError:
     console.warn("Plotly is not installed. Please run `pip install plotly`.")
     Figure = Any

+ 2 - 1
tests/integration/conftest.py

@@ -1,6 +1,7 @@
 """Shared conftest for all integration tests."""
 
 import pytest
+from pytest_mock import MockerFixture
 
 import reflex.app
 from reflex.testing import AppHarness, AppHarnessProd
@@ -22,7 +23,7 @@ def app_harness_env(request):
 
 
 @pytest.fixture(autouse=True)
-def raise_console_error(request, mocker):
+def raise_console_error(request, mocker: MockerFixture):
     """Spy on calls to `console.error` used by the framework.
 
     Help catch spurious error conditions that might otherwise go unnoticed.

+ 5 - 4
tests/units/compiler/test_compiler.py

@@ -3,6 +3,7 @@ import os
 from pathlib import Path
 
 import pytest
+from pytest_mock import MockerFixture
 
 from reflex import constants
 from reflex.compiler import compiler, utils
@@ -115,7 +116,7 @@ def test_compile_imports(import_dict: ParsedImportDict, test_dicts: list[dict]):
         )
 
 
-def test_compile_stylesheets(tmp_path: Path, mocker):
+def test_compile_stylesheets(tmp_path: Path, mocker: MockerFixture):
     """Test that stylesheets compile correctly.
 
     Args:
@@ -166,7 +167,7 @@ def test_compile_stylesheets(tmp_path: Path, mocker):
     ).read_text()
 
 
-def test_compile_stylesheets_scss_sass(tmp_path: Path, mocker):
+def test_compile_stylesheets_scss_sass(tmp_path: Path, mocker: MockerFixture):
     if importlib.util.find_spec("sass") is None:
         pytest.skip(
             'The `libsass` package is required to compile sass/scss stylesheet files. Run `pip install "libsass>=0.23.0"`.'
@@ -251,7 +252,7 @@ def test_compile_stylesheets_scss_sass(tmp_path: Path, mocker):
     ).read_text() == expected_result
 
 
-def test_compile_stylesheets_exclude_tailwind(tmp_path, mocker):
+def test_compile_stylesheets_exclude_tailwind(tmp_path, mocker: MockerFixture):
     """Test that Tailwind is excluded if tailwind config is explicitly set to None.
 
     Args:
@@ -281,7 +282,7 @@ def test_compile_stylesheets_exclude_tailwind(tmp_path, mocker):
     )
 
 
-def test_compile_nonexistent_stylesheet(tmp_path, mocker):
+def test_compile_nonexistent_stylesheet(tmp_path, mocker: MockerFixture):
     """Test that an error is thrown for non-existent stylesheets.
 
     Args:

+ 2 - 1
tests/units/middleware/test_hydrate_middleware.py

@@ -1,6 +1,7 @@
 from __future__ import annotations
 
 import pytest
+from pytest_mock import MockerFixture
 
 from reflex.app import App
 from reflex.middleware.hydrate_middleware import HydrateMiddleware
@@ -30,7 +31,7 @@ def hydrate_middleware() -> HydrateMiddleware:
 
 
 @pytest.mark.asyncio
-async def test_preprocess_no_events(hydrate_middleware, event1, mocker):
+async def test_preprocess_no_events(hydrate_middleware, event1, mocker: MockerFixture):
     """Test that app without on_load is processed correctly.
 
     Args:

+ 5 - 5
tests/units/test_app.py

@@ -775,7 +775,7 @@ async def test_dict_mutation_detection__plain_list(
         ),
     ],
 )
-async def test_upload_file(tmp_path, state, delta, token: str, mocker):
+async def test_upload_file(tmp_path, state, delta, token: str, mocker: MockerFixture):
     """Test that file upload works correctly.
 
     Args:
@@ -988,7 +988,7 @@ def test_dynamic_arg_shadow(
     windows_platform: bool,
     token: str,
     app_module_mock: unittest.mock.Mock,
-    mocker,
+    mocker: MockerFixture,
 ):
     """Create app with dynamic route var and try to add a page with a dynamic arg that shadows a state var.
 
@@ -1012,7 +1012,7 @@ def test_multiple_dynamic_args(
     windows_platform: bool,
     token: str,
     app_module_mock: unittest.mock.Mock,
-    mocker,
+    mocker: MockerFixture,
 ):
     """Create app with multiple dynamic route vars with the same name.
 
@@ -1037,7 +1037,7 @@ async def test_dynamic_route_var_route_change_completed_on_load(
     windows_platform: bool,
     token: str,
     app_module_mock: unittest.mock.Mock,
-    mocker,
+    mocker: MockerFixture,
 ):
     """Create app with dynamic route var, and simulate navigation.
 
@@ -1220,7 +1220,7 @@ async def test_dynamic_route_var_route_change_completed_on_load(
 
 
 @pytest.mark.asyncio
-async def test_process_events(mocker, token: str):
+async def test_process_events(mocker: MockerFixture, token: str):
     """Test that an event is processed properly and that it is postprocessed
     n+1 times. Also check that the processing flag of the last stateupdate is set to
     False.

+ 2 - 1
tests/units/test_config.py

@@ -4,6 +4,7 @@ from pathlib import Path
 from typing import Any
 
 import pytest
+from pytest_mock import MockerFixture
 
 import reflex as rx
 import reflex.config
@@ -107,7 +108,7 @@ def test_update_from_env_path(
         ),
     ],
 )
-def test_event_namespace(mocker, kwargs, expected):
+def test_event_namespace(mocker: MockerFixture, kwargs, expected):
     """Test the event namespace.
 
     Args:

+ 10 - 5
tests/units/test_health_endpoint.py

@@ -2,7 +2,8 @@ import json
 from unittest.mock import MagicMock, Mock
 
 import pytest
-import sqlalchemy
+import sqlalchemy.exc
+from pytest_mock import MockerFixture
 from redis.exceptions import RedisError
 
 from reflex.app import health
@@ -22,7 +23,9 @@ from reflex.utils.prerequisites import get_redis_status
         (None, {"redis": None}),
     ],
 )
-async def test_get_redis_status(mock_redis_client, expected_status, mocker):
+async def test_get_redis_status(
+    mock_redis_client, expected_status, mocker: MockerFixture
+):
     # Mock the `get_redis_sync` function to return the mock Redis client
     mock_get_redis_sync = mocker.patch(
         "reflex.utils.prerequisites.get_redis_sync", return_value=mock_redis_client
@@ -45,12 +48,14 @@ async def test_get_redis_status(mock_redis_client, expected_status, mocker):
         # Case 2: Database connection error (OperationalError)
         (
             MagicMock(),
-            sqlalchemy.exc.OperationalError("error", "error", "error"),
+            sqlalchemy.exc.OperationalError("error", "error", "error"),  # pyright: ignore[reportArgumentType]
             {"db": False},
         ),
     ],
 )
-async def test_get_db_status(mock_engine, execute_side_effect, expected_status, mocker):
+async def test_get_db_status(
+    mock_engine, execute_side_effect, expected_status, mocker: MockerFixture
+):
     # Mock get_engine to return the mock_engine
     mock_get_engine = mocker.patch("reflex.model.get_engine", return_value=mock_engine)
 
@@ -99,7 +104,7 @@ async def test_health(
     redis_status,
     expected_status,
     expected_code,
-    mocker,
+    mocker: MockerFixture,
 ):
     # Mock get_db_status and get_redis_status
     mocker.patch(

+ 1 - 0
tests/units/test_model.py

@@ -3,6 +3,7 @@ from unittest import mock
 
 import pytest
 import sqlalchemy
+import sqlalchemy.exc
 import sqlmodel
 
 import reflex.constants

+ 3 - 2
tests/units/test_route.py

@@ -1,4 +1,5 @@
 import pytest
+from pytest_mock import MockerFixture
 
 from reflex import constants
 from reflex.app import App
@@ -88,7 +89,7 @@ def app():
         ("/posts/[slug]/info/[[...slug1]]", "/posts/[slug]/info/[[...slug2]]"),
     ],
 )
-def test_check_routes_conflict_invalid(mocker, app, route1, route2):
+def test_check_routes_conflict_invalid(mocker: MockerFixture, app, route1, route2):
     mocker.patch.object(app, "_pages", {route1: []})
     with pytest.raises(ValueError):
         app._check_routes_conflict(route2)
@@ -116,7 +117,7 @@ def test_check_routes_conflict_invalid(mocker, app, route1, route2):
         ("/posts/[slug]/info/[...slug1]", "/posts/[slug]/info1/[...slug2]"),
     ],
 )
-def test_check_routes_conflict_valid(mocker, app, route1, route2):
+def test_check_routes_conflict_valid(mocker: MockerFixture, app, route1, route2):
     mocker.patch.object(app, "_pages", {route1: []})
     # test that running this does not throw an error.
     app._check_routes_conflict(route2)

+ 9 - 4
tests/units/test_state.py

@@ -19,6 +19,7 @@ import pytest_asyncio
 from plotly.graph_objects import Figure
 from pydantic import BaseModel as BaseModelV2
 from pydantic.v1 import BaseModel as BaseModelV1
+from pytest_mock import MockerFixture
 
 import reflex as rx
 import reflex.config
@@ -1849,7 +1850,7 @@ async def test_state_manager_lock_warning_threshold_contend(
     state_manager_redis: StateManagerRedis,
     token: str,
     substate_token_redis: str,
-    mocker,
+    mocker: MockerFixture,
 ):
     """Test that the state manager triggers a warning when lock contention exceeds the warning threshold.
 
@@ -2613,7 +2614,7 @@ def test_mutable_copy_vars(mutable_state: MutableTestState, copy_func: Callable)
         assert not isinstance(var_copy, MutableProxy)
 
 
-def test_duplicate_substate_class(mocker):
+def test_duplicate_substate_class(mocker: MockerFixture):
     # Neuter pytest escape hatch, because we want to test duplicate detection.
     mocker.patch("reflex.state.is_testing_env", lambda: False)
     # Neuter <locals> state handling since these _are_ defined inside a function.
@@ -2870,7 +2871,9 @@ class OnLoadState3(State):
         (OnLoadState3, {"on_load_state3": {"num": 1}}),
     ],
 )
-async def test_preprocess(app_module_mock, token, test_state, expected, mocker):
+async def test_preprocess(
+    app_module_mock, token, test_state, expected, mocker: MockerFixture
+):
     """Test that a state hydrate event is processed correctly.
 
     Args:
@@ -2919,7 +2922,9 @@ async def test_preprocess(app_module_mock, token, test_state, expected, mocker):
 
 
 @pytest.mark.asyncio
-async def test_preprocess_multiple_load_events(app_module_mock, token, mocker):
+async def test_preprocess_multiple_load_events(
+    app_module_mock, token, mocker: MockerFixture
+):
     """Test that a state hydrate event for multiple on-load events is processed correctly.
 
     Args:

+ 2 - 1
tests/units/test_telemetry.py

@@ -1,5 +1,6 @@
 import pytest
 from packaging.version import parse as parse_python_version
+from pytest_mock import MockerFixture
 
 from reflex.utils import telemetry
 
@@ -32,7 +33,7 @@ def test_disable():
 
 
 @pytest.mark.parametrize("event", ["init", "reinit", "run-dev", "run-prod", "export"])
-def test_send(mocker, event):
+def test_send(mocker: MockerFixture, event):
     httpx_post_mock = mocker.patch("httpx.post")
 
     # Mock the read_text method of Path

+ 2 - 1
tests/units/test_var.py

@@ -7,6 +7,7 @@ from typing import cast
 
 import pytest
 from pandas import DataFrame
+from pytest_mock import MockerFixture
 
 import reflex as rx
 from reflex.base import Base
@@ -1899,7 +1900,7 @@ def test_var_data_with_hooks_value():
     assert var_data == VarData(hooks=["whott", "whot", "what"])
 
 
-def test_str_var_in_components(mocker):
+def test_str_var_in_components(mocker: MockerFixture):
     class StateWithVar(rx.State):
         field: int = 1
 

+ 15 - 14
tests/units/utils/test_utils.py

@@ -8,6 +8,7 @@ from typing import Any, ClassVar, List, Literal, NoReturn  # noqa: UP035
 import click
 import pytest
 from packaging import version
+from pytest_mock import MockerFixture
 
 from reflex import constants
 from reflex.config import environment
@@ -173,7 +174,7 @@ def test_typehint_issubclass_mutable_as_immutable(subclass, superclass, expected
     )
 
 
-def test_validate_none_bun_path(mocker):
+def test_validate_none_bun_path(mocker: MockerFixture):
     """Test that an error is thrown when a bun path is not specified.
 
     Args:
@@ -184,9 +185,7 @@ def test_validate_none_bun_path(mocker):
     prerequisites.validate_bun()
 
 
-def test_validate_invalid_bun_path(
-    mocker,
-):
+def test_validate_invalid_bun_path(mocker: MockerFixture):
     """Test that an error is thrown when a custom specified bun path is not valid
     or does not exist.
 
@@ -202,7 +201,7 @@ def test_validate_invalid_bun_path(
         prerequisites.validate_bun()
 
 
-def test_validate_bun_path_incompatible_version(mocker):
+def test_validate_bun_path_incompatible_version(mocker: MockerFixture):
     """Test that an error is thrown when the bun version does not meet minimum requirements.
 
     Args:
@@ -221,7 +220,7 @@ def test_validate_bun_path_incompatible_version(mocker):
     prerequisites.validate_bun()
 
 
-def test_remove_existing_bun_installation(mocker):
+def test_remove_existing_bun_installation(mocker: MockerFixture):
     """Test that existing bun installation is removed.
 
     Args:
@@ -234,7 +233,7 @@ def test_remove_existing_bun_installation(mocker):
     rm.assert_called_once()
 
 
-def test_setup_frontend(tmp_path, mocker):
+def test_setup_frontend(tmp_path, mocker: MockerFixture):
     """Test checking if assets content have been
     copied into the .web/public folder.
 
@@ -342,7 +341,7 @@ def test_unsupported_literals(cls: type):
         ("appname2.io", "AppnameioConfig"),
     ],
 )
-def test_create_config(app_name: str, expected_config_name: str, mocker):
+def test_create_config(app_name: str, expected_config_name: str, mocker: MockerFixture):
     """Test templates.RXCONFIG is formatted with correct app name and config class name.
 
     Args:
@@ -421,7 +420,9 @@ def test_is_dataframe(class_type, expected):
 
 
 @pytest.mark.parametrize("gitignore_exists", [True, False])
-def test_initialize_non_existent_gitignore(tmp_path, mocker, gitignore_exists):
+def test_initialize_non_existent_gitignore(
+    tmp_path, mocker: MockerFixture, gitignore_exists
+):
     """Test that the generated .gitignore_file file on reflex init contains the correct file
     names with correct formatting.
 
@@ -452,7 +453,7 @@ def test_initialize_non_existent_gitignore(tmp_path, mocker, gitignore_exists):
     assert set(file_content) - expected == set()
 
 
-def test_validate_app_name(tmp_path, mocker):
+def test_validate_app_name(tmp_path, mocker: MockerFixture):
     """Test that an error is raised if the app name is reflex or if the name is not according to python package naming conventions.
 
     Args:
@@ -471,7 +472,7 @@ def test_validate_app_name(tmp_path, mocker):
         prerequisites.validate_app_name(app_name="1_test")
 
 
-def test_bun_install_without_unzip(mocker):
+def test_bun_install_without_unzip(mocker: MockerFixture):
     """Test that an error is thrown when installing bun with unzip not installed.
 
     Args:
@@ -486,7 +487,7 @@ def test_bun_install_without_unzip(mocker):
 
 
 @pytest.mark.parametrize("bun_version", [constants.Bun.VERSION, "1.0.0"])
-def test_bun_install_version(mocker, bun_version):
+def test_bun_install_version(mocker: MockerFixture, bun_version):
     """Test that bun is downloaded when the host version(installed by reflex)
     different from the current version set in reflex.
 
@@ -512,7 +513,7 @@ def test_bun_install_version(mocker, bun_version):
 
 
 @pytest.mark.parametrize("is_windows", [True, False])
-def test_create_reflex_dir(mocker, is_windows):
+def test_create_reflex_dir(mocker: MockerFixture, is_windows):
     """Test that a reflex directory is created on initializing frontend
     dependencies.
 
@@ -534,7 +535,7 @@ def test_create_reflex_dir(mocker, is_windows):
     assert create_cmd.called
 
 
-def test_output_system_info(mocker):
+def test_output_system_info(mocker: MockerFixture):
     """Make sure reflex does not crash dumping system info.
 
     Args: