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

Support quoted parameter list for MultiOption cli options #8665

Merged
merged 16 commits into from
Sep 22, 2023
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20230918-150855.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Support quoted parameter list for MultiOption CLI options..
emmyoop marked this conversation as resolved.
Show resolved Hide resolved
time: 2023-09-18T15:08:55.625412-05:00
custom:
Author: emmyoop
Issue: "8598"
2 changes: 1 addition & 1 deletion core/dbt/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def add_to_parser(self, parser, ctx):
def parser_process(value, state):
emmyoop marked this conversation as resolved.
Show resolved Hide resolved
# method to hook to the parser.process
done = False
value = [value]
value = str.split(value, " ")
if self.save_other_options:
# grab everything up to the next option
while state.rargs and not done:
Expand Down
105 changes: 105 additions & 0 deletions tests/functional/cli/test_multioption.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import pytest
from dbt.tests.util import run_dbt


model_one_sql = """
select 1 as fun
"""

source_sql = """
sources:
- name: my_source
description: "My source"
schema: test_schema
tables:
- name: my_table
"""


class TestResourceType:
@pytest.fixture(scope="class")
def models(self):
return {"schema.yml": source_sql, "model_one.sql": model_one_sql}

def test_resource_type_single(self, project):
result = run_dbt(["-q", "ls", "--resource-types", "model"])
assert len(result) == 1
assert result == ["test.model_one"]

def test_resource_type_quoted(self, project):
result = run_dbt(["-q", "ls", "--resource-types", "model source"])
assert len(result) == 2
assert result == ["test.model_one", "source:test.my_source.my_table"]
emmyoop marked this conversation as resolved.
Show resolved Hide resolved

def test_resource_type_args(self, project):
result = run_dbt(["-q", "ls", "--resource-type", "model", "--resource-type", "source"])
assert len(result) == 2
assert result == ["test.model_one", "source:test.my_source.my_table"]


class TestOutputKeys:
@pytest.fixture(scope="class")
def models(self):
return {"model_one.sql": model_one_sql}

def test_output_key_single(self, project):
result = run_dbt(["-q", "ls", "--output", "json", "--output-keys", "name"])
assert len(result) == 1
assert result == ['{"name": "model_one"}']

def test_output_key_quoted(self, project):
result = run_dbt(["-q", "ls", "--output", "json", "--output-keys", "name resource_type"])

assert len(result) == 1
assert result == ['{"name": "model_one", "resource_type": "model"}']

def test_output_key_args(self, project):
result = run_dbt(
[
"-q",
"ls",
"--output",
"json",
"--output-keys",
"name",
"--output-keys",
"resource_type",
]
)

assert len(result) == 1
assert result == ['{"name": "model_one", "resource_type": "model"}']


class TestSelectExclude:
@pytest.fixture(scope="class")
def models(self):
return {
"model_one.sql": model_one_sql,
"model_two.sql": model_one_sql,
"model_three.sql": model_one_sql,
}

def test_select_exclude_single(self, project):
result = run_dbt(["-q", "ls", "--select", "model_one"])
assert len(result) == 1
assert result == ["test.model_one"]
result = run_dbt(["-q", "ls", "--exclude", "model_one"])
assert len(result) == 2
assert "test.model_one" not in result

def test_select_exclude_quoted(self, project):
result = run_dbt(["-q", "ls", "--select", "model_one model_two"])
assert len(result) == 2
assert "test.model_three" not in result
result = run_dbt(["-q", "ls", "--exclude", "model_one model_two"])
assert len(result) == 1
assert result == ["test.model_three"]

def test_select_exclude_args(self, project):
result = run_dbt(["-q", "ls", "--select", "model_one", "--select", "model_two"])
assert len(result) == 2
assert "test.model_three" not in result
result = run_dbt(["-q", "ls", "--exclude", "model_one", "--exclude", "model_two"])
assert len(result) == 1
assert result == ["test.model_three"]
6 changes: 3 additions & 3 deletions tests/unit/test_cli_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,11 @@ def _create_flags_from_dict(self, cmd, d):
def test_from_dict__run(self):
args_dict = {
"print": False,
"select": ["model_one", "model_two"],
"select": "model_one, model_two",
emmyoop marked this conversation as resolved.
Show resolved Hide resolved
}
result = self._create_flags_from_dict(Command.RUN, args_dict)
assert "model_one" in result.select[0]
assert "model_two" in result.select[0]
assert "model_two" in result.select[1]

def test_from_dict__build(self):
args_dict = {
Expand All @@ -382,7 +382,7 @@ def test_from_dict__build(self):
assert "some/path" in str(result.state)

def test_from_dict__seed(self):
args_dict = {"use_colors": False, "exclude": ["model_three"]}
args_dict = {"use_colors": False, "exclude": "model_three"}
result = self._create_flags_from_dict(Command.SEED, args_dict)
assert result.use_colors is False
assert "model_three" in result.exclude[0]
Expand Down