Skip to content

Commit

Permalink
fix testing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
emmyoop committed Jan 12, 2024
1 parent 457e0ba commit 59f9fbb
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 96 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion dbt_common/clients/agate_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
12 changes: 6 additions & 6 deletions dbt_common/clients/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion dbt_common/events/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dbt_common/events/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
106 changes: 53 additions & 53 deletions dbt_common/events/types_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 23 additions & 23 deletions tests/unit/test_jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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),
)
Expand Down
Loading

0 comments on commit 59f9fbb

Please sign in to comment.