Skip to content

Commit 4b800c9

Browse files
committed
Add tests for YamlParamType
1 parent bea3558 commit 4b800c9

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

sqlmesh_dbt/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def run(ctx: click.Context, vars: t.Optional[t.Dict[str, t.Any]], **kwargs: t.An
9191
@dbt.command(name="list")
9292
@select_option
9393
@exclude_option
94+
@vars_option
9495
@click.pass_context
9596
def list_(ctx: click.Context, vars: t.Optional[t.Dict[str, t.Any]], **kwargs: t.Any) -> None:
9697
"""List the resources in your project"""

tests/dbt/cli/test_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ def test_list_with_vars(jaffle_shop_duckdb: Path, invoke_cli: t.Callable[..., Re
5959
assert result.exit_code == 0
6060
assert not result.exception
6161

62-
assert "model_bar" in result.output
62+
assert "model_bar" in result.output

tests/dbt/cli/test_options.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import typing as t
2+
import pytest
3+
from sqlmesh_dbt.options import YamlParamType
4+
from click.exceptions import BadParameter
5+
6+
7+
@pytest.mark.parametrize(
8+
"input,expected",
9+
[
10+
(1, BadParameter("Input value '1' should be a string")),
11+
("", BadParameter("String '' is not valid YAML")),
12+
("['a', 'b']", BadParameter("String.*did not evaluate to a dict, got.*")),
13+
("foo: bar", {"foo": "bar"}),
14+
('{"key": "value", "date": 20180101}', {"key": "value", "date": 20180101}),
15+
("{key: value, date: 20180101}", {"key": "value", "date": 20180101}),
16+
],
17+
)
18+
def test_yaml_param_type(input: str, expected: t.Union[BadParameter, t.Dict[str, t.Any]]):
19+
if isinstance(expected, BadParameter):
20+
with pytest.raises(BadParameter, match=expected.message):
21+
YamlParamType().convert(input, None, None)
22+
else:
23+
assert YamlParamType().convert(input, None, None) == expected

0 commit comments

Comments
 (0)