Files
dvc/tests/unit/remote/test_slow_link_detection.py
T
Alexander Schepanovski 6ccae711fe dvc: refactor config (#3298)
* dvc: refactor config

Advantages:
- read like a dict
- modify as a dict for testing or manipulation purposes
- wrap modifications into context manager to save them:

    with config.edit("local") as conf:
        conf["core"]["remote"] = "new-default"

Design decisions:
- dropped string constants
- remote sections are parsed into a simple subdict upon load
- remote config schema is now defined by url scheme
- relative paths are handled transparently upon load/save
- user config and remote manipulations are moved to commands
- same dev manipulations are done by simply modifying a config dict

* test: do not set cache.type for remotes that doesn't support it

* dvc: fix windows absolute paths validation in config

* test: fix windows separate drive test

* dvc: stylistic fixes in config
2020-02-13 19:35:37 +02:00

46 lines
1.2 KiB
Python

import mock
import pytest
import dvc.remote.slow_link_detection
from dvc.remote.slow_link_detection import slow_link_guard
@pytest.fixture(autouse=True)
def timeout_immediately(monkeypatch):
monkeypatch.setattr(dvc.remote.slow_link_detection, "timeout_seconds", 0.0)
@pytest.fixture
def make_remote():
def _make_remote(cache_type=None, should_warn=True):
remote = mock.Mock()
remote.repo.config = {
"cache": {"type": cache_type, "slow_link_warning": should_warn}
}
return remote
return _make_remote
def test_show_warning_once(caplog, make_remote):
remote = make_remote()
slow_link_guard(lambda x: None)(remote)
slow_link_guard(lambda x: None)(remote)
assert len(caplog.records) == 1
assert caplog.records[0].message == dvc.remote.slow_link_detection.message
def test_dont_warn_when_cache_type_is_set(caplog, make_remote):
remote = make_remote(cache_type="copy")
slow_link_guard(lambda x: None)(remote)
assert len(caplog.records) == 0
def test_dont_warn_when_warning_is_disabled(caplog, make_remote):
remote = make_remote(should_warn=False)
slow_link_guard(lambda x: None)(remote)
assert len(caplog.records) == 0