From 3edad21b41c267700a64bbf3485f96958ade01e7 Mon Sep 17 00:00:00 2001 From: Aman Sharma Date: Mon, 18 Nov 2019 01:44:54 +0530 Subject: [PATCH] Write test for `tmp_fname` to check if it accepts Path-like and str objects --- tests/unit/utils/test_utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/unit/utils/test_utils.py b/tests/unit/utils/test_utils.py index 6d4aba0bc0..6b4f75a53d 100644 --- a/tests/unit/utils/test_utils.py +++ b/tests/unit/utils/test_utils.py @@ -1,4 +1,5 @@ import filecmp +import re import os import pytest @@ -9,6 +10,7 @@ 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, + )