def get_fs_type(path): partition = { pathlib.Path(part.mountpoint): (part.fstype, part.device) for part in psutil.disk_partitions() } for parent in pathlib.Path(path).parents: if parent in partition: return partition[parent] return ("unkown", "none")
def get_fs_type(path): partition = { pathlib.Path(part.mountpoint): (part.fstype, part.device) for part in psutil.disk_partitions(all=True) } path = pathlib.Path(path) for parent in itertools.chain([path], path.parents): if parent in partition: return partition[parent] return ("unkown", "none")
def test_all_commits(git, dvc_repo): def add_and_commit(): stages = dvc_repo.add(str(testfile)) dvc_repo.scm.add([s.relpath for s in stages]) dvc_repo.scm.commit("message") cache_dir = os.path.join(dvc_repo.root_dir, ".dvc", "cache") testfile = pathlib.Path("testfile") testfile.write_text("uncommited") dvc_repo.add(str(testfile)) testfile.write_text("commited") add_and_commit() testfile.write_text("modified") add_and_commit() testfile.write_text("workspace") dvc_repo.add(str(testfile)) N = _count_files(cache_dir) dvc_repo.gc(all_commits=True) # Only one uncommited file should go away assert _count_files(cache_dir) == N - 1
def test_dvc_formatting_retained(dvc_repo, foo_copy): root = pathlib.Path(dvc_repo.root_dir) stage_file = root / foo_copy["stage_fname"] # Add comments and custom formatting to DVC-file lines = list(map(_format_dvc_line, stage_file.read_text().splitlines())) lines.insert(0, "# Starting comment") stage_text = "".join(l + "\n" for l in lines) stage_file.write_text(stage_text) # Rewrite data source and repro (root / "foo").write_text("new_foo") dvc_repo.reproduce(foo_copy["stage_fname"]) # All differences should be only about md5 assert _hide_md5(stage_text) == _hide_md5(stage_file.read_text())
import pytest import copy from dvc.utils.compat import pathlib from dvc.path_info import PathInfo, URLInfo, CloudURLInfo TEST_DEPTH = len(pathlib.Path(__file__).parents) + 1 @pytest.mark.parametrize("cls", [URLInfo, CloudURLInfo]) def test_url_info_str(cls): u = cls("ssh://[email protected]:/test1/") assert u.url == "ssh://[email protected]/test1/" assert str(u) == u.url @pytest.mark.parametrize("cls", [URLInfo, CloudURLInfo]) def test_url_info_eq(cls): u1 = cls("ssh://[email protected]:/test1/") u2 = cls("ssh://[email protected]/test1") assert u1 == u2 @pytest.mark.parametrize("cls", [URLInfo, CloudURLInfo]) def test_url_info_parent(cls): u1 = cls("ssh://[email protected]:/test1/test2") p = u1.parent u3 = cls("ssh://[email protected]/test1") assert u3 == p assert str(p) == "ssh://[email protected]/test1"