diff --git a/dvc/remote/local/__init__.py b/dvc/remote/local/__init__.py index 3a4192721..299a6ad4b 100644 --- a/dvc/remote/local/__init__.py +++ b/dvc/remote/local/__init__.py @@ -7,7 +7,6 @@ import os import stat import errno from shortuuid import uuid -import shutil import logging from functools import partial @@ -172,7 +171,7 @@ class RemoteLOCAL(RemoteBASE): move(from_info, to_info, mode=mode) def copy(self, from_info, to_info): - shutil.copyfile(from_info.fspath, to_info.fspath) + System.copy(from_info, to_info) def symlink(self, from_info, to_info): System.symlink(from_info, to_info) diff --git a/dvc/system.py b/dvc/system.py index b445ec01a..c7c7cf8e4 100644 --- a/dvc/system.py +++ b/dvc/system.py @@ -4,6 +4,7 @@ from dvc.utils.compat import str, open, fspath import os import errno +import shutil class System(object): @@ -11,6 +12,11 @@ class System(object): def is_unix(): return os.name != "nt" + @staticmethod + def copy(src, dest): + src, dest = fspath(src), fspath(dest) + return shutil.copyfile(src, dest) + @staticmethod def hardlink(source, link_name): import ctypes diff --git a/tests/func/test_add.py b/tests/func/test_add.py index c11e0a3b6..c804fa203 100644 --- a/tests/func/test_add.py +++ b/tests/func/test_add.py @@ -563,12 +563,12 @@ def test_should_not_checkout_when_adding_cached_copy(repo_dir, dvc_repo): shutil.copy(repo_dir.BAR, repo_dir.FOO) - copy_spy = spy(shutil.copyfile) + copy_spy = spy(dvc_repo.cache.local.copy) - RemoteLOCAL.CACHE_TYPE_MAP["copy"] = copy_spy - dvc_repo.add(repo_dir.FOO) + with patch.object(dvc_repo.cache.local, "copy", copy_spy): + dvc_repo.add(repo_dir.FOO) - assert copy_spy.mock.call_count == 0 + assert copy_spy.mock.call_count == 0 @pytest.mark.parametrize( @@ -583,13 +583,13 @@ def test_should_not_checkout_when_adding_cached_copy(repo_dir, dvc_repo): def test_should_relink_on_repeated_add( link, new_link, link_test_func, repo_dir, dvc_repo ): - dvc_repo.cache.local.cache_types = [link] + dvc_repo.config.set("cache", "type", link) dvc_repo.add(repo_dir.FOO) dvc_repo.add(repo_dir.BAR) os.remove(repo_dir.FOO) - RemoteLOCAL.CACHE_TYPE_MAP[link](repo_dir.BAR, repo_dir.FOO) + getattr(dvc_repo.cache.local, link)(repo_dir.BAR, repo_dir.FOO) dvc_repo.cache.local.cache_types = [new_link] @@ -613,10 +613,11 @@ def test_should_relink_single_file_in_dir(link, link_func, dvc_repo, repo_dir): dvc_repo.unprotect(repo_dir.DATA_SUB) link_spy = spy(link_func) - RemoteLOCAL.CACHE_TYPE_MAP[link] = link_spy - dvc_repo.add(repo_dir.DATA_DIR) - assert link_spy.mock.call_count == 1 + with patch.object(dvc_repo.cache.local, link, link_spy): + dvc_repo.add(repo_dir.DATA_DIR) + + assert link_spy.mock.call_count == 1 @pytest.mark.parametrize("link", ["hardlink", "symlink", "copy"])