Write test for tmp_fname to check if it accepts Path-like and str objects

This commit is contained in:
Aman Sharma
2019-11-18 11:49:40 +05:30
parent 38c210068b
commit 3edad21b41
+17
View File
@@ -1,4 +1,5 @@
import filecmp
import re
import os
import pytest
@@ -9,6 +10,7 @@ from dvc.utils import file_md5
from dvc.utils import fix_env
from dvc.utils import makedirs
from dvc.utils import to_chunks
from dvc.utils import tmp_fname
from tests.basic_env import TestDir
@@ -122,3 +124,18 @@ def test_makedirs(repo_dir):
makedirs(path_info)
assert os.path.isdir(path_info.fspath)
def test_tmp_fname():
file_path = os.path.join("path", "to", "file")
file_path_info = PathInfo(file_path)
def pattern(path):
return r"^" + re.escape(path) + r"\.[a-z0-9]{22}\.tmp$"
assert re.search(pattern(file_path), tmp_fname(file_path), re.IGNORECASE)
assert re.search(
pattern(file_path_info.fspath),
tmp_fname(file_path_info),
re.IGNORECASE,
)