Skip to content

Commit

Permalink
Write test for tmp_fname to check if it accepts Path-like and str o…
Browse files Browse the repository at this point in the history
…bjects
  • Loading branch information
algomaster99 committed Nov 18, 2019
1 parent 38c2100 commit 3edad21
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/unit/utils/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import filecmp
import re
import os

import pytest
Expand All @@ -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


Expand Down Expand Up @@ -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,
)

0 comments on commit 3edad21

Please sign in to comment.