From 8aa646b68766fa5f12f52ef88668581e002226b8 Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Tue, 1 Oct 2024 16:43:24 -0400 Subject: [PATCH] Add test --- tests/unit/test_jinja.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_jinja.py b/tests/unit/test_jinja.py index cf44eee..e839296 100644 --- a/tests/unit/test_jinja.py +++ b/tests/unit/test_jinja.py @@ -1,7 +1,7 @@ import unittest from dbt_common.clients._jinja_blocks import BlockTag -from dbt_common.clients.jinja import extract_toplevel_blocks +from dbt_common.clients.jinja import extract_toplevel_blocks, get_template, render_template from dbt_common.exceptions import CompilationError @@ -503,3 +503,24 @@ def test_if_endfor_newlines(self) -> None: hi {% endmaterialization %} """ + + +def test_if_list_filter(): + jinja_string = """ + {%- if my_var | is_list -%} + Found a list + {%- else -%} + Did not find a list + {%- endif -%} + """ + # Check with list variable + ctx = {"my_var": ["one", "two"]} + template = get_template(jinja_string, ctx) + rendered = render_template(template, ctx) + assert "Found a list" in rendered + + # Check with non-list variable + ctx = {"my_var": "one"} + template = get_template(jinja_string, ctx) + rendered = render_template(template, ctx) + assert "Did not find a list" in rendered