From c96795dcfbe8febf3305a56ad9f5258ac0a16cd8 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Fri, 9 Jun 2023 19:10:08 +0300 Subject: [PATCH] tests: checkout: fix test_checkout_relink_protected on windows --- tests/func/test_checkout.py | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/tests/func/test_checkout.py b/tests/func/test_checkout.py index 6a20ff132..eda509ba6 100644 --- a/tests/func/test_checkout.py +++ b/tests/func/test_checkout.py @@ -324,30 +324,25 @@ def test_checkout_relink(tmp_dir, dvc, link, link_test_func): dvc.cache.local.cache_types = [link] tmp_dir.dvc_gen({"dir": {"data": "text"}}) - dvc.unprotect("dir/data") - assert not link_test_func("dir/data") + + data_file = os.path.join("dir", "data") + + # NOTE: Windows symlink perms don't propagate to the target + if not (os.name == "nt" and link == "symlink"): + assert not os.access(data_file, os.W_OK) + + dvc.unprotect(data_file) + assert os.access(data_file, os.W_OK) + assert not link_test_func(data_file) stats = dvc.checkout(["dir.dvc"], relink=True) assert stats == empty_checkout - assert link_test_func("dir/data") + assert link_test_func(data_file) - -@pytest.mark.parametrize("link", ["hardlink", "symlink", "copy"]) -def test_checkout_relink_protected(tmp_dir, dvc, link): - dvc.cache.local.cache_types = [link] - - tmp_dir.dvc_gen("foo", "foo") - dvc.unprotect("foo") - assert os.access("foo", os.W_OK) - - stats = dvc.checkout(["foo.dvc"], relink=True) - assert stats == empty_checkout - - # NOTE: Windows symlink perms don't propagate to the target - if link == "copy" or (link == "symlink" and os.name == "nt"): - assert os.access("foo", os.W_OK) - else: - assert not os.access("foo", os.W_OK) + # NOTE: Windows symlink perms don't propagate to the target and + # hardlink was chmod-ed during relink to be deleted + if not (os.name == "nt" and link in ["symlink", "hardlink"]): + assert not os.access(data_file, os.W_OK) @pytest.mark.parametrize(