From 04d87d452f0e25ec16f20b30f315d05cf8d87fac Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Mon, 18 Sep 2023 15:06:51 -0500 Subject: [PATCH 01/16] allow multioption to be quoted --- core/dbt/cli/options.py | 2 +- tests/functional/cli/test_multioption.py | 102 +++++++++++++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 tests/functional/cli/test_multioption.py diff --git a/core/dbt/cli/options.py b/core/dbt/cli/options.py index 3a42dddda80..dc225b172f3 100644 --- a/core/dbt/cli/options.py +++ b/core/dbt/cli/options.py @@ -33,7 +33,7 @@ def add_to_parser(self, parser, ctx): def parser_process(value, state): # 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: diff --git a/tests/functional/cli/test_multioption.py b/tests/functional/cli/test_multioption.py new file mode 100644 index 00000000000..40838a694fd --- /dev/null +++ b/tests/functional/cli/test_multioption.py @@ -0,0 +1,102 @@ +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 + + def test_resource_type_quoted(self): + result = run_dbt(["-q", "ls", "--resource-types", "model source"]) + assert len(result) == 2 + + def test_resource_type_args(self): + result = run_dbt(["-q", "ls", "--resource-type", "model", "--resource-type", "source"]) + assert len(result) == 2 + + +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): + 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): + 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): + 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): + 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"] From 8c451520732e0bbaec6c1dd97c53567f42b06647 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Mon, 18 Sep 2023 15:09:01 -0500 Subject: [PATCH 02/16] changelog --- .changes/unreleased/Features-20230918-150855.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Features-20230918-150855.yaml diff --git a/.changes/unreleased/Features-20230918-150855.yaml b/.changes/unreleased/Features-20230918-150855.yaml new file mode 100644 index 00000000000..d54313fd5e9 --- /dev/null +++ b/.changes/unreleased/Features-20230918-150855.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Support quoted parameter list for MultiOption CLI options.. +time: 2023-09-18T15:08:55.625412-05:00 +custom: + Author: emmyoop + Issue: "8598" From 82c60cb723617f0a378182fb476d2ef450c48ae3 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Tue, 19 Sep 2023 10:34:23 -0500 Subject: [PATCH 03/16] fix test --- tests/unit/test_cli_flags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_cli_flags.py b/tests/unit/test_cli_flags.py index d5d78a229ae..5c2bcc8e99b 100644 --- a/tests/unit/test_cli_flags.py +++ b/tests/unit/test_cli_flags.py @@ -370,7 +370,7 @@ def test_from_dict__run(self): } 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 = { From 08792e5af60d1286e38ce2367088f37748184e57 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Tue, 19 Sep 2023 11:07:23 -0500 Subject: [PATCH 04/16] remove list format --- tests/unit/test_cli_flags.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_cli_flags.py b/tests/unit/test_cli_flags.py index 5c2bcc8e99b..78169c049cb 100644 --- a/tests/unit/test_cli_flags.py +++ b/tests/unit/test_cli_flags.py @@ -366,7 +366,7 @@ 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", } result = self._create_flags_from_dict(Command.RUN, args_dict) assert "model_one" in result.select[0] @@ -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] From 9c6de653ba3469c46decdf3d103e658e934ea628 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Tue, 19 Sep 2023 11:33:38 -0500 Subject: [PATCH 05/16] fix tests --- tests/functional/cli/test_multioption.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/functional/cli/test_multioption.py b/tests/functional/cli/test_multioption.py index 40838a694fd..1a5cb53806d 100644 --- a/tests/functional/cli/test_multioption.py +++ b/tests/functional/cli/test_multioption.py @@ -24,14 +24,17 @@ def models(self): 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): + 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"] - def test_resource_type_args(self): + 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: @@ -44,13 +47,13 @@ def test_output_key_single(self, project): assert len(result) == 1 assert result == ['{"name": "model_one"}'] - def test_output_key_quoted(self): + 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): + def test_output_key_args(self, project): result = run_dbt( [ "-q", @@ -85,7 +88,7 @@ def test_select_exclude_single(self, project): assert len(result) == 2 assert "test.model_one" not in result - def test_select_exclude_quoted(self): + 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 @@ -93,7 +96,7 @@ def test_select_exclude_quoted(self): assert len(result) == 1 assert result == ["test.model_three"] - def test_select_exclude_args(self): + 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 From 9aa22fd953f0ad99c7e926d47f2cf41b7281f025 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Thu, 21 Sep 2023 09:30:02 -0500 Subject: [PATCH 06/16] fix list object --- core/dbt/cli/flags.py | 6 +++- tests/functional/retry/fixtures.py | 13 ++++++++ tests/functional/retry/test_retry.py | 46 ++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/core/dbt/cli/flags.py b/core/dbt/cli/flags.py index 863db6ed0e4..2678d53b6dd 100644 --- a/core/dbt/cli/flags.py +++ b/core/dbt/cli/flags.py @@ -57,7 +57,7 @@ def args_to_context(args: List[str]) -> Context: from dbt.cli.main import cli cli_ctx = cli.make_context(cli.name, args) - # Split args if they're a comma seperated string. + # Split args if they're a comma separated string. if len(args) == 1 and "," in args[0]: args = args[0].split(",") sub_command_name, sub_command, args = cli.resolve_command(cli_ctx, args) @@ -340,6 +340,10 @@ def add_fn(x): spinal_cased = k.replace("_", "-") + # MultiOption flags come back as lists, but we want to pass them as space separated strings + if isinstance(v, list): + v = " ".join(v) + if k == "macro" and command == CliCommand.RUN_OPERATION: add_fn(v) # None is a Singleton, False is a Flyweight, only one instance of each. diff --git a/tests/functional/retry/fixtures.py b/tests/functional/retry/fixtures.py index 1c063b4490a..caa1191b837 100644 --- a/tests/functional/retry/fixtures.py +++ b/tests/functional/retry/fixtures.py @@ -45,3 +45,16 @@ {% do log("Timezone set to: " + timezone, info=True) %} {% endmacro %} """ + +simple_model = """ +select null as id +""" + +simple_schema = """ +models: + - name: some_model + columns: + - name: id + tests: + - not_null +""" diff --git a/tests/functional/retry/test_retry.py b/tests/functional/retry/test_retry.py index 8c322a664c7..c028bc33f45 100644 --- a/tests/functional/retry/test_retry.py +++ b/tests/functional/retry/test_retry.py @@ -9,6 +9,8 @@ schema_yml, models__second_model, macros__alter_timezone_sql, + simple_model, + simple_schema, ) @@ -225,3 +227,47 @@ def test_fail_fast(self, project): results = run_dbt(["retry"]) assert {r.node.unique_id: r.status for r in results.results} == {} + + +class TestRetryResourceType: + @pytest.fixture(scope="class") + def models(self): + return { + "null_model.sql": simple_model, + "schema.yml": simple_schema, + } + + def test_resource_type(self, project): + # test multiple options in single string + results = run_dbt(["build", "--select", "null_model", "--resource-type", "test model"]) + assert len(results) == 1 + + # nothing to do + results = run_dbt(["retry"]) + assert len(results) == 0 + + # test multiple options in multiple args + results = run_dbt( + [ + "build", + "--select", + "null_model", + "--resource-type", + "test", + "--resource-type", + "model", + ] + ) + assert len(results) == 1 + + # nothing to do + results = run_dbt(["retry"]) + assert len(results) == 0 + + # test single all option + results = run_dbt(["build", "--select", "null_model", "--resource-type", "all"]) + assert len(results) == 1 + + # nothing to do + results = run_dbt(["retry"]) + assert len(results) == 0 From 52dda3322097855e9f8d9c0bed00fb211400ddec Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Thu, 21 Sep 2023 09:54:23 -0500 Subject: [PATCH 07/16] review arg change --- tests/unit/test_cli_flags.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_cli_flags.py b/tests/unit/test_cli_flags.py index 78169c049cb..2e0682cca13 100644 --- a/tests/unit/test_cli_flags.py +++ b/tests/unit/test_cli_flags.py @@ -366,7 +366,7 @@ 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"], } result = self._create_flags_from_dict(Command.RUN, args_dict) assert "model_one" in result.select[0] @@ -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] From d70a49a55c7cc5ea2a5ae8666d0ed31078e34b32 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Thu, 21 Sep 2023 09:55:08 -0500 Subject: [PATCH 08/16] fix quotes --- tests/unit/test_cli_flags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_cli_flags.py b/tests/unit/test_cli_flags.py index 2e0682cca13..5c2bcc8e99b 100644 --- a/tests/unit/test_cli_flags.py +++ b/tests/unit/test_cli_flags.py @@ -366,7 +366,7 @@ 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"], } result = self._create_flags_from_dict(Command.RUN, args_dict) assert "model_one" in result.select[0] From 40b7daf1cdc2f70febceeeae2c007de57c3a31ac Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Thu, 21 Sep 2023 09:56:31 -0500 Subject: [PATCH 09/16] Update .changes/unreleased/Features-20230918-150855.yaml --- .changes/unreleased/Features-20230918-150855.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/unreleased/Features-20230918-150855.yaml b/.changes/unreleased/Features-20230918-150855.yaml index d54313fd5e9..b54b3447b7a 100644 --- a/.changes/unreleased/Features-20230918-150855.yaml +++ b/.changes/unreleased/Features-20230918-150855.yaml @@ -1,5 +1,5 @@ kind: Features -body: Support quoted parameter list for MultiOption CLI options.. +body: Support quoted parameter list for MultiOption CLI options. time: 2023-09-18T15:08:55.625412-05:00 custom: Author: emmyoop From 814d15e9d6d6afdde053ce8ce843976b270152dd Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Fri, 22 Sep 2023 11:40:03 -0500 Subject: [PATCH 10/16] add types --- core/dbt/cli/options.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/core/dbt/cli/options.py b/core/dbt/cli/options.py index dc225b172f3..53cacacfde3 100644 --- a/core/dbt/cli/options.py +++ b/core/dbt/cli/options.py @@ -2,6 +2,7 @@ import inspect import typing as t from click import Context +from click.parser import OptionParser, ParsingState from dbt.cli.option_types import ChoiceTuple @@ -29,11 +30,11 @@ def __init__(self, *args, **kwargs): else: assert isinstance(option_type, ChoiceTuple), msg - def add_to_parser(self, parser, ctx): - def parser_process(value, state): + def add_to_parser(self, parser: OptionParser, ctx: Context): + def parser_process(value: str, state: ParsingState): # method to hook to the parser.process done = False - value = str.split(value, " ") + value_list = str.split(value, " ") if self.save_other_options: # grab everything up to the next option while state.rargs and not done: @@ -41,14 +42,14 @@ def parser_process(value, state): if state.rargs[0].startswith(prefix): done = True if not done: - value.append(state.rargs.pop(0)) + value_list.append(state.rargs.pop(0)) else: # grab everything remaining - value += state.rargs + value_list += state.rargs state.rargs[:] = [] - value = tuple(value) + value_tuple = tuple(value_list) # call the actual process - self._previous_parser_process(value, state) + self._previous_parser_process(value_tuple, state) retval = super(MultiOption, self).add_to_parser(parser, ctx) for name in self.opts: @@ -56,7 +57,8 @@ def parser_process(value, state): if our_parser: self._eat_all_parser = our_parser self._previous_parser_process = our_parser.process - our_parser.process = parser_process + # mypy doesnt like assingment to a method see https://github.com/python/mypy/issues/708 + our_parser.process = parser_process # type: ignore break return retval From f88572f006a34f35e04a88c29278ea6dfe80837f Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Fri, 22 Sep 2023 11:44:13 -0500 Subject: [PATCH 11/16] convert list to set in test --- tests/functional/cli/test_multioption.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/functional/cli/test_multioption.py b/tests/functional/cli/test_multioption.py index 1a5cb53806d..2da0014604d 100644 --- a/tests/functional/cli/test_multioption.py +++ b/tests/functional/cli/test_multioption.py @@ -29,12 +29,14 @@ def test_resource_type_single(self, project): 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"] + expected_result = {"test.model_one", "source:test.my_source.my_table"} + assert set(result) == expected_result 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"] + expected_result = {"test.model_one", "source:test.my_source.my_table"} + assert set(result) == expected_result class TestOutputKeys: From a95e26c1c8c6fdad4f1595a2b6d48dc45c19d664 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Fri, 22 Sep 2023 12:14:59 -0500 Subject: [PATCH 12/16] make mypy happy --- core/dbt/cli/options.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/dbt/cli/options.py b/core/dbt/cli/options.py index 53cacacfde3..9d30e74efb8 100644 --- a/core/dbt/cli/options.py +++ b/core/dbt/cli/options.py @@ -14,8 +14,9 @@ def __init__(self, *args, **kwargs): nargs = kwargs.pop("nargs", -1) assert nargs == -1, "nargs, if set, must be -1 not {}".format(nargs) super(MultiOption, self).__init__(*args, **kwargs) - self._previous_parser_process = None - self._eat_all_parser = None + # this makes mypy happy, setting these to None causes mypy failures + self._previous_parser_process = lambda *args, **kwargs: None + self._eat_all_parser = lambda *args, **kwargs: None # validate that multiple=True multiple = kwargs.pop("multiple", None) @@ -55,9 +56,9 @@ def parser_process(value: str, state: ParsingState): for name in self.opts: our_parser = parser._long_opt.get(name) or parser._short_opt.get(name) if our_parser: - self._eat_all_parser = our_parser - self._previous_parser_process = our_parser.process # mypy doesnt like assingment to a method see https://github.com/python/mypy/issues/708 + self._eat_all_parser = our_parser # type: ignore + self._previous_parser_process = our_parser.process # type: ignore our_parser.process = parser_process # type: ignore break return retval From ed9c5bbbe82b4735b010243c65712ae79564d7d8 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Fri, 22 Sep 2023 12:34:22 -0500 Subject: [PATCH 13/16] mroe mypy happiness --- core/dbt/cli/options.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/dbt/cli/options.py b/core/dbt/cli/options.py index 9d30e74efb8..9dc1a037773 100644 --- a/core/dbt/cli/options.py +++ b/core/dbt/cli/options.py @@ -15,8 +15,8 @@ def __init__(self, *args, **kwargs): assert nargs == -1, "nargs, if set, must be -1 not {}".format(nargs) super(MultiOption, self).__init__(*args, **kwargs) # this makes mypy happy, setting these to None causes mypy failures - self._previous_parser_process = lambda *args, **kwargs: None - self._eat_all_parser = lambda *args, **kwargs: None + self._previous_parser_process = None + self._eat_all_parser = None # validate that multiple=True multiple = kwargs.pop("multiple", None) @@ -39,7 +39,7 @@ def parser_process(value: str, state: ParsingState): if self.save_other_options: # grab everything up to the next option while state.rargs and not done: - for prefix in self._eat_all_parser.prefixes: + for prefix in self._eat_all_parser.prefixes: # type: ignore[attr-defined] if state.rargs[0].startswith(prefix): done = True if not done: @@ -57,9 +57,9 @@ def parser_process(value: str, state: ParsingState): our_parser = parser._long_opt.get(name) or parser._short_opt.get(name) if our_parser: # mypy doesnt like assingment to a method see https://github.com/python/mypy/issues/708 - self._eat_all_parser = our_parser # type: ignore - self._previous_parser_process = our_parser.process # type: ignore - our_parser.process = parser_process # type: ignore + self._eat_all_parser = our_parser + self._previous_parser_process = our_parser.process + our_parser.process = parser_process # type: ignore[method-assign] break return retval From 3de423195a80ab27db48e2f35a90df35f854e70f Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Fri, 22 Sep 2023 12:49:44 -0500 Subject: [PATCH 14/16] more mypy happiness --- core/dbt/cli/options.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/dbt/cli/options.py b/core/dbt/cli/options.py index 9dc1a037773..ccc9a91f46c 100644 --- a/core/dbt/cli/options.py +++ b/core/dbt/cli/options.py @@ -15,8 +15,8 @@ def __init__(self, *args, **kwargs): assert nargs == -1, "nargs, if set, must be -1 not {}".format(nargs) super(MultiOption, self).__init__(*args, **kwargs) # this makes mypy happy, setting these to None causes mypy failures - self._previous_parser_process = None - self._eat_all_parser = None + self._previous_parser_process = lambda *args, **kwargs: None + self._eat_all_parser = lambda *args, **kwargs: None # validate that multiple=True multiple = kwargs.pop("multiple", None) @@ -56,9 +56,9 @@ def parser_process(value: str, state: ParsingState): for name in self.opts: our_parser = parser._long_opt.get(name) or parser._short_opt.get(name) if our_parser: - # mypy doesnt like assingment to a method see https://github.com/python/mypy/issues/708 self._eat_all_parser = our_parser self._previous_parser_process = our_parser.process + # mypy doesnt like assingment to a method see https://github.com/python/mypy/issues/708 our_parser.process = parser_process # type: ignore[method-assign] break return retval From daa025c4e3b696d7e5e38277d5d76781e66f6df2 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Fri, 22 Sep 2023 13:28:56 -0500 Subject: [PATCH 15/16] last mypy change --- core/dbt/cli/options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/dbt/cli/options.py b/core/dbt/cli/options.py index ccc9a91f46c..307a1ce97aa 100644 --- a/core/dbt/cli/options.py +++ b/core/dbt/cli/options.py @@ -56,7 +56,7 @@ def parser_process(value: str, state: ParsingState): for name in self.opts: our_parser = parser._long_opt.get(name) or parser._short_opt.get(name) if our_parser: - self._eat_all_parser = our_parser + self._eat_all_parser = our_parser # type: ignore[assignment] self._previous_parser_process = our_parser.process # mypy doesnt like assingment to a method see https://github.com/python/mypy/issues/708 our_parser.process = parser_process # type: ignore[method-assign] From e1fb937e0f064b8a3b2ffd56fd650d0d72bb8863 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Fri, 22 Sep 2023 13:51:19 -0500 Subject: [PATCH 16/16] add node to test --- tests/functional/cli/test_multioption.py | 49 ++++++++++++++++++++---- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/tests/functional/cli/test_multioption.py b/tests/functional/cli/test_multioption.py index 2da0014604d..e9013fdb658 100644 --- a/tests/functional/cli/test_multioption.py +++ b/tests/functional/cli/test_multioption.py @@ -6,20 +6,35 @@ select 1 as fun """ -source_sql = """ +schema_sql = """ sources: - name: my_source description: "My source" schema: test_schema tables: - name: my_table + - name: my_other_table + +exposures: + - name: weekly_jaffle_metrics + label: By the Week + type: dashboard + maturity: high + url: https://bi.tool/dashboards/1 + description: > + Did someone say "exponential growth"? + depends_on: + - ref('model_one') + owner: + name: dbt Labs + email: data@jaffleshop.com """ class TestResourceType: @pytest.fixture(scope="class") def models(self): - return {"schema.yml": source_sql, "model_one.sql": model_one_sql} + return {"schema.yml": schema_sql, "model_one.sql": model_one_sql} def test_resource_type_single(self, project): result = run_dbt(["-q", "ls", "--resource-types", "model"]) @@ -28,14 +43,34 @@ def test_resource_type_single(self, project): def test_resource_type_quoted(self, project): result = run_dbt(["-q", "ls", "--resource-types", "model source"]) - assert len(result) == 2 - expected_result = {"test.model_one", "source:test.my_source.my_table"} + assert len(result) == 3 + expected_result = { + "test.model_one", + "source:test.my_source.my_table", + "source:test.my_source.my_other_table", + } assert set(result) == expected_result def test_resource_type_args(self, project): - result = run_dbt(["-q", "ls", "--resource-type", "model", "--resource-type", "source"]) - assert len(result) == 2 - expected_result = {"test.model_one", "source:test.my_source.my_table"} + result = run_dbt( + [ + "-q", + "ls", + "--resource-type", + "model", + "--resource-type", + "source", + "--resource-type", + "exposure", + ] + ) + assert len(result) == 4 + expected_result = { + "test.model_one", + "source:test.my_source.my_table", + "source:test.my_source.my_other_table", + "exposure:test.weekly_jaffle_metrics", + } assert set(result) == expected_result