diff --git a/Makefile b/Makefile index 298b696d..ed1b9d70 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ lint: .PHONY: proto_types proto_types: ## generates google protobuf python file from types.proto - protoc -I=./dbt/common/events --python_out=./dbt/common/events ./dbt/common/events/types.proto + hatch run dev-env:protoc -I=./dbt_common/events --python_out=./dbt_common/events ./dbt_common/events/types.proto .PHONY: help help: ## Show this help message. diff --git a/dbt_common/clients/agate_helper.py b/dbt_common/clients/agate_helper.py index 719d49c7..d5aa1b2a 100644 --- a/dbt_common/clients/agate_helper.py +++ b/dbt_common/clients/agate_helper.py @@ -7,7 +7,7 @@ from typing import Iterable, List, Dict, Union, Optional, Any from dbt_common.exceptions import DbtRuntimeError -from dbt_common.utils import ForgivingJSONEncoder +from dbt_common.utils.encoding import ForgivingJSONEncoder BOM = BOM_UTF8.decode("utf-8") # '\ufeff' diff --git a/dbt_common/clients/jinja.py b/dbt_common/clients/jinja.py index 34c2fa3b..a35984d7 100644 --- a/dbt_common/clients/jinja.py +++ b/dbt_common/clients/jinja.py @@ -8,14 +8,14 @@ from typing import List, Union, Set, Optional, Dict, Any, Iterator, Type, Callable from typing_extensions import Protocol -import jinja2 -import jinja2.ext +import jinja2 # type: ignore +import jinja2.ext # type: ignore import jinja2.nativetypes # type: ignore -import jinja2.nodes -import jinja2.parser -import jinja2.sandbox +import jinja2.nodes # type: ignore +import jinja2.parser # type: ignore +import jinja2.sandbox # type: ignore -from dbt_common.utils import ( +from dbt_common.utils.jinja import ( get_dbt_macro_name, get_docs_macro_name, get_materialization_macro_name, diff --git a/dbt_common/events/functions.py b/dbt_common/events/functions.py index a21fd317..c53e98f8 100644 --- a/dbt_common/events/functions.py +++ b/dbt_common/events/functions.py @@ -3,7 +3,7 @@ from dbt_common.events.event_manager_client import get_event_manager from dbt_common.invocation import get_invocation_id from dbt_common.helper_types import WarnErrorOptions -from dbt_common.utils import ForgivingJSONEncoder +from dbt_common.utils.encoding import ForgivingJSONEncoder from dbt_common.events.base_types import BaseEvent, EventLevel, EventMsg from dbt_common.events.logger import LoggerConfig, LineFormat from dbt_common.exceptions import scrub_secrets, env_secrets diff --git a/dbt_common/events/logger.py b/dbt_common/events/logger.py index 368d5aeb..f7a0a139 100644 --- a/dbt_common/events/logger.py +++ b/dbt_common/events/logger.py @@ -11,7 +11,7 @@ from dbt_common.events.base_types import EventLevel, EventMsg from dbt_common.events.format import timestamp_to_datetime_string -from dbt_common.utils import ForgivingJSONEncoder +from dbt_common.utils.encoding import ForgivingJSONEncoder # A Filter is a function which takes a BaseEvent and returns True if the event # should be logged, False otherwise. diff --git a/dbt_common/events/types_pb2.py b/dbt_common/events/types_pb2.py index 0afe8e57..0bf1c693 100644 --- a/dbt_common/events/types_pb2.py +++ b/dbt_common/events/types_pb2.py @@ -2,67 +2,67 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # source: types.proto """Generated protocol buffer code.""" +from google.protobuf.internal import builder as _builder from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database -from google.protobuf.internal import builder as _builder - # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile( - b'\n\x0btypes.proto\x12\x0bproto_types\x1a\x1fgoogle/protobuf/timestamp.proto"\x91\x02\n\tEventInfo\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0c\n\x04\x63ode\x18\x02 \x01(\t\x12\x0b\n\x03msg\x18\x03 \x01(\t\x12\r\n\x05level\x18\x04 \x01(\t\x12\x15\n\rinvocation_id\x18\x05 \x01(\t\x12\x0b\n\x03pid\x18\x06 \x01(\x05\x12\x0e\n\x06thread\x18\x07 \x01(\t\x12&\n\x02ts\x18\x08 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x30\n\x05\x65xtra\x18\t \x03(\x0b\x32!.proto_types.EventInfo.ExtraEntry\x12\x10\n\x08\x63\x61tegory\x18\n \x01(\t\x1a,\n\nExtraEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01"6\n\x0eGenericMessage\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo"1\n\x11RetryExternalCall\x12\x0f\n\x07\x61ttempt\x18\x01 \x01(\x05\x12\x0b\n\x03max\x18\x02 \x01(\x05"j\n\x14RetryExternalCallMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12,\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x1e.proto_types.RetryExternalCall"#\n\x14RecordRetryException\x12\x0b\n\x03\x65xc\x18\x01 \x01(\t"p\n\x17RecordRetryExceptionMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12/\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32!.proto_types.RecordRetryException"@\n\x13SystemCouldNotWrite\x12\x0c\n\x04path\x18\x01 \x01(\t\x12\x0e\n\x06reason\x18\x02 \x01(\t\x12\x0b\n\x03\x65xc\x18\x03 \x01(\t"n\n\x16SystemCouldNotWriteMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12.\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32 .proto_types.SystemCouldNotWrite"!\n\x12SystemExecutingCmd\x12\x0b\n\x03\x63md\x18\x01 \x03(\t"l\n\x15SystemExecutingCmdMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12-\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x1f.proto_types.SystemExecutingCmd"\x1c\n\x0cSystemStdOut\x12\x0c\n\x04\x62msg\x18\x01 \x01(\t"`\n\x0fSystemStdOutMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12\'\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x19.proto_types.SystemStdOut"\x1c\n\x0cSystemStdErr\x12\x0c\n\x04\x62msg\x18\x01 \x01(\t"`\n\x0fSystemStdErrMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12\'\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x19.proto_types.SystemStdErr",\n\x16SystemReportReturnCode\x12\x12\n\nreturncode\x18\x01 \x01(\x05"t\n\x19SystemReportReturnCodeMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12\x31\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32#.proto_types.SystemReportReturnCode"\x19\n\nFormatting\x12\x0b\n\x03msg\x18\x01 \x01(\t"\\\n\rFormattingMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12%\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x17.proto_types.Formatting"\x13\n\x04Note\x12\x0b\n\x03msg\x18\x01 \x01(\t"P\n\x07NoteMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12\x1f\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x11.proto_types.Noteb\x06proto3' -) +from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2 -_globals = globals() -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, "types_pb2", _globals) + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0btypes.proto\x12\x0bproto_types\x1a\x1fgoogle/protobuf/timestamp.proto\"\x91\x02\n\tEventInfo\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0c\n\x04\x63ode\x18\x02 \x01(\t\x12\x0b\n\x03msg\x18\x03 \x01(\t\x12\r\n\x05level\x18\x04 \x01(\t\x12\x15\n\rinvocation_id\x18\x05 \x01(\t\x12\x0b\n\x03pid\x18\x06 \x01(\x05\x12\x0e\n\x06thread\x18\x07 \x01(\t\x12&\n\x02ts\x18\x08 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x30\n\x05\x65xtra\x18\t \x03(\x0b\x32!.proto_types.EventInfo.ExtraEntry\x12\x10\n\x08\x63\x61tegory\x18\n \x01(\t\x1a,\n\nExtraEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"6\n\x0eGenericMessage\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\"1\n\x11RetryExternalCall\x12\x0f\n\x07\x61ttempt\x18\x01 \x01(\x05\x12\x0b\n\x03max\x18\x02 \x01(\x05\"j\n\x14RetryExternalCallMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12,\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x1e.proto_types.RetryExternalCall\"#\n\x14RecordRetryException\x12\x0b\n\x03\x65xc\x18\x01 \x01(\t\"p\n\x17RecordRetryExceptionMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12/\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32!.proto_types.RecordRetryException\"@\n\x13SystemCouldNotWrite\x12\x0c\n\x04path\x18\x01 \x01(\t\x12\x0e\n\x06reason\x18\x02 \x01(\t\x12\x0b\n\x03\x65xc\x18\x03 \x01(\t\"n\n\x16SystemCouldNotWriteMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12.\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32 .proto_types.SystemCouldNotWrite\"!\n\x12SystemExecutingCmd\x12\x0b\n\x03\x63md\x18\x01 \x03(\t\"l\n\x15SystemExecutingCmdMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12-\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x1f.proto_types.SystemExecutingCmd\"\x1c\n\x0cSystemStdOut\x12\x0c\n\x04\x62msg\x18\x01 \x01(\t\"`\n\x0fSystemStdOutMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12\'\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x19.proto_types.SystemStdOut\"\x1c\n\x0cSystemStdErr\x12\x0c\n\x04\x62msg\x18\x01 \x01(\t\"`\n\x0fSystemStdErrMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12\'\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x19.proto_types.SystemStdErr\",\n\x16SystemReportReturnCode\x12\x12\n\nreturncode\x18\x01 \x01(\x05\"t\n\x19SystemReportReturnCodeMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12\x31\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32#.proto_types.SystemReportReturnCode\"\x19\n\nFormatting\x12\x0b\n\x03msg\x18\x01 \x01(\t\"\\\n\rFormattingMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12%\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x17.proto_types.Formatting\"\x13\n\x04Note\x12\x0b\n\x03msg\x18\x01 \x01(\t\"P\n\x07NoteMsg\x12$\n\x04info\x18\x01 \x01(\x0b\x32\x16.proto_types.EventInfo\x12\x1f\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x11.proto_types.Noteb\x06proto3') + +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'types_pb2', globals()) if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None - _EVENTINFO_EXTRAENTRY._options = None - _EVENTINFO_EXTRAENTRY._serialized_options = b"8\001" - _globals["_EVENTINFO"]._serialized_start = 62 - _globals["_EVENTINFO"]._serialized_end = 335 - _globals["_EVENTINFO_EXTRAENTRY"]._serialized_start = 291 - _globals["_EVENTINFO_EXTRAENTRY"]._serialized_end = 335 - _globals["_GENERICMESSAGE"]._serialized_start = 337 - _globals["_GENERICMESSAGE"]._serialized_end = 391 - _globals["_RETRYEXTERNALCALL"]._serialized_start = 393 - _globals["_RETRYEXTERNALCALL"]._serialized_end = 442 - _globals["_RETRYEXTERNALCALLMSG"]._serialized_start = 444 - _globals["_RETRYEXTERNALCALLMSG"]._serialized_end = 550 - _globals["_RECORDRETRYEXCEPTION"]._serialized_start = 552 - _globals["_RECORDRETRYEXCEPTION"]._serialized_end = 587 - _globals["_RECORDRETRYEXCEPTIONMSG"]._serialized_start = 589 - _globals["_RECORDRETRYEXCEPTIONMSG"]._serialized_end = 701 - _globals["_SYSTEMCOULDNOTWRITE"]._serialized_start = 703 - _globals["_SYSTEMCOULDNOTWRITE"]._serialized_end = 767 - _globals["_SYSTEMCOULDNOTWRITEMSG"]._serialized_start = 769 - _globals["_SYSTEMCOULDNOTWRITEMSG"]._serialized_end = 879 - _globals["_SYSTEMEXECUTINGCMD"]._serialized_start = 881 - _globals["_SYSTEMEXECUTINGCMD"]._serialized_end = 914 - _globals["_SYSTEMEXECUTINGCMDMSG"]._serialized_start = 916 - _globals["_SYSTEMEXECUTINGCMDMSG"]._serialized_end = 1024 - _globals["_SYSTEMSTDOUT"]._serialized_start = 1026 - _globals["_SYSTEMSTDOUT"]._serialized_end = 1054 - _globals["_SYSTEMSTDOUTMSG"]._serialized_start = 1056 - _globals["_SYSTEMSTDOUTMSG"]._serialized_end = 1152 - _globals["_SYSTEMSTDERR"]._serialized_start = 1154 - _globals["_SYSTEMSTDERR"]._serialized_end = 1182 - _globals["_SYSTEMSTDERRMSG"]._serialized_start = 1184 - _globals["_SYSTEMSTDERRMSG"]._serialized_end = 1280 - _globals["_SYSTEMREPORTRETURNCODE"]._serialized_start = 1282 - _globals["_SYSTEMREPORTRETURNCODE"]._serialized_end = 1326 - _globals["_SYSTEMREPORTRETURNCODEMSG"]._serialized_start = 1328 - _globals["_SYSTEMREPORTRETURNCODEMSG"]._serialized_end = 1444 - _globals["_FORMATTING"]._serialized_start = 1446 - _globals["_FORMATTING"]._serialized_end = 1471 - _globals["_FORMATTINGMSG"]._serialized_start = 1473 - _globals["_FORMATTINGMSG"]._serialized_end = 1565 - _globals["_NOTE"]._serialized_start = 1567 - _globals["_NOTE"]._serialized_end = 1586 - _globals["_NOTEMSG"]._serialized_start = 1588 - _globals["_NOTEMSG"]._serialized_end = 1668 + + DESCRIPTOR._options = None + _EVENTINFO_EXTRAENTRY._options = None + _EVENTINFO_EXTRAENTRY._serialized_options = b'8\001' + _EVENTINFO._serialized_start=62 + _EVENTINFO._serialized_end=335 + _EVENTINFO_EXTRAENTRY._serialized_start=291 + _EVENTINFO_EXTRAENTRY._serialized_end=335 + _GENERICMESSAGE._serialized_start=337 + _GENERICMESSAGE._serialized_end=391 + _RETRYEXTERNALCALL._serialized_start=393 + _RETRYEXTERNALCALL._serialized_end=442 + _RETRYEXTERNALCALLMSG._serialized_start=444 + _RETRYEXTERNALCALLMSG._serialized_end=550 + _RECORDRETRYEXCEPTION._serialized_start=552 + _RECORDRETRYEXCEPTION._serialized_end=587 + _RECORDRETRYEXCEPTIONMSG._serialized_start=589 + _RECORDRETRYEXCEPTIONMSG._serialized_end=701 + _SYSTEMCOULDNOTWRITE._serialized_start=703 + _SYSTEMCOULDNOTWRITE._serialized_end=767 + _SYSTEMCOULDNOTWRITEMSG._serialized_start=769 + _SYSTEMCOULDNOTWRITEMSG._serialized_end=879 + _SYSTEMEXECUTINGCMD._serialized_start=881 + _SYSTEMEXECUTINGCMD._serialized_end=914 + _SYSTEMEXECUTINGCMDMSG._serialized_start=916 + _SYSTEMEXECUTINGCMDMSG._serialized_end=1024 + _SYSTEMSTDOUT._serialized_start=1026 + _SYSTEMSTDOUT._serialized_end=1054 + _SYSTEMSTDOUTMSG._serialized_start=1056 + _SYSTEMSTDOUTMSG._serialized_end=1152 + _SYSTEMSTDERR._serialized_start=1154 + _SYSTEMSTDERR._serialized_end=1182 + _SYSTEMSTDERRMSG._serialized_start=1184 + _SYSTEMSTDERRMSG._serialized_end=1280 + _SYSTEMREPORTRETURNCODE._serialized_start=1282 + _SYSTEMREPORTRETURNCODE._serialized_end=1326 + _SYSTEMREPORTRETURNCODEMSG._serialized_start=1328 + _SYSTEMREPORTRETURNCODEMSG._serialized_end=1444 + _FORMATTING._serialized_start=1446 + _FORMATTING._serialized_end=1471 + _FORMATTINGMSG._serialized_start=1473 + _FORMATTINGMSG._serialized_end=1565 + _NOTE._serialized_start=1567 + _NOTE._serialized_end=1586 + _NOTEMSG._serialized_start=1588 + _NOTEMSG._serialized_end=1668 # @@protoc_insertion_point(module_scope) diff --git a/tests/unit/test_jinja.py b/tests/unit/test_jinja.py index 600abe52..f038a1ec 100644 --- a/tests/unit/test_jinja.py +++ b/tests/unit/test_jinja.py @@ -53,8 +53,8 @@ def test_comments(self): def test_evil_comments(self): body = '{{ config(foo="bar") }}\r\nselect * from this.that\r\n' comment = ( - "{# external comment {% othertype bar %} select * from ", - "thing.other_thing{% endothertype %} #}", + "{# external comment {% othertype bar %} select * from " + "thing.other_thing{% endothertype %} #}" ) block_data = " \n\r\t{%- mytype foo %}" + body + "{%endmytype -%}" blocks = extract_toplevel_blocks( @@ -68,13 +68,13 @@ def test_evil_comments(self): def test_nested_comments(self): body = ( - '{# my comment #} {{ config(foo="bar") }}', - "\r\nselect * from {# my other comment embedding {% endmytype %} #} this.that\r\n", + '{# my comment #} {{ config(foo="bar") }}' + "\r\nselect * from {# my other comment embedding {% endmytype %} #} this.that\r\n" ) block_data = " \n\r\t{%- mytype foo %}" + body + "{% endmytype -%}" comment = ( - "{# external comment {% othertype bar %} select * from ", - "thing.other_thing{% endothertype %} #}", + "{# external comment {% othertype bar %} select * from " + "thing.other_thing{% endothertype %} #}" ) blocks = extract_toplevel_blocks( comment + block_data, allowed_blocks={"mytype"}, collect_raw_data=False @@ -108,8 +108,8 @@ def test_complex_file(self): def test_peaceful_macro_coexistence(self): body = ( - "{# my macro #} {% macro foo(a, b) %} do a thing ", - "{%- endmacro %} {# my model #} {% a b %} test {% enda %}", + "{# my macro #} {% macro foo(a, b) %} do a thing " + "{%- endmacro %} {# my model #} {% a b %} test {% enda %}" ) blocks = extract_toplevel_blocks( body, allowed_blocks={"macro", "a"}, collect_raw_data=True @@ -126,8 +126,8 @@ def test_peaceful_macro_coexistence(self): def test_macro_with_trailing_data(self): body = ( - "{# my macro #} {% macro foo(a, b) %} do a thing {%- endmacro %} ", - "{# my model #} {% a b %} test {% enda %} raw data so cool", + "{# my macro #} {% macro foo(a, b) %} do a thing {%- endmacro %} " + "{# my model #} {% a b %} test {% enda %} raw data so cool" ) blocks = extract_toplevel_blocks( body, allowed_blocks={"macro", "a"}, collect_raw_data=True @@ -145,9 +145,9 @@ def test_macro_with_trailing_data(self): def test_macro_with_crazy_args(self): body = ( - """{% macro foo(a, b=asdf("cool this is 'embedded'" * 3) + external_var, c)%}""", - "cool{# block comment with {% endmacro %} in it #} stuff here ", - "{% endmacro %}", + """{% macro foo(a, b=asdf("cool this is 'embedded'" * 3) + external_var, c)%}""" + "cool{# block comment with {% endmacro %} in it #} stuff here " + "{% endmacro %}" ) blocks = extract_toplevel_blocks(body, allowed_blocks={"macro"}, collect_raw_data=False) self.assertEqual(len(blocks), 1) @@ -234,8 +234,8 @@ def test_set_block(self): def test_crazy_set_statement(self): body = ( - '{% set x = (thing("{% myblock foo %}")) %}{% otherblock bar %}x{% endotherblock %}', - '{% set y = otherthing("{% myblock foo %}") %}', + '{% set x = (thing("{% myblock foo %}")) %}{% otherblock bar %}x{% endotherblock %}' + '{% set y = otherthing("{% myblock foo %}") %}' ) blocks = extract_toplevel_blocks( body, allowed_blocks={"otherblock"}, collect_raw_data=False @@ -268,8 +268,8 @@ def test_do_block(self): def test_crazy_do_statement(self): body = ( - '{% do (thing("{% myblock foo %}")) %}{% otherblock bar %}x{% endotherblock %}', - '{% do otherthing("{% myblock foo %}") %}{% myblock x %}hi{% endmyblock %}', + '{% do (thing("{% myblock foo %}")) %}{% otherblock bar %}x{% endotherblock %}' + '{% do otherthing("{% myblock foo %}") %}{% myblock x %}hi{% endmyblock %}' ) blocks = extract_toplevel_blocks( body, allowed_blocks={"myblock", "otherblock"}, collect_raw_data=False @@ -313,8 +313,8 @@ def test_quoted_endblock_within_block(self): def test_docs_block(self): body = ( - "{% docs __my_doc__ %} asdf {# nope {% enddocs %}} #} {% enddocs %}", - '{% docs __my_other_doc__ %} asdf "{% enddocs %}', + "{% docs __my_doc__ %} asdf {# nope {% enddocs %}} #} {% enddocs %}" + '{% docs __my_other_doc__ %} asdf "{% enddocs %}' ) blocks = extract_toplevel_blocks(body, allowed_blocks={"docs"}, collect_raw_data=False) self.assertEqual(len(blocks), 2) @@ -363,8 +363,8 @@ def test_for(self): def test_for_innocuous(self): # no for-loops over macros. body = ( - "{% for x in range(10) %}{% something my_something %} adsf ", - "{% endsomething %}{% endfor %}", + "{% for x in range(10) %}{% something my_something %} adsf " + "{% endsomething %}{% endfor %}" ) blocks = extract_toplevel_blocks(body) self.assertEqual(len(blocks), 1) @@ -376,8 +376,8 @@ def test_endif(self): extract_toplevel_blocks(body) self.assertIn( ( - "Got an unexpected control flow end tag, got endif but ", - "never saw a preceeding if (@ 1:53)", + "Got an unexpected control flow end tag, got endif but " + "never saw a preceeding if (@ 1:53)" ), str(err.exception), ) diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 2237914a..250c20cc 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -1,7 +1,7 @@ import unittest import dbt_common.exceptions -import dbt_common.utils +import dbt_common.utils.dict class TestDeepMerge(unittest.TestCase): @@ -16,7 +16,7 @@ def test__simple_cases(self): ] for case in cases: - actual = dbt_common.utils.deep_merge(*case["args"]) + actual = dbt_common.utils.dict.deep_merge(*case["args"]) self.assertEqual( case["expected"], actual, @@ -38,7 +38,7 @@ def test__simple_cases(self): ] for case in cases: - actual = dbt_common.utils.deep_merge(*case["args"]) + actual = dbt_common.utils.dict.deep_merge(*case["args"]) self.assertEqual( case["expected"], actual, @@ -91,10 +91,10 @@ def test__simple_cases(self): }, ], } - actual = dbt_common.utils.deep_map_render(self.intify_all, self.input_value) + actual = dbt_common.utils.dict.deep_map_render(self.intify_all, self.input_value) self.assertEqual(actual, expected) - actual = dbt_common.utils.deep_map_render(self.intify_all, expected) + actual = dbt_common.utils.dict.deep_map_render(self.intify_all, expected) self.assertEqual(actual, expected) @staticmethod @@ -122,21 +122,21 @@ def test__keypath(self): }, ], } - actual = dbt_common.utils.deep_map_render(self.special_keypath, self.input_value) + actual = dbt_common.utils.dict.deep_map_render(self.special_keypath, self.input_value) self.assertEqual(actual, expected) - actual = dbt_common.utils.deep_map_render(self.special_keypath, expected) + actual = dbt_common.utils.dict.deep_map_render(self.special_keypath, expected) self.assertEqual(actual, expected) def test__noop(self): - actual = dbt_common.utils.deep_map_render(lambda x, _: x, self.input_value) + actual = dbt_common.utils.dict.deep_map_render(lambda x, _: x, self.input_value) self.assertEqual(actual, self.input_value) def test_trivial(self): cases = [[], {}, 1, "abc", None, True] for case in cases: - result = dbt_common.utils.deep_map_render(lambda x, _: x, case) + result = dbt_common.utils.dict.deep_map_render(lambda x, _: x, case) self.assertEqual(result, case) with self.assertRaises(dbt_common.exceptions.DbtConfigError): - dbt_common.utils.deep_map_render(lambda x, _: x, {"foo": object()}) + dbt_common.utils.dict.deep_map_render(lambda x, _: x, {"foo": object()})