-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix test_builtin_invocation_args_dict_function #6898
Changes from 6 commits
4954c49
cb05818
3464ba7
74dde44
ed81349
7922969
255e715
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,9 @@ | |
|
||
macros__validate_invocation_sql = """ | ||
{% macro validate_invocation(my_variable) %} | ||
-- check a specific value | ||
{{ log("use_colors: "~ invocation_args_dict['use_colors']) }} | ||
-- whole dictionary (as string) | ||
{{ log("invocation_result: "~ invocation_args_dict) }} | ||
{% endmacro %} | ||
""" | ||
|
@@ -61,7 +64,11 @@ def parse_json_logs(json_log_output): | |
|
||
def find_result_in_parsed_logs(parsed_logs, result_name): | ||
return next( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Can we rewrite this as a loop instead? |
||
(item for item in parsed_logs if result_name in item["info"].get("msg", "msg")), | ||
( | ||
item["data"]["msg"] | ||
for item in parsed_logs | ||
if result_name in item["data"].get("msg", "msg") | ||
), | ||
False, | ||
) | ||
|
||
|
@@ -104,27 +111,22 @@ def test_builtin_invocation_args_dict_function(self, project): | |
) | ||
|
||
parsed_logs = parse_json_logs(log_output) | ||
result = find_result_in_parsed_logs(parsed_logs, "invocation_result") | ||
|
||
use_colors = result = find_result_in_parsed_logs(parsed_logs, "use_colors") | ||
assert use_colors == "use_colors: True" | ||
invocation_dict = find_result_in_parsed_logs(parsed_logs, "invocation_result") | ||
assert result | ||
|
||
# Result is checked in two parts because profiles_dir is unique each test run | ||
expected = "invocation_result: {'debug': True, 'log_format': 'json', 'write_json': True, 'use_colors': True, 'printer_width': 80, 'version_check': True, 'partial_parse': True, 'static_parser': True, 'profiles_dir': " | ||
assert expected in str(result) | ||
iknox-fa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# The result should include a dictionary of all flags with values that aren't None | ||
expected = ( | ||
"'send_anonymous_usage_stats': False", | ||
iknox-fa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"'quiet': False", | ||
"'no_print': False", | ||
iknox-fa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"'print': True", | ||
"'cache_selected_only': False", | ||
"'macro': 'validate_invocation'", | ||
"'args': '{my_variable: test_variable}'", | ||
iknox-fa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"'args': {'my_variable': 'test_variable'}", | ||
"'which': 'run-operation'", | ||
"'rpc_method': 'run-operation'", | ||
iknox-fa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"'indirect_selection': 'eager'", | ||
) | ||
for element in expected: | ||
assert element in str(result) | ||
assert all(element in invocation_dict for element in expected) | ||
|
||
def test_builtin_dbt_metadata_envs_function(self, project, monkeypatch): | ||
envs = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,25 +45,54 @@ def test_log_path_default(self, run_context): | |
assert getattr(flags, "LOG_PATH") == "logs" | ||
|
||
@pytest.mark.parametrize( | ||
"do_not_track,expected_anonymous_usage_stats", | ||
"set_stats_param,do_not_track,expected_anonymous_usage_stats", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MichelleArk There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you!! Looks great. |
||
[ | ||
("1", False), | ||
("t", False), | ||
("true", False), | ||
("y", False), | ||
("yes", False), | ||
("false", True), | ||
("anything", True), | ||
("2", True), | ||
# set_stats_param = default, DNT = True, expected = False | ||
("default", "1", False), | ||
("default", "t", False), | ||
("default", "true", False), | ||
("default", "y", False), | ||
("default", "yes", False), | ||
# set_stats_param = default, DNT = false, expected = True | ||
("default", "false", True), | ||
("default", "anything", True), | ||
# set_stats_param = True, DNT = True, expected = False | ||
(True, "1", False), | ||
(True, "t", False), | ||
(True, "true", False), | ||
(True, "y", False), | ||
(True, "yes", False), | ||
# set_stats_param = True, DNT = false, expected = True | ||
(True, "false", True), | ||
(True, "anything", True), | ||
(True, "2", True), | ||
# set_stats_param = False, DNT = True, expected = False | ||
(False, "1", False), | ||
(False, "t", False), | ||
(False, "true", False), | ||
(False, "y", False), | ||
(False, "yes", False), | ||
# set_stats_param = False, DNT = False, expected = False | ||
(False, "false", False), | ||
(False, "anything", False), | ||
(False, "2", False), | ||
], | ||
) | ||
def test_anonymous_usage_state( | ||
self, monkeypatch, run_context, do_not_track, expected_anonymous_usage_stats | ||
self, | ||
monkeypatch, | ||
run_context, | ||
set_stats_param, | ||
do_not_track, | ||
expected_anonymous_usage_stats, | ||
): | ||
# patch the env | ||
monkeypatch.setenv("DO_NOT_TRACK", do_not_track) | ||
|
||
# set the param | ||
if set_stats_param != "default": | ||
run_context.params["send_anonymous_usage_stats"] = set_stats_param | ||
flags = Flags(run_context) | ||
assert flags.ANONYMOUS_USAGE_STATS == expected_anonymous_usage_stats | ||
assert flags.SEND_ANONYMOUS_USAGE_STATS is expected_anonymous_usage_stats | ||
|
||
def test_empty_user_config_uses_default(self, run_context, user_config): | ||
flags = Flags(run_context, user_config) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Tracking this in #6903
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it turns out renaming a symbol in some places and not others is confusing AF. Might as well do it all at once since it's going to require changes in a medium sized pile of tests that have a manually set value for send stats (not sure why, most of them have nothing to do with tracking).
/shrug