fix units test again

This commit is contained in:
Lendemor 2025-02-10 18:48:13 +01:00
parent ace61f4f30
commit 8e2192a4b5
2 changed files with 3 additions and 21 deletions

View File

@ -1317,7 +1317,7 @@ def validate_bun():
if not path_ops.samefile(bun_path, constants.Bun.DEFAULT_PATH): if not path_ops.samefile(bun_path, constants.Bun.DEFAULT_PATH):
console.info(f"Using custom Bun path: {bun_path}") console.info(f"Using custom Bun path: {bun_path}")
bun_version = get_bun_version() bun_version = get_bun_version()
if not bun_version: if bun_version is None:
console.error( console.error(
"Failed to obtain bun version. Make sure the specified bun path in your config is correct." "Failed to obtain bun version. Make sure the specified bun path in your config is correct."
) )

View File

@ -126,39 +126,22 @@ def test_validate_none_bun_path(mocker):
prerequisites.validate_bun() prerequisites.validate_bun()
@pytest.mark.parametrize(
"exists,samefile",
[
(False, None),
(True, False),
],
)
def test_validate_invalid_bun_path( def test_validate_invalid_bun_path(
exists,
samefile,
mocker, mocker,
): ):
"""Test that an error is thrown when a custom specified bun path is not valid """Test that an error is thrown when a custom specified bun path is not valid
or does not exist. or does not exist.
Args: Args:
exists: Whether the bun path exists.
samefile: Whether the bun path is the same file.
mocker: Pytest mocker object. mocker: Pytest mocker object.
""" """
mock_path = mocker.Mock() mock_path = mocker.Mock()
mock_path.exists.return_value = exists
mock_path.samefile.return_value = samefile
mocker.patch("reflex.utils.path_ops.get_bun_path", return_value=mock_path) mocker.patch("reflex.utils.path_ops.get_bun_path", return_value=mock_path)
mocker.patch("reflex.utils.path_ops.samefile", return_value=False)
mocker.patch("reflex.utils.prerequisites.get_bun_version", return_value=None) mocker.patch("reflex.utils.prerequisites.get_bun_version", return_value=None)
with pytest.raises(typer.Exit): with pytest.raises(typer.Exit):
prerequisites.validate_bun() prerequisites.validate_bun()
mock_path.exists.assert_called_once()
if exists:
mock_path.samefile.assert_called_once()
else:
mock_path.samefile.assert_not_called()
def test_validate_bun_path_incompatible_version(mocker): def test_validate_bun_path_incompatible_version(mocker):
@ -170,6 +153,7 @@ def test_validate_bun_path_incompatible_version(mocker):
mock_path = mocker.Mock() mock_path = mocker.Mock()
mock_path.samefile.return_value = False mock_path.samefile.return_value = False
mocker.patch("reflex.utils.path_ops.get_bun_path", return_value=mock_path) mocker.patch("reflex.utils.path_ops.get_bun_path", return_value=mock_path)
mocker.patch("reflex.utils.path_ops.samefile", return_value=False)
mocker.patch( mocker.patch(
"reflex.utils.prerequisites.get_bun_version", "reflex.utils.prerequisites.get_bun_version",
return_value=version.parse("0.6.5"), return_value=version.parse("0.6.5"),
@ -177,8 +161,6 @@ def test_validate_bun_path_incompatible_version(mocker):
with pytest.raises(typer.Exit): with pytest.raises(typer.Exit):
prerequisites.validate_bun() prerequisites.validate_bun()
mock_path.exists.assert_called_once()
mock_path.samefile.assert_called_once()
def test_remove_existing_bun_installation(mocker): def test_remove_existing_bun_installation(mocker):