From 144f10d8cb19daf68b67a15259fc8388d61aaf3b Mon Sep 17 00:00:00 2001 From: pawel Date: Tue, 14 Jan 2020 15:25:55 +0100 Subject: [PATCH] fs: tests: remove repo_dir --- tests/unit/utils/test_fs.py | 67 +++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/tests/unit/utils/test_fs.py b/tests/unit/utils/test_fs.py index fbde5fcdf..0c0e19a0b 100644 --- a/tests/unit/utils/test_fs.py +++ b/tests/unit/utils/test_fs.py @@ -6,6 +6,7 @@ import pytest from mock import patch import dvc +from dvc.compat import fspath from dvc.ignore import CleanTree from dvc.path_info import PathInfo from dvc.scm.tree import WorkingTree @@ -120,26 +121,33 @@ def test_relpath_windows_different_drives(): assert rel_info == path1 -def test_get_inode(repo_dir): - path = repo_dir.FOO - path_info = PathInfo(path) - assert get_inode(path) == get_inode(path_info) +def test_get_inode(tmp_dir): + tmp_dir.gen("foo", "foo content") + + assert get_inode("foo") == get_inode(PathInfo("foo")) -@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 -): - tree = CleanTree(WorkingTree(repo_dir.root_dir)) - time, size = get_mtime_and_size(path, tree) - object_time, object_size = get_mtime_and_size(PathInfo(path), tree) +def test_path_object_and_str_are_valid_types_get_mtime_and_size(tmp_dir): + tmp_dir.gen( + {"dir": {"dir_file": "dir file content"}, "file": "file_content"} + ) + tree = CleanTree(WorkingTree(tmp_dir)) + + time, size = get_mtime_and_size("dir", tree) + object_time, object_size = get_mtime_and_size(PathInfo("dir"), tree) + assert time == object_time + assert size == object_size + + time, size = get_mtime_and_size("file", tree) + object_time, object_size = get_mtime_and_size(PathInfo("file"), tree) assert time == object_time assert size == object_size -def test_move(repo_dir): - src = repo_dir.FOO - src_info = PathInfo(repo_dir.BAR) +def test_move(tmp_dir): + tmp_dir.gen({"foo": "foo content", "bar": "bar content"}) + src = "foo" + src_info = PathInfo("bar") dest = os.path.join("some", "directory") dest_info = PathInfo(os.path.join("some", "path-like", "directory")) @@ -156,9 +164,10 @@ def test_move(repo_dir): assert len(os.listdir(dest_info.fspath)) == 1 -def test_remove(repo_dir): - path = repo_dir.FOO - path_info = PathInfo(repo_dir.BAR) +def test_remove(tmp_dir): + tmp_dir.gen({"foo": "foo content", "bar": "bar content"}) + path = "foo" + path_info = PathInfo("bar") remove(path) assert not os.path.isfile(path) @@ -208,11 +217,9 @@ def test_path_isin_with_absolute_path(): assert path_isin(child, parent) -def test_makedirs(repo_dir): - path = os.path.join(repo_dir.root_dir, "directory") - path_info = PathInfo( - os.path.join(repo_dir.root_dir, "another", "directory") - ) +def test_makedirs(tmp_dir): + path = os.path.join(fspath(tmp_dir), "directory") + path_info = PathInfo(os.path.join(fspath(tmp_dir), "another", "directory")) makedirs(path) assert os.path.isdir(path) @@ -221,11 +228,19 @@ def test_makedirs(repo_dir): 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 +@pytest.mark.parametrize("path", ["file", "dir"]) +def test_copyfile(path, tmp_dir): + tmp_dir.gen( + { + "foo": "foo content", + "bar": "bar content", + "file": "file content", + "dir": {}, + } + ) + src = "foo" dest = path - src_info = PathInfo(repo_dir.BAR) + src_info = PathInfo("bar") dest_info = PathInfo(path) copyfile(src, dest)