test_utils.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. import os
  2. import typing
  3. from functools import cached_property
  4. from pathlib import Path
  5. from typing import (
  6. Any,
  7. ClassVar,
  8. List,
  9. Literal,
  10. Mapping,
  11. NoReturn,
  12. Sequence,
  13. Type,
  14. Union,
  15. )
  16. import pytest
  17. import typer
  18. from packaging import version
  19. from reflex import constants
  20. from reflex.base import Base
  21. from reflex.config import environment
  22. from reflex.event import EventHandler
  23. from reflex.state import BaseState
  24. from reflex.utils import build, prerequisites, types
  25. from reflex.utils import exec as utils_exec
  26. from reflex.utils.exceptions import ReflexError, SystemPackageMissingError
  27. from reflex.vars.base import Var
  28. def mock_event(arg):
  29. pass
  30. def get_above_max_version():
  31. """Get the 1 version above the max required bun version.
  32. Returns:
  33. max bun version plus one.
  34. """
  35. semantic_version_list = constants.Bun.VERSION.split(".")
  36. semantic_version_list[-1] = str(int(semantic_version_list[-1]) + 1) # pyright: ignore [reportArgumentType, reportCallIssue]
  37. return ".".join(semantic_version_list)
  38. V055 = version.parse("0.5.5")
  39. V059 = version.parse("0.5.9")
  40. V056 = version.parse("0.5.6")
  41. VMAXPLUS1 = version.parse(get_above_max_version())
  42. class ExampleTestState(BaseState):
  43. """Test state class."""
  44. def test_event_handler(self):
  45. """Test event handler."""
  46. pass
  47. def test_func():
  48. pass
  49. @pytest.mark.parametrize(
  50. "cls,expected",
  51. [
  52. (str, False),
  53. (int, False),
  54. (float, False),
  55. (bool, False),
  56. (List, True),
  57. (list[int], True),
  58. ],
  59. )
  60. def test_is_generic_alias(cls: type, expected: bool):
  61. """Test checking if a class is a GenericAlias.
  62. Args:
  63. cls: The class to check.
  64. expected: Whether the class is a GenericAlias.
  65. """
  66. assert types.is_generic_alias(cls) == expected
  67. @pytest.mark.parametrize(
  68. ("subclass", "superclass", "expected"),
  69. [
  70. *[
  71. (base_type, base_type, True)
  72. for base_type in [int, float, str, bool, list, dict]
  73. ],
  74. *[
  75. (one_type, another_type, False)
  76. for one_type in [int, float, str, list, dict]
  77. for another_type in [int, float, str, list, dict]
  78. if one_type != another_type
  79. ],
  80. (bool, int, True),
  81. (int, bool, False),
  82. (list, List, True),
  83. (list, list[str], True), # this is wrong, but it's a limitation of the function
  84. (List, list, True),
  85. (list[int], list, True),
  86. (list[int], List, True),
  87. (list[int], list[str], False),
  88. (list[int], list[int], True),
  89. (list[int], list[float], False),
  90. (list[int], list[int | float], True),
  91. (list[int], list[float | str], False),
  92. (int | float, list[int | float], False),
  93. (int | float, int | float | str, True),
  94. (int | float, str | float, False),
  95. (dict[str, int], dict[str, int], True),
  96. (dict[str, bool], dict[str, int], True),
  97. (dict[str, int], dict[str, bool], False),
  98. (dict[str, Any], dict[str, str], False),
  99. (dict[str, str], dict[str, str], True),
  100. (dict[str, str], dict[str, Any], True),
  101. (dict[str, Any], dict[str, Any], True),
  102. (Mapping[str, int], dict[str, int], False),
  103. (Sequence[int], list[int], False),
  104. (Sequence[int] | list[int], list[int], False),
  105. (str, Literal["test", "value"], True),
  106. (str, Literal["test", "value", 2, 3], True),
  107. (int, Literal["test", "value"], False),
  108. (int, Literal["test", "value", 2, 3], True),
  109. *[
  110. (NoReturn, super_class, True)
  111. for super_class in [int, float, str, bool, list, dict, object, Any]
  112. ],
  113. *[
  114. (list[NoReturn], list[super_class], True)
  115. for super_class in [int, float, str, bool, list, dict, object, Any]
  116. ],
  117. ],
  118. )
  119. def test_typehint_issubclass(subclass, superclass, expected):
  120. assert types.typehint_issubclass(subclass, superclass) == expected
  121. @pytest.mark.parametrize(
  122. ("subclass", "superclass", "expected"),
  123. [
  124. *[
  125. (base_type, base_type, True)
  126. for base_type in [int, float, str, bool, list, dict]
  127. ],
  128. *[
  129. (one_type, another_type, False)
  130. for one_type in [int, float, str, list, dict]
  131. for another_type in [int, float, str, list, dict]
  132. if one_type != another_type
  133. ],
  134. (bool, int, True),
  135. (int, bool, False),
  136. (list, List, True),
  137. (list, list[str], True), # this is wrong, but it's a limitation of the function
  138. (List, list, True),
  139. (list[int], list, True),
  140. (list[int], List, True),
  141. (list[int], list[str], False),
  142. (list[int], list[int], True),
  143. (list[int], list[float], False),
  144. (list[int], list[int | float], True),
  145. (list[int], list[float | str], False),
  146. (int | float, list[int | float], False),
  147. (int | float, int | float | str, True),
  148. (int | float, str | float, False),
  149. (dict[str, int], dict[str, int], True),
  150. (dict[str, bool], dict[str, int], True),
  151. (dict[str, int], dict[str, bool], False),
  152. (dict[str, Any], dict[str, str], False),
  153. (dict[str, str], dict[str, str], True),
  154. (dict[str, str], dict[str, Any], True),
  155. (dict[str, Any], dict[str, Any], True),
  156. (Mapping[str, int], dict[str, int], True),
  157. (Sequence[int], list[int], True),
  158. (Sequence[int] | list[int], list[int], True),
  159. (str, Literal["test", "value"], True),
  160. (str, Literal["test", "value", 2, 3], True),
  161. (int, Literal["test", "value"], False),
  162. (int, Literal["test", "value", 2, 3], True),
  163. *[
  164. (NoReturn, super_class, True)
  165. for super_class in [int, float, str, bool, list, dict, object, Any]
  166. ],
  167. *[
  168. (list[NoReturn], list[super_class], True)
  169. for super_class in [int, float, str, bool, list, dict, object, Any]
  170. ],
  171. ],
  172. )
  173. def test_typehint_issubclass_mutable_as_immutable(subclass, superclass, expected):
  174. assert (
  175. types.typehint_issubclass(
  176. subclass, superclass, treat_mutable_superclasss_as_immutable=True
  177. )
  178. == expected
  179. )
  180. def test_validate_none_bun_path(mocker):
  181. """Test that an error is thrown when a bun path is not specified.
  182. Args:
  183. mocker: Pytest mocker object.
  184. """
  185. mocker.patch("reflex.utils.path_ops.get_bun_path", return_value=None)
  186. # with pytest.raises(typer.Exit):
  187. prerequisites.validate_bun()
  188. def test_validate_invalid_bun_path(
  189. mocker,
  190. ):
  191. """Test that an error is thrown when a custom specified bun path is not valid
  192. or does not exist.
  193. Args:
  194. mocker: Pytest mocker object.
  195. """
  196. mock_path = mocker.Mock()
  197. mocker.patch("reflex.utils.path_ops.get_bun_path", return_value=mock_path)
  198. mocker.patch("reflex.utils.path_ops.samefile", return_value=False)
  199. mocker.patch("reflex.utils.prerequisites.get_bun_version", return_value=None)
  200. with pytest.raises(typer.Exit):
  201. prerequisites.validate_bun()
  202. def test_validate_bun_path_incompatible_version(mocker):
  203. """Test that an error is thrown when the bun version does not meet minimum requirements.
  204. Args:
  205. mocker: Pytest mocker object.
  206. """
  207. mock_path = mocker.Mock()
  208. mock_path.samefile.return_value = False
  209. mocker.patch("reflex.utils.path_ops.get_bun_path", return_value=mock_path)
  210. mocker.patch("reflex.utils.path_ops.samefile", return_value=False)
  211. mocker.patch(
  212. "reflex.utils.prerequisites.get_bun_version",
  213. return_value=version.parse("0.6.5"),
  214. )
  215. with pytest.raises(typer.Exit):
  216. prerequisites.validate_bun()
  217. def test_remove_existing_bun_installation(mocker):
  218. """Test that existing bun installation is removed.
  219. Args:
  220. mocker: Pytest mocker.
  221. """
  222. mocker.patch("reflex.utils.prerequisites.Path.exists", return_value=True)
  223. rm = mocker.patch("reflex.utils.prerequisites.path_ops.rm", mocker.Mock())
  224. prerequisites.remove_existing_bun_installation()
  225. rm.assert_called_once()
  226. def test_setup_frontend(tmp_path, mocker):
  227. """Test checking if assets content have been
  228. copied into the .web/public folder.
  229. Args:
  230. tmp_path: root path of test case data directory
  231. mocker: mocker object to allow mocking
  232. """
  233. web_public_folder = tmp_path / ".web" / "public"
  234. assets = tmp_path / "assets"
  235. assets.mkdir()
  236. (assets / "favicon.ico").touch()
  237. mocker.patch("reflex.utils.prerequisites.install_frontend_packages")
  238. mocker.patch("reflex.utils.build.set_env_json")
  239. build.setup_frontend(tmp_path, disable_telemetry=False)
  240. assert web_public_folder.exists()
  241. assert (web_public_folder / "favicon.ico").exists()
  242. @pytest.fixture
  243. def test_backend_variable_cls():
  244. class TestBackendVariable(BaseState):
  245. """Test backend variable."""
  246. _classvar: ClassVar[int] = 0
  247. _hidden: int = 0
  248. not_hidden: int = 0
  249. __dunderattr__: int = 0
  250. @classmethod
  251. def _class_method(cls):
  252. pass
  253. def _hidden_method(self):
  254. pass
  255. @property
  256. def _hidden_property(self):
  257. pass
  258. @cached_property
  259. def _cached_hidden_property(self):
  260. pass
  261. return TestBackendVariable
  262. @pytest.mark.parametrize(
  263. "input, output",
  264. [
  265. ("_classvar", False),
  266. ("_class_method", False),
  267. ("_hidden_method", False),
  268. ("_hidden", True),
  269. ("not_hidden", False),
  270. ("__dundermethod__", False),
  271. ("_hidden_property", False),
  272. ("_cached_hidden_property", False),
  273. ],
  274. )
  275. def test_is_backend_base_variable(
  276. test_backend_variable_cls: Type[BaseState], input: str, output: bool
  277. ):
  278. assert types.is_backend_base_variable(input, test_backend_variable_cls) == output
  279. @pytest.mark.parametrize(
  280. "cls, cls_check, expected",
  281. [
  282. (int, int, True),
  283. (int, float, False),
  284. (int, int | float, True),
  285. (float, int | float, True),
  286. (str, int | float, False),
  287. (list[int], list[int], True),
  288. (list[int], list[float], True),
  289. (int | float, int | float, False),
  290. (int | Var[int], Var[int], False),
  291. (int, Any, True),
  292. (Any, Any, True),
  293. (int | float, Any, True),
  294. (str, Union[Literal["test", "value"], int], True),
  295. (int, Union[Literal["test", "value"], int], True),
  296. (str, Literal["test", "value"], True),
  297. (int, Literal["test", "value"], False),
  298. ],
  299. )
  300. def test_issubclass(cls: type, cls_check: type, expected: bool):
  301. assert types._issubclass(cls, cls_check) == expected
  302. @pytest.mark.parametrize("cls", [Literal["test", 1], Literal[1, "test"]])
  303. def test_unsupported_literals(cls: type):
  304. with pytest.raises(TypeError):
  305. types.get_base_class(cls)
  306. @pytest.mark.parametrize(
  307. "app_name,expected_config_name",
  308. [
  309. ("appname", "AppnameConfig"),
  310. ("app_name", "AppnameConfig"),
  311. ("app-name", "AppnameConfig"),
  312. ("appname2.io", "AppnameioConfig"),
  313. ],
  314. )
  315. def test_create_config(app_name: str, expected_config_name: str, mocker):
  316. """Test templates.RXCONFIG is formatted with correct app name and config class name.
  317. Args:
  318. app_name: App name.
  319. expected_config_name: Expected config name.
  320. mocker: Mocker object.
  321. """
  322. mocker.patch("pathlib.Path.write_text")
  323. tmpl_mock = mocker.patch("reflex.compiler.templates.RXCONFIG")
  324. prerequisites.create_config(app_name)
  325. tmpl_mock.render.assert_called_with(
  326. app_name=app_name, config_name=expected_config_name
  327. )
  328. @pytest.fixture
  329. def tmp_working_dir(tmp_path):
  330. """Create a temporary directory and chdir to it.
  331. After the test executes, chdir back to the original working directory.
  332. Args:
  333. tmp_path: pytest tmp_path fixture creates per-test temp dir
  334. Yields:
  335. subdirectory of tmp_path which is now the current working directory.
  336. """
  337. old_pwd = Path.cwd()
  338. working_dir = tmp_path / "working_dir"
  339. working_dir.mkdir()
  340. os.chdir(working_dir)
  341. yield working_dir
  342. os.chdir(old_pwd)
  343. def test_create_config_e2e(tmp_working_dir):
  344. """Create a new config file, exec it, and make assertions about the config.
  345. Args:
  346. tmp_working_dir: a new directory that is the current working directory
  347. for the duration of the test.
  348. """
  349. app_name = "e2e"
  350. prerequisites.create_config(app_name)
  351. eval_globals = {}
  352. exec((tmp_working_dir / constants.Config.FILE).read_text(), eval_globals)
  353. config = eval_globals["config"]
  354. assert config.app_name == app_name
  355. class DataFrame:
  356. """A Fake pandas DataFrame class."""
  357. pass
  358. @pytest.mark.parametrize(
  359. "class_type,expected",
  360. [
  361. (list, False),
  362. (int, False),
  363. (dict, False),
  364. (DataFrame, True),
  365. (typing.Any, False),
  366. (typing.List, False),
  367. ],
  368. )
  369. def test_is_dataframe(class_type, expected):
  370. """Test that a type name is DataFrame.
  371. Args:
  372. class_type: the class type.
  373. expected: whether type name is DataFrame
  374. """
  375. assert types.is_dataframe(class_type) == expected
  376. @pytest.mark.parametrize("gitignore_exists", [True, False])
  377. def test_initialize_non_existent_gitignore(tmp_path, mocker, gitignore_exists):
  378. """Test that the generated .gitignore_file file on reflex init contains the correct file
  379. names with correct formatting.
  380. Args:
  381. tmp_path: The root test path.
  382. mocker: The mock object.
  383. gitignore_exists: Whether a gitignore file exists in the root dir.
  384. """
  385. expected = constants.GitIgnore.DEFAULTS.copy()
  386. mocker.patch("reflex.constants.GitIgnore.FILE", tmp_path / ".gitignore")
  387. gitignore_file = tmp_path / ".gitignore"
  388. if gitignore_exists:
  389. gitignore_file.touch()
  390. gitignore_file.write_text(
  391. """*.db
  392. __pycache__/
  393. """
  394. )
  395. prerequisites.initialize_gitignore(gitignore_file=gitignore_file)
  396. assert gitignore_file.exists()
  397. file_content = [
  398. line.strip() for line in gitignore_file.open().read().splitlines() if line
  399. ]
  400. assert set(file_content) - expected == set()
  401. def test_validate_app_name(tmp_path, mocker):
  402. """Test that an error is raised if the app name is reflex or if the name is not according to python package naming conventions.
  403. Args:
  404. tmp_path: Test working dir.
  405. mocker: Pytest mocker object.
  406. """
  407. reflex = tmp_path / "reflex"
  408. reflex.mkdir()
  409. mocker.patch("reflex.utils.prerequisites.os.getcwd", return_value=str(reflex))
  410. with pytest.raises(typer.Exit):
  411. prerequisites.validate_app_name()
  412. with pytest.raises(typer.Exit):
  413. prerequisites.validate_app_name(app_name="1_test")
  414. def test_node_install_windows(tmp_path, mocker):
  415. """Require user to install node manually for windows if node is not installed.
  416. Args:
  417. tmp_path: Test working dir.
  418. mocker: Pytest mocker object.
  419. """
  420. fnm_root_path = tmp_path / "reflex" / "fnm"
  421. fnm_exe = fnm_root_path / "fnm.exe"
  422. mocker.patch("reflex.utils.prerequisites.constants.Fnm.DIR", fnm_root_path)
  423. mocker.patch("reflex.utils.prerequisites.constants.Fnm.EXE", fnm_exe)
  424. mocker.patch("reflex.utils.prerequisites.constants.IS_WINDOWS", True)
  425. mocker.patch("reflex.utils.processes.new_process")
  426. mocker.patch("reflex.utils.processes.stream_logs")
  427. class Resp(Base):
  428. status_code = 200
  429. text = "test"
  430. mocker.patch("httpx.stream", return_value=Resp())
  431. download = mocker.patch("reflex.utils.prerequisites.download_and_extract_fnm_zip")
  432. mocker.patch("reflex.utils.prerequisites.zipfile.ZipFile")
  433. mocker.patch("reflex.utils.prerequisites.path_ops.rm")
  434. prerequisites.install_node()
  435. assert fnm_root_path.exists()
  436. download.assert_called_once()
  437. @pytest.mark.parametrize(
  438. "machine, system",
  439. [
  440. ("x64", "Darwin"),
  441. ("arm64", "Darwin"),
  442. ("x64", "Windows"),
  443. ("arm64", "Windows"),
  444. ("armv7", "Linux"),
  445. ("armv8-a", "Linux"),
  446. ("armv8.1-a", "Linux"),
  447. ("armv8.2-a", "Linux"),
  448. ("armv8.3-a", "Linux"),
  449. ("armv8.4-a", "Linux"),
  450. ("aarch64", "Linux"),
  451. ("aarch32", "Linux"),
  452. ],
  453. )
  454. def test_node_install_unix(tmp_path, mocker, machine, system):
  455. fnm_root_path = tmp_path / "reflex" / "fnm"
  456. fnm_exe = fnm_root_path / "fnm"
  457. mocker.patch("reflex.utils.prerequisites.constants.Fnm.DIR", fnm_root_path)
  458. mocker.patch("reflex.utils.prerequisites.constants.Fnm.EXE", fnm_exe)
  459. mocker.patch("reflex.utils.prerequisites.constants.IS_WINDOWS", False)
  460. mocker.patch("reflex.utils.prerequisites.platform.machine", return_value=machine)
  461. mocker.patch("reflex.utils.prerequisites.platform.system", return_value=system)
  462. class Resp(Base):
  463. status_code = 200
  464. text = "test"
  465. mocker.patch("httpx.stream", return_value=Resp())
  466. download = mocker.patch("reflex.utils.prerequisites.download_and_extract_fnm_zip")
  467. process = mocker.patch("reflex.utils.processes.new_process")
  468. chmod = mocker.patch("pathlib.Path.chmod")
  469. mocker.patch("reflex.utils.processes.stream_logs")
  470. prerequisites.install_node()
  471. assert fnm_root_path.exists()
  472. download.assert_called_once()
  473. if system == "Darwin" and machine == "arm64":
  474. process.assert_called_with(
  475. [
  476. fnm_exe,
  477. "install",
  478. "--arch=arm64",
  479. constants.Node.VERSION,
  480. "--fnm-dir",
  481. fnm_root_path,
  482. ]
  483. )
  484. else:
  485. process.assert_called_with(
  486. [fnm_exe, "install", constants.Node.VERSION, "--fnm-dir", fnm_root_path]
  487. )
  488. chmod.assert_called_once()
  489. def test_bun_install_without_unzip(mocker):
  490. """Test that an error is thrown when installing bun with unzip not installed.
  491. Args:
  492. mocker: Pytest mocker object.
  493. """
  494. mocker.patch("reflex.utils.path_ops.which", return_value=None)
  495. mocker.patch("pathlib.Path.exists", return_value=False)
  496. mocker.patch("reflex.utils.prerequisites.constants.IS_WINDOWS", False)
  497. with pytest.raises(SystemPackageMissingError):
  498. prerequisites.install_bun()
  499. @pytest.mark.parametrize("bun_version", [constants.Bun.VERSION, "1.0.0"])
  500. def test_bun_install_version(mocker, bun_version):
  501. """Test that bun is downloaded when the host version(installed by reflex)
  502. different from the current version set in reflex.
  503. Args:
  504. mocker: Pytest mocker object.
  505. bun_version: the host bun version
  506. """
  507. mocker.patch("reflex.utils.prerequisites.constants.IS_WINDOWS", False)
  508. mocker.patch("pathlib.Path.exists", return_value=True)
  509. mocker.patch(
  510. "reflex.utils.prerequisites.get_bun_version",
  511. return_value=version.parse(bun_version),
  512. )
  513. mocker.patch("reflex.utils.path_ops.which")
  514. mock = mocker.patch("reflex.utils.prerequisites.download_and_run")
  515. prerequisites.install_bun()
  516. if bun_version == constants.Bun.VERSION:
  517. mock.assert_not_called()
  518. else:
  519. mock.assert_called_once()
  520. @pytest.mark.parametrize("is_windows", [True, False])
  521. def test_create_reflex_dir(mocker, is_windows):
  522. """Test that a reflex directory is created on initializing frontend
  523. dependencies.
  524. Args:
  525. mocker: Pytest mocker object.
  526. is_windows: Whether platform is windows.
  527. """
  528. mocker.patch("reflex.utils.prerequisites.constants.IS_WINDOWS", is_windows)
  529. mocker.patch("reflex.utils.prerequisites.processes.run_concurrently", mocker.Mock())
  530. mocker.patch("reflex.utils.prerequisites.initialize_web_directory", mocker.Mock())
  531. mocker.patch("reflex.utils.processes.run_concurrently")
  532. mocker.patch("reflex.utils.prerequisites.validate_bun")
  533. create_cmd = mocker.patch(
  534. "reflex.utils.prerequisites.path_ops.mkdir", mocker.Mock()
  535. )
  536. prerequisites.initialize_reflex_user_directory()
  537. assert create_cmd.called
  538. def test_output_system_info(mocker):
  539. """Make sure reflex does not crash dumping system info.
  540. Args:
  541. mocker: Pytest mocker object.
  542. This test makes no assertions about the output, other than it executes
  543. without crashing.
  544. """
  545. mocker.patch("reflex.utils.console._LOG_LEVEL", constants.LogLevel.DEBUG)
  546. utils_exec.output_system_info()
  547. @pytest.mark.parametrize(
  548. "callable", [ExampleTestState.test_event_handler, test_func, lambda x: x]
  549. )
  550. def test_style_prop_with_event_handler_value(callable):
  551. """Test that a type error is thrown when a style prop has a
  552. callable as value.
  553. Args:
  554. callable: The callable function or event handler.
  555. """
  556. import reflex as rx
  557. style = {
  558. "color": (
  559. EventHandler(fn=callable)
  560. if type(callable) is not EventHandler
  561. else callable
  562. )
  563. }
  564. with pytest.raises(ReflexError):
  565. rx.box(style=style) # pyright: ignore [reportArgumentType]
  566. def test_is_prod_mode() -> None:
  567. """Test that the prod mode is correctly determined."""
  568. environment.REFLEX_ENV_MODE.set(constants.Env.PROD)
  569. assert utils_exec.is_prod_mode()
  570. environment.REFLEX_ENV_MODE.set(None)
  571. assert not utils_exec.is_prod_mode()