mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-04 15:28:27 +01:00
Currently we don't handle bad name well: ``` (dvc-3.8.3) ➜ dvc git:(config-bug) ✗ dvc config section ERROR: unexpected error - not enough values to unpack (expected 2, got 1) ``` With this PR, we check name to conform to either `remote.name.option` or `section.option`, so we'll give a more friendly: ``` (dvc-3.8.3) ➜ dvc git:(config-bug) ✗ dvc config section ERROR: argument name: name argument should look like remote.name.option or section.option usage: dvc config [-h] [--global | --system | --local] [-q | -v] [-u] [-l] [name] [value] Get or set config options. Documentation: <https://man.dvc.org/config> positional arguments: name Option name (remote.name.option or section.option). value Option value. optional arguments: -h, --help show this help message and exit --global Use global config. --system Use system config. --local Use local config. -q, --quiet Be quiet. -v, --verbose Be verbose. -u, --unset Unset option. -l, --list List all defined config values. ```
32 lines
889 B
Python
32 lines
889 B
Python
import pytest
|
|
|
|
from dvc.cli import DvcParserError, parse_args
|
|
from dvc.command.config import CmdConfig
|
|
|
|
|
|
def test_config_formatter():
|
|
example_config = {
|
|
"section_foo": {"option_bar": True, "option_baz": False},
|
|
"section_foo2": {
|
|
"option_bar2": {"option_baz2": True},
|
|
"option_baz3": {"option_baz4": False},
|
|
},
|
|
"section_foo3": {},
|
|
}
|
|
|
|
config_lines = tuple(CmdConfig._format_config(example_config))
|
|
assert config_lines == (
|
|
"section_foo.option_bar=True",
|
|
"section_foo.option_baz=False",
|
|
"section_foo2.option_bar2.option_baz2=True",
|
|
"section_foo2.option_baz3.option_baz4=False",
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"name", ["way.too.long", "no_option", "remote.way.too.long"],
|
|
)
|
|
def test_config_bad_name(name):
|
|
with pytest.raises(DvcParserError):
|
|
parse_args(["config", name])
|