mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
Currently if dvc_dir doesn't exists (e.g. we are creating an uninitialized repo), config will try looking for `.dvc` dir in the current directory, which might be inside of another dvc repository resulting in mixed configs. Use explicit `from_cwd` method to make `Config` try to find repo configs if available to avoid the usage mixup.
117 lines
3.0 KiB
Python
117 lines
3.0 KiB
Python
import logging
|
|
import os
|
|
import textwrap
|
|
|
|
import pytest
|
|
|
|
from dvc.config import Config, ConfigError
|
|
from dvc.fs import LocalFileSystem
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"path, expected",
|
|
[
|
|
("cache", "../cache"),
|
|
(os.path.join("..", "cache"), "../../cache"),
|
|
(os.getcwd(), os.getcwd()),
|
|
("ssh://some/path", "ssh://some/path"),
|
|
],
|
|
)
|
|
def test_to_relpath(path, expected):
|
|
assert Config._to_relpath(os.path.join(".", "config"), path) == expected
|
|
|
|
|
|
def test_get_fs(tmp_dir, scm):
|
|
tmp_dir.scm_gen("foo", "foo", commit="add foo")
|
|
|
|
fs = scm.get_fs("master")
|
|
config = Config.from_cwd(fs=fs)
|
|
|
|
assert config.fs == fs
|
|
assert config.wfs != fs
|
|
assert isinstance(config.wfs, LocalFileSystem)
|
|
|
|
assert config._get_fs("repo") == fs
|
|
assert config._get_fs("local") == config.wfs
|
|
assert config._get_fs("global") == config.wfs
|
|
assert config._get_fs("system") == config.wfs
|
|
|
|
|
|
def test_s3_ssl_verify(tmp_dir, dvc):
|
|
config = Config.from_cwd(validate=False)
|
|
with config.edit() as conf:
|
|
conf["remote"]["remote-name"] = {"url": "s3://bucket/dvc"}
|
|
|
|
assert "ssl_verify" not in config["remote"]["remote-name"]
|
|
|
|
with config.edit() as conf:
|
|
section = conf["remote"]["remote-name"]
|
|
section["ssl_verify"] = False
|
|
|
|
assert (tmp_dir / ".dvc" / "config").read_text() == textwrap.dedent(
|
|
"""\
|
|
[core]
|
|
no_scm = True
|
|
['remote "remote-name"']
|
|
url = s3://bucket/dvc
|
|
ssl_verify = False
|
|
"""
|
|
)
|
|
|
|
with config.edit() as conf:
|
|
section = conf["remote"]["remote-name"]
|
|
section["ssl_verify"] = "/path/to/custom/cabundle.pem"
|
|
|
|
assert (tmp_dir / ".dvc" / "config").read_text() == textwrap.dedent(
|
|
"""\
|
|
[core]
|
|
no_scm = True
|
|
['remote "remote-name"']
|
|
url = s3://bucket/dvc
|
|
ssl_verify = /path/to/custom/cabundle.pem
|
|
"""
|
|
)
|
|
|
|
|
|
def test_load_unicode_error(tmp_dir, dvc, mocker):
|
|
config = Config.from_cwd(validate=False)
|
|
mocker.patch(
|
|
"configobj.ConfigObj",
|
|
side_effect=UnicodeDecodeError("", b"", 0, 0, ""),
|
|
)
|
|
with pytest.raises(ConfigError):
|
|
with config.edit():
|
|
pass
|
|
|
|
|
|
def test_load_configob_error(tmp_dir, dvc, mocker):
|
|
from configobj import ConfigObjError
|
|
|
|
config = Config.from_cwd(validate=False)
|
|
mocker.patch(
|
|
"configobj.ConfigObj",
|
|
side_effect=ConfigObjError(),
|
|
)
|
|
with pytest.raises(ConfigError):
|
|
with config.edit():
|
|
pass
|
|
|
|
|
|
def test_feature_section_supports_arbitrary_values(caplog):
|
|
with caplog.at_level(logging.WARNING, logger="dvc.config_schema"):
|
|
data = Config.validate(
|
|
{
|
|
"feature": {
|
|
"random_key_1": "random_value_1",
|
|
"random_key_2": 42,
|
|
}
|
|
}
|
|
)
|
|
|
|
assert "random_key_1" not in data
|
|
assert "random_key_2" not in data
|
|
assert (
|
|
"'feature.random_key_1', 'feature.random_key_2' "
|
|
"config options are unsupported"
|
|
) in caplog.text
|