def test_get_hash_dirty_file(tmp_dir, dvc): from dvc_data import check from dvc_data.hashfile.hash import hash_file tmp_dir.dvc_gen("file", "file") file_hash_info = HashInfo("md5", "8c7dd922ad47494fc02c388e12c00eac") (tmp_dir / "file").write_text("something") something_hash_info = HashInfo("md5", "437b930db84b8079c2dd804a71936b5f") # file is modified in workspace # hash_file(file) should return workspace hash, not DVC cached hash fs = DvcFileSystem(repo=dvc) assert fs.info("file").get("md5") is None staging, _, obj = stage(dvc.odb.local, "file", fs, "md5") assert obj.hash_info == something_hash_info check(staging, obj) # hash_file(file) should return DVC cached hash (tmp_dir / "file").unlink() assert fs.info("file")["md5"] == file_hash_info.value _, hash_info = hash_file("file", fs, "md5", state=dvc.state) assert hash_info == file_hash_info # tmp_dir/file can be staged even though it is missing in workspace since # repofs will use the DVC cached hash (and refer to the local cache object) _, _, obj = stage(dvc.odb.local, "file", fs, "md5") assert obj.hash_info == file_hash_info
def test_get_hash_cached_file(tmp_dir, dvc, mocker): tmp_dir.dvc_gen({"foo": "foo"}) fs = DvcFileSystem(repo=dvc) expected = "acbd18db4cc2f85cedef654fccc4a4d8" assert fs.info("foo").get("md5") is None _, _, obj = stage(dvc.odb.local, "foo", fs, "md5") assert obj.hash_info == HashInfo("md5", expected) (tmp_dir / "foo").unlink() assert fs.info("foo")["md5"] == expected
def test_get_hash_granular(tmp_dir, dvc): tmp_dir.dvc_gen( {"dir": {"foo": "foo", "bar": "bar", "subdir": {"data": "data"}}} ) fs = DvcFileSystem(repo=dvc) subdir = "dir/subdir" assert fs.info(subdir).get("md5") is None _, _, obj = stage(dvc.odb.local, subdir, fs, "md5", dry_run=True) assert obj.hash_info == HashInfo( "md5", "af314506f1622d107e0ed3f14ec1a3b5.dir" ) data = posixpath.join(subdir, "data") assert fs.info(data)["md5"] == "8d777f385d3dfec8815d20f7496026dc" _, _, obj = stage(dvc.odb.local, data, fs, "md5", dry_run=True) assert obj.hash_info == HashInfo("md5", "8d777f385d3dfec8815d20f7496026dc")
def test_get_hash_file(tmp_dir, dvc): tmp_dir.dvc_gen({"foo": "foo"}) fs = DvcFileSystem(repo=dvc) assert ( fs.info((tmp_dir / "foo").fs_path)["md5"] == "acbd18db4cc2f85cedef654fccc4a4d8" )
def test_get_hash_granular(tmp_dir, dvc): tmp_dir.dvc_gen( {"dir": {"foo": "foo", "bar": "bar", "subdir": {"data": "data"}}} ) fs = DvcFileSystem(repo=dvc) subdir = PathInfo(tmp_dir) / "dir" / "subdir" assert fs.info(subdir).get("md5") is None assert stage(dvc.odb.local, subdir, fs, "md5").hash_info == HashInfo( "md5", "af314506f1622d107e0ed3f14ec1a3b5.dir", ) assert ( fs.info(subdir / "data")["md5"] == "8d777f385d3dfec8815d20f7496026dc" ) assert stage( dvc.odb.local, subdir / "data", fs, "md5" ).hash_info == HashInfo("md5", "8d777f385d3dfec8815d20f7496026dc",)
def test_get_hash_dirty_dir(tmp_dir, dvc): tmp_dir.dvc_gen({"dir": {"foo": "foo", "bar": "bar"}}) (tmp_dir / "dir" / "baz").write_text("baz") fs = DvcFileSystem(repo=dvc) expected = "5ea40360f5b4ec688df672a4db9c17d1.dir" assert fs.info("dir").get("md5") == expected _, _, obj = stage(dvc.odb.local, "dir", fs, "md5", dry_run=True) assert obj.hash_info == HashInfo("md5", expected)
def test_get_hash_dirty_file(tmp_dir, dvc): tmp_dir.dvc_gen("file", "file") (tmp_dir / "file").write_text("something") fs = DvcFileSystem(repo=dvc) expected = "8c7dd922ad47494fc02c388e12c00eac" assert fs.info("file").get("md5") == expected _, _, obj = stage(dvc.odb.local, "file", fs, "md5", dry_run=True) assert obj.hash_info == HashInfo("md5", expected)
def test_get_hash_dirty_dir(tmp_dir, dvc): tmp_dir.dvc_gen({"dir": {"foo": "foo", "bar": "bar"}}) (tmp_dir / "dir" / "baz").write_text("baz") fs = DvcFileSystem(dvc) expected = "5ea40360f5b4ec688df672a4db9c17d1.dir" assert fs.info(PathInfo(tmp_dir) / "dir").get("md5") == expected assert get_hash(PathInfo(tmp_dir) / "dir", fs, "md5") == HashInfo("md5", expected)
def test_get_hash_dirty_file(tmp_dir, dvc): tmp_dir.dvc_gen("file", "file") (tmp_dir / "file").write_text("something") fs = DvcFileSystem(dvc) expected = "8c7dd922ad47494fc02c388e12c00eac" assert fs.info(PathInfo(tmp_dir) / "file").get("md5") == expected assert get_hash(PathInfo(tmp_dir) / "file", fs, "md5") == HashInfo("md5", expected)
def test_get_hash_cached_dir(tmp_dir, dvc, mocker): tmp_dir.dvc_gen( {"dir": {"foo": "foo", "bar": "bar", "subdir": {"data": "data"}}} ) fs = DvcFileSystem(repo=dvc) expected = "8761c4e9acad696bee718615e23e22db.dir" assert fs.info("dir").get("md5") is None _, _, obj = stage(dvc.odb.local, "dir", fs, "md5") assert obj.hash_info == HashInfo( "md5", "8761c4e9acad696bee718615e23e22db.dir" ) shutil.rmtree(tmp_dir / "dir") assert fs.info("dir")["md5"] == expected _, _, obj = stage(dvc.odb.local, "dir", fs, "md5") assert obj.hash_info == HashInfo( "md5", "8761c4e9acad696bee718615e23e22db.dir" )
def test_get_hash_dir(tmp_dir, dvc, mocker): import dvc as dvc_module tmp_dir.dvc_gen( {"dir": {"foo": "foo", "bar": "bar", "subdir": {"data": "data"}}} ) fs = DvcFileSystem(repo=dvc) get_file_hash_spy = mocker.spy(dvc_module.data.stage, "get_file_hash") assert fs.info("dir")["md5"] == "8761c4e9acad696bee718615e23e22db.dir" assert not get_file_hash_spy.called
def test_get_hash_cached_granular(tmp_dir, dvc, mocker): tmp_dir.dvc_gen( {"dir": {"foo": "foo", "bar": "bar", "subdir": {"data": "data"}}} ) fs = DvcFileSystem(repo=dvc) subdir = "dir/subdir" assert fs.info(subdir).get("md5") is None _, _, obj = stage(dvc.odb.local, subdir, fs, "md5") assert obj.hash_info == HashInfo( "md5", "af314506f1622d107e0ed3f14ec1a3b5.dir" ) assert fs.info(posixpath.join(subdir, "data")).get("md5") is None _, _, obj = stage(dvc.odb.local, posixpath.join(subdir, "data"), fs, "md5") assert obj.hash_info == HashInfo("md5", "8d777f385d3dfec8815d20f7496026dc") (tmp_dir / "dir" / "subdir" / "data").unlink() assert ( fs.info(posixpath.join(subdir, "data"))["md5"] == "8d777f385d3dfec8815d20f7496026dc" )
def test_get_hash_file(tmp_dir, dvc): tmp_dir.dvc_gen({"foo": "foo"}) fs = DvcFileSystem(dvc) assert (fs.info(PathInfo(tmp_dir) / "foo")["md5"] == "acbd18db4cc2f85cedef654fccc4a4d8")