remote: base: dump dir_info json with sorted keys

This commit is contained in:
pared
2019-05-01 23:34:52 -07:00
parent 4e5ab29200
commit 28f7ccfc6c
2 changed files with 58 additions and 15 deletions
+38
View File
@@ -1,5 +1,6 @@
import os
import configobj
from dvc.remote.base import RemoteBase
from mock import patch
from dvc.main import main
@@ -183,3 +184,40 @@ def test_large_dir_progress(repo_dir, dvc):
with patch.object(progress, "update_target") as update_target:
dvc.add("gen")
assert update_target.called
def test_dir_checksum_should_be_key_order_agnostic(dvc):
data_dir = os.path.join(dvc.root_dir, "data")
file1 = os.path.join(data_dir, "1")
file2 = os.path.join(data_dir, "2")
os.mkdir(data_dir)
with open(file1, "w") as fobj:
fobj.write("1")
with open(file2, "w") as fobj:
fobj.write("2")
path_info = {"scheme": "local", "path": data_dir}
with dvc.state:
with patch.object(
RemoteBase,
"_collect_dir",
return_value=[
{"relpath": "1", "md5": "1"},
{"relpath": "2", "md5": "2"},
],
):
checksum1 = dvc.cache.local.get_dir_checksum(path_info)
with patch.object(
RemoteBase,
"_collect_dir",
return_value=[
{"md5": "1", "relpath": "1"},
{"md5": "2", "relpath": "2"},
],
):
checksum2 = dvc.cache.local.get_dir_checksum(path_info)
assert checksum1 == checksum2