Files
dvc/tests/func/test_state.py
T
b349b39d62 Decoupling dvcignore and fs (#5812)
* Decoupling dvcignore and fs

[x] remove dvcignore from fs objects
[x] attach dvcignore to repo
[x] add ignore check to functions(add, checkout, output, pipeline, etc)
[x] pass all tests
[x] final check

* Solve all of the arugments error.

* add dvcignore to dvc list

* Solve some test_ignore cases

* add dvcignore to checkout.

1. add dvcignore to 'checkout', 'add'
2. add ignore_filter to fs

* Solve two tests

* Get rid of ignore_filter

* Add ignore examine to download

* Solve a test issue

* Solve dvcignore and subrepo problems

* Solve sub repo error

* Revert some changes

* pass all tests

* Remove debug codes

* Some final exams

* dvcignore trie tree only update when needed

* reuse of the dir result in path walk.

* Some change after code review.

* Recover something from false `--force` push

* add abspath trans to dvcginore

* pass pylint

* pylint related

* Update dvc/fs/repo.py

Co-authored-by: Ruslan Kuprieiev <[email protected]>

* Changes related to reviews.

* dvcignore call api change

from dvcignore.walk_files(fs.walk(path_info)) to dvcignore.walk_files(fs, path_info)

* Get rid of PathInfo in test_ignore.py

* fs.walk follow the arguments of os.walk

* Dvcignore as parameters

* pass dvcignore as arguments to checkouts

* Decoupling state and repo

* Update dvc/dvcfile.py

Co-authored-by: Paweł Redzyński <[email protected]>

* Update dvc/objects/stage.py

Co-authored-by: Paweł Redzyński <[email protected]>

* Solve some small problems

* Add tests to verify that dependency now not ignore

fix#5256

* Update dvc/ignore.py

* Update dvc/fs/git.py

* Update dvc/repo/__init__.py

* Some small improvements

* pass black

* Refactor is_ignored

* Update dvc/output/base.py

* repofs: use dvcignore in exists/isdir/isfile

Per https://github.com/iterative/dvc/pull/5812/files#r630604524

Co-authored-by: myname <[email protected]>
Co-authored-by: Ruslan Kuprieiev <[email protected]>
Co-authored-by: Paweł Redzyński <[email protected]>
Co-authored-by: Ruslan Kuprieiev <[email protected]>
2021-05-12 05:29:04 +03:00

74 lines
1.9 KiB
Python

import os
from dvc.hash_info import HashInfo
from dvc.path_info import PathInfo
from dvc.state import State
from dvc.utils import file_md5
def test_state(tmp_dir, dvc):
tmp_dir.gen("foo", "foo content")
path = tmp_dir / "foo"
path_info = PathInfo(path)
hash_info = HashInfo("md5", file_md5(path, dvc.fs))
state = State(dvc.root_dir, dvc.tmp_dir, dvc.dvcignore)
state.save(path_info, dvc.fs, hash_info)
assert state.get(path_info, dvc.fs) == hash_info
path.unlink()
path.write_text("1")
assert state.get(path_info, dvc.fs) is None
hash_info = HashInfo("md5", file_md5(path, dvc.fs))
state.save(path_info, dvc.fs, hash_info)
assert state.get(path_info, dvc.fs) == hash_info
def test_state_overflow(tmp_dir, dvc):
# NOTE: trying to add more entries than state can handle,
# to see if it will clean up and vacuum successfully
dvc.config["state"]["row_limit"] = 10
path = tmp_dir / "dir"
path.mkdir()
for i in range(20):
(path / str(i)).write_text(str(i))
dvc.add("dir")
def mock_get_inode(inode):
def get_inode_mocked(_):
return inode
return get_inode_mocked
def test_remove_links(tmp_dir, dvc):
tmp_dir.dvc_gen({"foo": "foo_content", "bar": "bar_content"})
assert len(dvc.state.links) == 2
dvc.state.remove_links(["foo", "bar"], dvc.fs)
assert len(dvc.state.links) == 0
def test_get_unused_links(tmp_dir, dvc):
tmp_dir.dvc_gen({"foo": "foo_content", "bar": "bar_content"})
links = [os.path.join(dvc.root_dir, link) for link in ["foo", "bar"]]
assert set(dvc.state.get_unused_links([], dvc.fs)) == {"foo", "bar"}
assert set(dvc.state.get_unused_links(links[:1], dvc.fs)) == {"bar"}
assert set(dvc.state.get_unused_links(links, dvc.fs)) == set()
assert set(
dvc.state.get_unused_links(
(links[:1] + [os.path.join(dvc.root_dir, "not-existing-file")]),
dvc.fs,
)
) == {"bar"}