From ace61f4f30a35a370edf632c3b45ecefde0a6241 Mon Sep 17 00:00:00 2001 From: Lendemor Date: Mon, 10 Feb 2025 17:55:49 +0100 Subject: [PATCH] fix unit tests and mock object --- tests/units/utils/test_utils.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/units/utils/test_utils.py b/tests/units/utils/test_utils.py index a9b9e417c..8123d8ca5 100644 --- a/tests/units/utils/test_utils.py +++ b/tests/units/utils/test_utils.py @@ -126,21 +126,39 @@ def test_validate_none_bun_path(mocker): prerequisites.validate_bun() -def test_validate_invalid_bun_path(mocker): +@pytest.mark.parametrize( + "exists,samefile", + [ + (False, None), + (True, False), + ], +) +def test_validate_invalid_bun_path( + exists, + samefile, + mocker, +): """Test that an error is thrown when a custom specified bun path is not valid or does not exist. Args: + exists: Whether the bun path exists. + samefile: Whether the bun path is the same file. mocker: Pytest mocker object. """ mock_path = mocker.Mock() - mock_path.samefile.return_value = False + 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.prerequisites.get_bun_version", return_value=None) with pytest.raises(typer.Exit): 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):