From 5cf1421c61668e90f377edd4b6450f492e83869e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saugat=20Pachhai=20=28=E0=A4=B8=E0=A5=8C=E0=A4=97=E0=A4=BE?= =?UTF-8?q?=E0=A4=A4=29?= Date: Wed, 24 Aug 2022 13:16:31 +0545 Subject: [PATCH] fix tests --- dvc/repo/data.py | 6 +++--- tests/func/test_data_status.py | 32 ++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/dvc/repo/data.py b/dvc/repo/data.py index e7807bc00..4c5311a48 100644 --- a/dvc/repo/data.py +++ b/dvc/repo/data.py @@ -109,7 +109,9 @@ def _diff( with_dirs: bool = False, granular: bool = False, ): - if not granular or not (old_obj or new_obj): + if not granular: + return _shallow_diff(root, old_oid, new_oid, odb) + if (old_oid and not old_obj) or (new_oid and not new_obj): # we don't have enough information to give full details return _shallow_diff(root, old_oid, new_oid, odb) return _granular_diff(root, old_obj, new_obj, odb, with_dirs=with_dirs) @@ -174,8 +176,6 @@ def _diff_index_to_wtree(repo: "Repo", **kwargs: Any) -> Dict[str, List[str]]: cache = repo.odb.repo root = str(out) old = out.get_obj() - if not old and new and out.hash_info == new.hash_info: - old = new with ui.status(f"Calculating diff for {root} between index/workspace"): d = _diff( diff --git a/tests/func/test_data_status.py b/tests/func/test_data_status.py index 3eceeb823..47b54d979 100644 --- a/tests/func/test_data_status.py +++ b/tests/func/test_data_status.py @@ -153,7 +153,9 @@ def test_untracked_newly_added_files(M, tmp_dir, dvc, scm): expected = { **EMPTY_STATUS, - "untracked": M.unordered("dir/foo", "dir/bar", "foobar"), + "untracked": M.unordered( + join("dir", "foo"), join("dir", "bar"), "foobar" + ), "git": M.dict(), } assert dvc.data_status(untracked_files="all") == expected @@ -186,7 +188,8 @@ def test_missing_cache_workspace_exists(M, tmp_dir, dvc, scm): # even though we don't have cache obj, we can repurpose # what we have in the workspace "not_in_cache": M.unordered( - "foobar", join("dir", "bar"), join("dir", "foo") + "foobar", + join("dir", ""), ), "git": M.dict(), } @@ -200,19 +203,19 @@ def test_missing_cache_missing_workspace(M, tmp_dir, dvc, scm): assert dvc.data_status(untracked_files="all") == { **EMPTY_STATUS, - "untracked": ["foobar.dvc", "dir.dvc", ".gitignore"], - "uncommitted": {"deleted": ["foobar", join("dir", "")]}, - "committed": {"added": ["foobar", join("dir", "")]}, - "not_in_cache": ["foobar", join("dir", "")], + "untracked": M.unordered("foobar.dvc", "dir.dvc", ".gitignore"), + "uncommitted": {"deleted": M.unordered("foobar", join("dir", ""))}, + "committed": {"added": M.unordered("foobar", join("dir", ""))}, + "not_in_cache": M.unordered("foobar", join("dir", "")), "git": M.dict(), } assert dvc.data_status(granular=True, untracked_files="all") == { **EMPTY_STATUS, - "untracked": ["foobar.dvc", "dir.dvc", ".gitignore"], - "uncommitted": {"deleted": ["foobar", join("dir", "")]}, - "committed": {"added": ["foobar", join("dir", "")]}, - "not_in_cache": ["foobar", join("dir", "")], + "untracked": M.unordered("foobar.dvc", "dir.dvc", ".gitignore"), + "uncommitted": {"deleted": M.unordered("foobar", join("dir", ""))}, + "committed": {"added": M.unordered("foobar", join("dir", ""))}, + "not_in_cache": M.unordered("foobar", join("dir", "")), "git": M.dict(), } @@ -224,7 +227,7 @@ def test_git_committed_missing_cache_workspace_exists(M, tmp_dir, dvc, scm): assert dvc.data_status(untracked_files="all") == { **EMPTY_STATUS, - "not_in_cache": ["foobar", join("dir", "")], + "not_in_cache": M.unordered("foobar", join("dir", "")), "git": M.dict(), # TODO: clarify what is unchanged "unchanged": M.unordered("foobar", join("dir", "")), @@ -232,11 +235,12 @@ def test_git_committed_missing_cache_workspace_exists(M, tmp_dir, dvc, scm): assert dvc.data_status(granular=True) == { **EMPTY_STATUS, "not_in_cache": M.unordered( - "foobar", join("dir", "foo"), join("dir", "bar") + "foobar", + join("dir", ""), ), "git": M.dict(), # TODO: clarify what is unchanged - "unchanged": M.unordered("foobar"), + "unchanged": M.unordered("foobar", join("dir", "")), } @@ -299,7 +303,7 @@ def test_missing_dir_object_from_head(M, tmp_dir, dvc, scm): } assert dvc.data_status(granular=True) == { **EMPTY_STATUS, - "committed": {"added": [join("dir", "foobar")]}, + "committed": {"modified": [join("dir", "")]}, "git": M.dict(), }