Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
1. add two tests
2. add one validation
3. modified remote remove to satithe validation change
  • Loading branch information
karajan1001 committed May 1, 2020
1 parent 55e1201 commit 194ed2d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 13 deletions.
4 changes: 2 additions & 2 deletions dvc/command/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def run(self):

class CmdRemoteRemove(CmdRemote):
def run(self):
with self.config.edit(self.args.level) as conf:
self._check_exists(conf)
conf = self.config.load_one(self.args.level)
self._check_exists(conf)

# Remove core.remote refs to this remote in any shadowing configs
for level in reversed(self.config.LEVELS):
Expand Down
5 changes: 1 addition & 4 deletions dvc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,7 @@ def validate(data):
"remote" in data["core"]
and data["core"]["remote"] not in data["remote"]
):
print(data)
print(data["core"]["remote"])
print(data["remote"])
raise ConfigError("")
raise ConfigError("Default remote not in the remote list.")
return COMPILED_SCHEMA(data)
except Invalid as exc:
raise ConfigError(str(exc)) from None
Expand Down
32 changes: 31 additions & 1 deletion tests/func/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_non_existing(self):
self.assertEqual(ret, 251)

ret = main(["config", "core.remote", "myremote"])
self.assertEqual(ret, 0)
self.assertEqual(ret, 251)

ret = main(["config", "core.non_existing_field", "-u"])
self.assertEqual(ret, 251)
Expand Down Expand Up @@ -109,6 +109,36 @@ def test_merging_two_levels(dvc):
}


def test_remote_default_set(dvc):
local_level = "local_remote"
repo_level = "repo_remote"
with dvc.config.edit() as conf:
conf["remote"][repo_level] = {"url": "ssh://example.com"}
with dvc.config.edit() as conf:
conf["remote"][local_level] = {"url": "ssh://example.com"}

# repo-level remote repo cannot set default in global level
with pytest.raises(ConfigError):
with dvc.config.edit("global") as conf:
conf["core"]["remote"] = repo_level
assert "remote" not in dvc.config["core"]

# remote default must in remote list
with pytest.raises(ConfigError):
with dvc.config.edit("local") as conf:
conf["core"]["remote"] = "not_in_list"
assert "remote" not in dvc.config["core"]

with dvc.config.edit() as conf:
conf["core"]["remote"] = repo_level
assert dvc.config["core"]["remote"] == repo_level

# repo-level remote repo can set default in local level
with dvc.config.edit("local") as conf:
conf["core"]["remote"] = local_level
assert dvc.config["core"]["remote"] == local_level


def test_config_loads_without_error_for_non_dvc_repo(tmp_dir):
# regression testing for https://github.com/iterative/dvc/issues/3328
Config(validate=True)
21 changes: 15 additions & 6 deletions tests/func/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,19 @@ def test_remote_modify_validation(dvc):
assert unsupported_config not in config['remote "{}"'.format(remote_name)]


def test_remote_default_modify(dvc):
remote_name = "my_remote"
wrong_remote_name = "anything"
assert main(["remote", "add", remote_name, "s3://bucket/name"]) == 0
def test_remote_modify_default(dvc):
remote_repo = "repo_level"
remote_local = "local_level"
wrong_name = "anything"
assert main(["remote", "add", remote_repo, "s3://bucket/repo"]) == 0
assert main(["remote", "add", remote_local, "s3://bucket/local"]) == 0

assert main(["remote", "default", wrong_name]) == 251
assert main(["remote", "default", remote_repo]) == 0
assert main(["remote", "default", "--local", remote_local]) == 0

repo_config = configobj.ConfigObj(dvc.config.files["repo"])
local_config = configobj.ConfigObj(dvc.config.files["local"])

assert main(["remote", "default", remote_name]) == 0
assert main(["remote", "default", wrong_remote_name]) == 251
assert repo_config["core"]["remote"] == remote_repo
assert local_config["core"]["remote"] == remote_local

0 comments on commit 194ed2d

Please sign in to comment.