fix units tests

This commit is contained in:
Lendemor 2024-12-09 20:22:23 +01:00
parent 453c5177aa
commit fafb51dba5
2 changed files with 8 additions and 8 deletions

View File

@ -105,8 +105,8 @@ def test_initialize_requirements_txt_no_op(mocker):
return_value=Mock(best=lambda: Mock(encoding="utf-8")), return_value=Mock(best=lambda: Mock(encoding="utf-8")),
) )
mock_fp_touch = mocker.patch("pathlib.Path.touch") mock_fp_touch = mocker.patch("pathlib.Path.touch")
open_mock = mock_open(read_data="reflex==0.2.9") open_mock = mock_open(read_data="reflex==0.6.7")
mocker.patch("builtins.open", open_mock) mocker.patch("pathlib.Path.open", open_mock)
initialize_requirements_txt() initialize_requirements_txt()
assert open_mock.call_count == 1 assert open_mock.call_count == 1
assert open_mock.call_args.kwargs["encoding"] == "utf-8" 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")), return_value=Mock(best=lambda: Mock(encoding="utf-8")),
) )
open_mock = mock_open(read_data="random-package=1.2.3") 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() initialize_requirements_txt()
# Currently open for read, then open for append # Currently open for read, then open for append
assert open_mock.call_count == 2 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 # File does not exist, create file with reflex
mocker.patch("pathlib.Path.exists", return_value=False) mocker.patch("pathlib.Path.exists", return_value=False)
open_mock = mock_open() open_mock = mock_open()
mocker.patch("builtins.open", open_mock) mocker.patch("pathlib.Path.open", open_mock)
initialize_requirements_txt() initialize_requirements_txt()
assert open_mock.call_count == 2 assert open_mock.call_count == 2
# By default, use utf-8 encoding # By default, use utf-8 encoding
@ -170,7 +170,7 @@ def test_requirements_txt_other_encoding(mocker):
) )
initialize_requirements_txt() initialize_requirements_txt()
open_mock = mock_open(read_data="random-package=1.2.3") 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() initialize_requirements_txt()
# Currently open for read, then open for append # Currently open for read, then open for append
assert open_mock.call_count == 2 assert open_mock.call_count == 2

View File

@ -270,7 +270,7 @@ def test_unsupported_literals(cls: type):
("appname2.io", "AppnameioConfig"), ("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. """Test templates.RXCONFIG is formatted with correct app name and config class name.
Args: Args:
@ -278,7 +278,7 @@ def test_create_config(app_name, expected_config_name, mocker):
expected_config_name: Expected config name. expected_config_name: Expected config name.
mocker: Mocker object. mocker: Mocker object.
""" """
mocker.patch("builtins.open") mocker.patch("pathlib.Path.write_text")
tmpl_mock = mocker.patch("reflex.compiler.templates.RXCONFIG") tmpl_mock = mocker.patch("reflex.compiler.templates.RXCONFIG")
prerequisites.create_config(app_name) prerequisites.create_config(app_name)
tmpl_mock.render.assert_called_with( 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()) mocker.patch("httpx.stream", return_value=Resp())
download = mocker.patch("reflex.utils.prerequisites.download_and_extract_fnm_zip") download = mocker.patch("reflex.utils.prerequisites.download_and_extract_fnm_zip")
process = mocker.patch("reflex.utils.processes.new_process") 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") mocker.patch("reflex.utils.processes.stream_logs")
prerequisites.install_node() prerequisites.install_node()