diff --git a/tests/units/test_prerequisites.py b/tests/units/test_prerequisites.py index 2497318e7..90afe0963 100644 --- a/tests/units/test_prerequisites.py +++ b/tests/units/test_prerequisites.py @@ -105,8 +105,8 @@ def test_initialize_requirements_txt_no_op(mocker): return_value=Mock(best=lambda: Mock(encoding="utf-8")), ) mock_fp_touch = mocker.patch("pathlib.Path.touch") - open_mock = mock_open(read_data="reflex==0.2.9") - mocker.patch("builtins.open", open_mock) + open_mock = mock_open(read_data="reflex==0.6.7") + mocker.patch("pathlib.Path.open", open_mock) initialize_requirements_txt() assert open_mock.call_count == 1 assert open_mock.call_args.kwargs["encoding"] == "utf-8" @@ -122,7 +122,7 @@ def test_initialize_requirements_txt_missing_reflex(mocker): return_value=Mock(best=lambda: Mock(encoding="utf-8")), ) open_mock = mock_open(read_data="random-package=1.2.3") - mocker.patch("builtins.open", open_mock) + mocker.patch("pathlib.Path.open", open_mock) initialize_requirements_txt() # Currently open for read, then open for append assert open_mock.call_count == 2 @@ -138,7 +138,7 @@ def test_initialize_requirements_txt_not_exist(mocker): # File does not exist, create file with reflex mocker.patch("pathlib.Path.exists", return_value=False) open_mock = mock_open() - mocker.patch("builtins.open", open_mock) + mocker.patch("pathlib.Path.open", open_mock) initialize_requirements_txt() assert open_mock.call_count == 2 # By default, use utf-8 encoding @@ -170,7 +170,7 @@ def test_requirements_txt_other_encoding(mocker): ) initialize_requirements_txt() open_mock = mock_open(read_data="random-package=1.2.3") - mocker.patch("builtins.open", open_mock) + mocker.patch("pathlib.Path.open", open_mock) initialize_requirements_txt() # Currently open for read, then open for append assert open_mock.call_count == 2 diff --git a/tests/units/utils/test_utils.py b/tests/units/utils/test_utils.py index a13652bc4..710930f25 100644 --- a/tests/units/utils/test_utils.py +++ b/tests/units/utils/test_utils.py @@ -270,7 +270,7 @@ def test_unsupported_literals(cls: type): ("appname2.io", "AppnameioConfig"), ], ) -def test_create_config(app_name, expected_config_name, mocker): +def test_create_config(app_name: str, expected_config_name: str, mocker): """Test templates.RXCONFIG is formatted with correct app name and config class name. Args: @@ -278,7 +278,7 @@ def test_create_config(app_name, expected_config_name, mocker): expected_config_name: Expected config name. mocker: Mocker object. """ - mocker.patch("builtins.open") + mocker.patch("pathlib.Path.write_text") tmpl_mock = mocker.patch("reflex.compiler.templates.RXCONFIG") prerequisites.create_config(app_name) tmpl_mock.render.assert_called_with( @@ -464,7 +464,7 @@ def test_node_install_unix(tmp_path, mocker, machine, system): mocker.patch("httpx.stream", return_value=Resp()) download = mocker.patch("reflex.utils.prerequisites.download_and_extract_fnm_zip") process = mocker.patch("reflex.utils.processes.new_process") - chmod = mocker.patch("reflex.utils.prerequisites.os.chmod") + chmod = mocker.patch("pathlib.Path.chmod") mocker.patch("reflex.utils.processes.stream_logs") prerequisites.install_node()