Skip to content

Commit

Permalink
api: params_show: Raise exception if no params found.
Browse files Browse the repository at this point in the history
Fixes #7926
  • Loading branch information
daavoo committed Jul 5, 2022
1 parent 9099413 commit 954de0c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dvc/api/params.py
Expand Up @@ -3,6 +3,7 @@

from funcy import first

from dvc.exceptions import DvcException
from dvc.repo import Repo


Expand Down Expand Up @@ -50,6 +51,9 @@ def params_show(
Returns:
Dict: See Examples below.
Raises:
DvcException: If no params are found in `repo`.
Examples:
- No arguments.
Expand Down Expand Up @@ -253,6 +257,9 @@ def _postprocess(params):
if "workspace" in processed:
del processed["workspace"]

if not processed:
raise DvcException("No params found")

return processed[first(processed)]

with Repo.open(repo) as _repo:
Expand Down
17 changes: 17 additions & 0 deletions tests/func/api/test_params.py
Expand Up @@ -3,6 +3,7 @@
import pytest

from dvc import api
from dvc.exceptions import DvcException


@pytest.fixture
Expand Down Expand Up @@ -128,3 +129,19 @@ def test_params_show_repo(tmp_dir, erepo_dir):
params=["foo"],
)
assert api.params_show(repo=erepo_dir) == {"foo": 1}


def test_params_show_no_params_found(tmp_dir, dvc):
# Empty repo
with pytest.raises(DvcException, match="No params found"):
api.params_show()

# params.yaml but no dvc.yaml
(tmp_dir / "params.yaml").dump({"foo": 1})
assert api.params_show() == {"foo": 1}

# dvc.yaml but no params.yaml
(tmp_dir / "params.yaml").unlink()
dvc.stage.add(name="echo", cmd="echo foo")
with pytest.raises(DvcException, match="No params found"):
api.params_show()

0 comments on commit 954de0c

Please sign in to comment.