mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
Merge pull request #2698 from algomaster99/test-argument-types-get_mtime_and_size
Verify if `get_mtime_and_size` can take both Path objects and strings
This commit is contained in:
@@ -4,6 +4,7 @@ neatlynx/__pycache__
|
||||
cache
|
||||
*.pyc
|
||||
.env/
|
||||
.env2.7/
|
||||
|
||||
cache
|
||||
.dvc.conf.lock
|
||||
|
||||
+3
-5
@@ -369,14 +369,12 @@ class State(object): # pylint: disable=too-many-instance-attributes
|
||||
"""
|
||||
assert path_info.scheme == "local"
|
||||
assert checksum is not None
|
||||
|
||||
path = fspath_py35(path_info)
|
||||
assert os.path.exists(path)
|
||||
assert os.path.exists(fspath_py35(path_info))
|
||||
|
||||
actual_mtime, actual_size = get_mtime_and_size(
|
||||
path, self.repo.dvcignore
|
||||
path_info, self.repo.dvcignore
|
||||
)
|
||||
actual_inode = get_inode(path)
|
||||
actual_inode = get_inode(path_info)
|
||||
|
||||
existing_record = self.get_state_record_for_inode(actual_inode)
|
||||
if not existing_record:
|
||||
|
||||
+3
-3
@@ -7,7 +7,7 @@ import logging
|
||||
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.system import System
|
||||
from dvc.utils import dict_md5, walk_files
|
||||
from dvc.utils import dict_md5, walk_files, fspath_py35
|
||||
from dvc.utils.compat import str
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ def get_inode(path):
|
||||
|
||||
|
||||
def get_mtime_and_size(path, dvcignore):
|
||||
if os.path.isdir(path):
|
||||
if os.path.isdir(fspath_py35(path)):
|
||||
size = 0
|
||||
files_mtimes = {}
|
||||
for file_path in walk_files(path, dvcignore):
|
||||
@@ -39,7 +39,7 @@ def get_mtime_and_size(path, dvcignore):
|
||||
# max(mtime(f) for f in non_ignored_files)
|
||||
mtime = dict_md5(files_mtimes)
|
||||
else:
|
||||
base_stat = os.stat(path)
|
||||
base_stat = os.stat(fspath_py35(path))
|
||||
size = base_stat.st_size
|
||||
mtime = base_stat.st_mtime
|
||||
mtime = int(nanotime.timestamp(mtime))
|
||||
|
||||
@@ -156,3 +156,14 @@ def test_get_inode(repo_dir):
|
||||
path = repo_dir.FOO
|
||||
path_info = PathInfo(path)
|
||||
assert get_inode(path) == get_inode(path_info)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("path", [TestDir.DATA, TestDir.DATA_DIR])
|
||||
def test_path_object_and_str_are_valid_types_get_mtime_and_size(
|
||||
path, repo_dir
|
||||
):
|
||||
dvcignore = DvcIgnoreFilter(repo_dir.root_dir)
|
||||
time, size = get_mtime_and_size(path, dvcignore)
|
||||
object_time, object_size = get_mtime_and_size(PathInfo(path), dvcignore)
|
||||
assert time == object_time
|
||||
assert size == object_size
|
||||
|
||||
Reference in New Issue
Block a user