api: params_show: Raise exception if no params found.

Fixes #7926
This commit is contained in:
David de la Iglesia Castro
2022-07-05 09:18:22 +02:00
parent 909941308b
commit 954de0cae4
2 changed files with 24 additions and 0 deletions
+7
View File
@@ -3,6 +3,7 @@ from typing import Dict, Iterable, Optional, Union
from funcy import first
from dvc.exceptions import DvcException
from dvc.repo import Repo
@@ -50,6 +51,9 @@ def params_show(
Returns:
Dict: See Examples below.
Raises:
DvcException: If no params are found in `repo`.
Examples:
- No arguments.
@@ -253,6 +257,9 @@ def params_show(
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:
+17
View File
@@ -3,6 +3,7 @@ from textwrap import dedent
import pytest
from dvc import api
from dvc.exceptions import DvcException
@pytest.fixture
@@ -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()