Files
dvc/tests/func/test_version.py
T
Ruslan Kuprieiev 803ffaec57 remote: local: don't auto-create directory in __init__
Imagine the scenario of shared cache. To set it up, user would do:

```
dvc config cache.dir /path
dvc config cache.shared group
```

Now, when he runs any dvc operation that involves the Repo instance,
RemoteLOCAL will also be initialized and it will currently auto-create
the directory with a regular `os.mkdir`, which is not using group
permissions. To solve that, we can't simply use `self.makdirs` instead,
as it will cause same issues if you run any dvc command before
`dvc config cache.shared group`. So what we should do is create
directories on demand, instead of creating it in advance, same as we do
in other remotes.

The change itself is pretty trivial and involved removing that `mkdir`
line, adjusting tests to not rely on cache dir existence and also
adjusting `dvc version` to not rely on cache directory existance.

Fixes #2563
2019-10-14 15:50:49 +03:00

58 lines
1.9 KiB
Python

import re
import pytest
from dvc.main import main
from dvc.command.version import psutil
def test_info_in_repo(repo_dir, dvc_repo, caplog):
# adding a file so that dvc creates `.dvc/cache`, that is needed for proper
# supported link types check.
assert main(["add", repo_dir.FOO]) == 0
assert main(["version"]) == 0
assert re.search(re.compile(r"DVC version: \d+\.\d+\.\d+"), caplog.text)
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
)
def test_info_outside_of_repo(repo_dir, caplog):
assert main(["version"]) == 0
assert re.search(re.compile(r"DVC version: \d+\.\d+\.\d+"), caplog.text)
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
)