Пример #1
0
def test_is_protected(tmp_dir, dvc, link_name):
    tree = LocalTree(dvc, {})
    link_method = getattr(tree, link_name)

    (tmp_dir / "foo").write_text("foo")

    foo = PathInfo(tmp_dir / "foo")
    link = PathInfo(tmp_dir / "link")

    link_method(foo, link)

    assert not tree.is_protected(foo)
    assert not tree.is_protected(link)

    tree.protect(foo)

    assert tree.is_protected(foo)
    assert tree.is_protected(link)

    tree.unprotect(link)

    assert not tree.is_protected(link)
    if os.name == "nt" and link_name == "hardlink":
        # NOTE: NTFS doesn't allow deleting read-only files, which forces us to
        # set write perms on the link, which propagates to the source.
        assert not tree.is_protected(foo)
    else:
        assert tree.is_protected(foo)
Пример #2
0
def test_protect_ignore_erofs(tmp_dir, mocker):
    tmp_dir.gen("foo", "foo")
    foo = PathInfo("foo")
    tree = LocalTree(None, {})

    mock_chmod = mocker.patch("os.chmod",
                              side_effect=OSError(errno.EROFS, "read-only fs"))
    tree.protect(foo)
    assert mock_chmod.called
Пример #3
0
def test_protect_ignore_errors(tmp_dir, mocker, err):
    tmp_dir.gen("foo", "foo")
    foo = PathInfo("foo")
    tree = LocalTree(None, {})

    tree.protect(foo)

    mock_chmod = mocker.patch("os.chmod",
                              side_effect=OSError(err, "something"))
    tree.protect(foo)
    assert mock_chmod.called