Move copyfile to fs.py

This commit is contained in:
Aman Sharma
2020-01-09 04:57:53 +05:30
parent eca5d2dde4
commit a79816920d
7 changed files with 78 additions and 78 deletions
+28
View File
@@ -1,3 +1,4 @@
import filecmp
import os
from unittest import TestCase
@@ -11,6 +12,7 @@ from dvc.scm.tree import WorkingTree
from dvc.system import System
from dvc.utils import relpath
from dvc.utils.fs import BasePathNotInCheckedPathException
from dvc.utils.fs import copyfile
from dvc.utils.fs import contains_symlink_up_to
from dvc.utils.fs import get_inode
from dvc.utils.fs import get_mtime_and_size
@@ -216,3 +218,29 @@ def test_makedirs(repo_dir):
makedirs(path_info)
assert os.path.isdir(path_info.fspath)
@pytest.mark.parametrize("path", [TestDir.DATA, TestDir.DATA_DIR])
def test_copyfile(path, repo_dir):
src = repo_dir.FOO
dest = path
src_info = PathInfo(repo_dir.BAR)
dest_info = PathInfo(path)
copyfile(src, dest)
if os.path.isdir(dest):
assert filecmp.cmp(
src, os.path.join(dest, os.path.basename(src)), shallow=False
)
else:
assert filecmp.cmp(src, dest, shallow=False)
copyfile(src_info, dest_info)
if os.path.isdir(dest_info.fspath):
assert filecmp.cmp(
src_info.fspath,
os.path.join(dest_info.fspath, os.path.basename(src_info.fspath)),
shallow=False,
)
else:
assert filecmp.cmp(src_info.fspath, dest_info.fspath, shallow=False)
-29
View File
@@ -1,18 +1,15 @@
import filecmp
import re
import os
import pytest
from dvc.path_info import PathInfo
from dvc.utils import copyfile
from dvc.utils import file_md5
from dvc.utils import fix_env
from dvc.utils import relpath
from dvc.utils import to_chunks
from dvc.utils import tmp_fname
from dvc.utils import walk_files
from tests.basic_env import TestDir
@pytest.mark.parametrize(
@@ -88,32 +85,6 @@ def test_file_md5(repo_dir):
assert file_md5(fname) == file_md5(fname_object)
@pytest.mark.parametrize("path", [TestDir.DATA, TestDir.DATA_DIR])
def test_copyfile(path, repo_dir):
src = repo_dir.FOO
dest = path
src_info = PathInfo(repo_dir.BAR)
dest_info = PathInfo(path)
copyfile(src, dest)
if os.path.isdir(dest):
assert filecmp.cmp(
src, os.path.join(dest, os.path.basename(src)), shallow=False
)
else:
assert filecmp.cmp(src, dest, shallow=False)
copyfile(src_info, dest_info)
if os.path.isdir(dest_info.fspath):
assert filecmp.cmp(
src_info.fspath,
os.path.join(dest_info.fspath, os.path.basename(src_info.fspath)),
shallow=False,
)
else:
assert filecmp.cmp(src_info.fspath, dest_info.fspath, shallow=False)
def test_tmp_fname():
file_path = os.path.join("path", "to", "file")
file_path_info = PathInfo(file_path)