diff --git a/dvc/command/version.py b/dvc/command/version.py index d964eaa8b..770d9ad3c 100644 --- a/dvc/command/version.py +++ b/dvc/command/version.py @@ -42,22 +42,22 @@ class CmdVersion(CmdBaseNoRepo): binary=binary, ) - if psutil: - try: - repo = Repo() - root_directory = repo.root_dir + try: + repo = Repo() + root_directory = repo.root_dir + info += "Cache: {cache}\n".format( + cache=self.get_linktype_support_info(repo) + ) + + if psutil: info += ( - "Cache: {cache}\n" "Filesystem type (cache directory): {fs_cache}\n" - ).format( - cache=self.get_linktype_support_info(repo), - fs_cache=self.get_fs_type(repo.cache.local.cache_dir), - ) - - except NotDvcRepoError: - root_directory = os.getcwd() + ).format(fs_cache=self.get_fs_type(repo.cache.local.cache_dir)) + except NotDvcRepoError: + root_directory = os.getcwd() + if psutil: info += ("Filesystem type (workspace): {fs_root}").format( fs_root=self.get_fs_type(os.path.abspath(root_directory)) ) diff --git a/tests/func/test_version.py b/tests/func/test_version.py index a040c1e14..d0fe6f2eb 100644 --- a/tests/func/test_version.py +++ b/tests/func/test_version.py @@ -1,6 +1,8 @@ import re +import pytest from dvc.main import main +from dvc.command.version import psutil def test_info_in_repo(dvc_repo, caplog): @@ -10,15 +12,21 @@ def test_info_in_repo(dvc_repo, caplog): assert re.search(re.compile(r"Python version: \d\.\d\.\d"), caplog.text) assert re.search(re.compile(r"Platform: .*"), caplog.text) assert re.search(re.compile(r"Binary: (True|False)"), caplog.text) + assert re.search( + re.compile(r"(Cache: (.*link - (True|False)(,\s)?){3})"), caplog.text + ) + + +@pytest.mark.skipif(psutil is None, reason="No psutil.") +def test_fs_info_in_repo(dvc_repo, caplog): + assert main(["version"]) == 0 + assert re.search( re.compile(r"Filesystem type \(cache directory\): .*"), caplog.text ) assert re.search( re.compile(r"Filesystem type \(workspace\): .*"), caplog.text ) - assert re.search( - re.compile(r"(Cache: (.*link - (True|False)(,\s)?){3})"), caplog.text - ) def test_info_outside_of_repo(repo_dir, caplog): @@ -28,12 +36,18 @@ def test_info_outside_of_repo(repo_dir, caplog): assert re.search(re.compile(r"Python version: \d\.\d\.\d"), caplog.text) assert re.search(re.compile(r"Platform: .*"), caplog.text) assert re.search(re.compile(r"Binary: (True|False)"), caplog.text) + assert not re.search( + re.compile(r"(Cache: (.*link - (True|False)(,\s)?){3})"), caplog.text + ) + + +@pytest.mark.skipif(psutil is None, reason="No psutil.") +def test_fs_info_outside_of_repo(repo_dir, caplog): + assert main(["version"]) == 0 + assert re.search( re.compile(r"Filesystem type \(workspace\): .*"), caplog.text ) assert not re.search( re.compile(r"Filesystem type \(cache directory\): .*"), caplog.text ) - assert not re.search( - re.compile(r"(Cache: (.*link - (True|False)(,\s)?){3})"), caplog.text - )