fixup! Make tree.walk() output deterministic

This commit is contained in:
Dani Hodovic
2019-12-05 21:05:01 +01:00
parent 97862a3d5f
commit 8c3ffe816d
4 changed files with 11 additions and 25 deletions
-5
View File
@@ -296,11 +296,6 @@ def dvc_walk(top, dvcignore, topdown=True, onerror=None, followlinks=False):
for root, dirs, files in os.walk(
top, topdown=topdown, onerror=onerror, followlinks=followlinks
):
# Dirs are returned in arbitrary order on different platforms. Force a
# specific order so that we can make deterministic assumptions on the
# directory order.
# https://stackoverflow.com/a/54773660/2966951
dirs.sort()
if dvcignore:
dirs[:], files[:] = dvcignore(root, dirs, files)
-9
View File
@@ -48,12 +48,6 @@ class TestDirFixture(object):
)
UNICODE = "тест"
UNICODE_CONTENTS = "проверка"
REGULAR_DIR = "lib"
REGULAR_FILE = os.path.join(REGULAR_DIR, "file.txt")
REGULAR_FILE_CONTENTS = """
A file used to test retrieval of regular files tracked by git that
are not stored in a dvc remote backend.
"""
def __init__(self):
root_dir = self.mkdtemp()
@@ -102,8 +96,6 @@ class TestDirFixture(object):
self.create(self.DATA, self.DATA_CONTENTS)
self.create(self.DATA_SUB, self.DATA_SUB_CONTENTS)
self.create(self.UNICODE, self.UNICODE_CONTENTS)
os.mkdir(self.REGULAR_DIR)
self.create(self.REGULAR_FILE, self.REGULAR_FILE_CONTENTS)
def tearDown(self):
self._popd()
@@ -145,7 +137,6 @@ class TestGitFixture(TestDirFixture):
raise
self.git.index.add([self.CODE])
self.git.index.add([self.REGULAR_DIR])
self.git.index.commit("add code")
def tearDown(self):
+8 -5
View File
@@ -38,9 +38,10 @@ def test_get_repo_dir(erepo):
trees_equal(src, dst)
def test_get_regular_file(repo_dir, erepo):
src = erepo.REGULAR_FILE
dst = erepo.REGULAR_FILE + "_imported"
def test_get_regular_file(erepo):
src = os.path.join(erepo.root_dir, "file")
dst = src + "_imported"
erepo.create(src, "hello")
Repo.get(erepo.root_dir, src, dst)
@@ -50,9 +51,11 @@ def test_get_regular_file(repo_dir, erepo):
def test_get_regular_dir(repo_dir, erepo):
src = erepo.REGULAR_DIR
dst = erepo.REGULAR_DIR + "_imported"
src = os.path.join(erepo.root_dir, "directory")
dst = src + "_imported"
os.mkdir(src)
erepo.create(os.path.join(src, "file"), "hello")
Repo.get(erepo.root_dir, src, dst)
assert os.path.exists(dst)
+3 -6
View File
@@ -115,7 +115,7 @@ class TestWalkInNoSCM(AssertWalkEqualMixin, TestDir):
[
(
self._root_dir,
["lib", "data_dir"],
["data_dir"],
["code.py", "bar", "тест", "foo"],
),
(join(self._root_dir, "data_dir"), ["data_sub_dir"], ["data"]),
@@ -124,7 +124,6 @@ class TestWalkInNoSCM(AssertWalkEqualMixin, TestDir):
[],
["data_sub"],
),
(join(self._root_dir, "lib"), [], ["file.txt"]),
],
)
@@ -152,7 +151,7 @@ class TestWalkInGit(AssertWalkEqualMixin, TestGit):
[
(
self._root_dir,
["lib", "data_dir"],
["data_dir"],
["bar", "тест", "code.py", "foo"],
),
(join(self._root_dir, "data_dir"), ["data_sub_dir"], ["data"]),
@@ -161,7 +160,6 @@ class TestWalkInGit(AssertWalkEqualMixin, TestGit):
[],
["data_sub"],
),
(join(self._root_dir, "lib"), [], ["file.txt"]),
],
)
self.assertWalkEqual(
@@ -183,14 +181,13 @@ class TestWalkInGit(AssertWalkEqualMixin, TestGit):
self.assertWalkEqual(
tree.walk("."),
[
(self._root_dir, ["data_dir", "lib"], ["code.py"]),
(self._root_dir, ["data_dir"], ["code.py"]),
(join(self._root_dir, "data_dir"), ["data_sub_dir"], []),
(
join(self._root_dir, "data_dir", "data_sub_dir"),
[],
["data_sub"],
),
(join(self._root_dir, "lib"), [], ["file.txt"]),
],
)
self.assertWalkEqual(