def test_dir_hash_should_be_key_order_agnostic(tmp_dir, dvc): from dvc.objects.stage import stage from dvc.objects.tree import Tree tmp_dir.gen({"data": {"1": "1 content", "2": "2 content"}}) path = (tmp_dir / "data").fs_path tree = Tree.from_list([{ "relpath": "1", "md5": "1" }, { "relpath": "2", "md5": "2" }]) tree.digest() with patch("dvc.objects.stage._stage_tree", return_value=(None, tree)): _, _, obj = stage(dvc.odb.local, path, dvc.odb.local.fs, "md5") hash1 = obj.hash_info tree = Tree.from_list([{ "md5": "1", "relpath": "1" }, { "md5": "2", "relpath": "2" }]) tree.digest() with patch("dvc.objects.stage._stage_tree", return_value=(None, tree)): _, _, obj = stage(dvc.odb.local, path, dvc.odb.local.fs, "md5") hash2 = obj.hash_info assert hash1 == hash2
def test_dir_hash_should_be_key_order_agnostic(tmp_dir, dvc): from dvc.objects.stage import stage from dvc.objects.tree import Tree tmp_dir.gen({"data": {"1": "1 content", "2": "2 content"}}) path_info = PathInfo("data") tree = Tree.from_list( [{"relpath": "1", "md5": "1"}, {"relpath": "2", "md5": "2"}] ) tree.digest() with patch("dvc.objects.stage._get_tree_obj", return_value=tree): hash1 = stage( dvc.odb.local, path_info, dvc.odb.local.fs, "md5" ).hash_info tree = Tree.from_list( [{"md5": "1", "relpath": "1"}, {"md5": "2", "relpath": "2"}] ) tree.digest() with patch("dvc.objects.stage._get_tree_obj", return_value=tree): hash2 = stage( dvc.odb.local, path_info, dvc.odb.local.fs, "md5" ).hash_info assert hash1 == hash2
def test_list(lst, trie_dict): tree = Tree.from_list(lst) assert tree._dict == trie_dict assert tree.as_list() == sorted(lst, key=itemgetter("relpath"))