Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remote: verify repository exists when level requires it #3194

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions dvc/command/remote.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import logging

from dvc.repo import Repo
from dvc.command.base import append_doc_link
from dvc.command.base import fix_subparsers
from dvc.command.config import CmdConfig
Expand All @@ -14,6 +15,12 @@ def __init__(self, args):
super().__init__(args)
self.remote_config = RemoteConfig(self.config)

# Verify repository existance when level requires to modify its config
repository_levels = [self.config.LEVEL_REPO, self.config.LEVEL_LOCAL]
efiop marked this conversation as resolved.
Show resolved Hide resolved

if self.args.level in repository_levels:
Repo.find_dvc_dir()


class CmdRemoteAdd(CmdRemoteConfig):
def run(self):
Expand Down
19 changes: 19 additions & 0 deletions tests/func/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,22 @@ def test_modify_missing_remote(dvc):

with pytest.raises(ConfigError, match=r"unable to find remote section"):
remote_config.modify("myremote", "gdrive_client_id", "xxx")


@pytest.mark.parametrize(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solution is for config in general, but tests are for remote specifically, not nice 🙂Also not clear why are you testing CLI again and not API?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, that's a left over. Those tests are not relevant since they were replaced for the ones in test_config.py

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer testing the CLI in this case, it is more complete, but if you want, I use the API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MrOutis CLI is a dumb wrapper for API. We always test API, so let's do the same here. If you want to check that CLI returns proper codes on corresponding exceptions, just add a unit test to tests/unit/command/.

"cmd",
[
["remote", "add", "example", "https://example.com"],
["remote", "add", "--local", "example", "https://example.com"],
["remote", "modify", "example", "random", "value"],
["remote", "modify", "--local", "example", "random", "value"],
["remote", "remove", "example"],
["remote", "remove", "--local", "example"],
["remote", "list"],
["remote", "list", "--local"],
["remote", "default", "example"],
["remote", "default", "--local", "example"],
],
)
def test_commands_outside_dvc_repository(tmp_dir, cmd):
assert 253 == main(cmd)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

253 is returned when NotDvcRepoError is raised.