bito-code-review[bot] commented on code in PR #42785:
URL: https://github.com/apache/superset/pull/42785#discussion_r3976081157
##########
tests/unit_tests/jinja_context_test.py:
##########
@@ -3416,3 +3416,81 @@ def
test_get_rendered_sql_filter_values_index_error_on_empty_list() -> None:
match=r"Virtual dataset template error: list object has no element 0",
):
table.get_rendered_sql(processor)
+
+
[email protected](
+ "sql,expected",
+ [
+ pytest.param("SELECT 1", False, id="plain"),
+ pytest.param("SELECT '{{ current_username() }}'", True,
id="expression"),
+ pytest.param("{% set a = 1 %}SELECT {{ a }}", True, id="statement"),
+ # A comment leaves no trace in a parsed template, but still has to be
+ # expanded away before the SQL is SQL.
+ pytest.param("SELECT 1 {# a comment #}", True, id="comment"),
+ # A whole query that is one macro lexes without a `data` token at all.
+ pytest.param("{{ dataset(1) }}", True, id="template_only"),
+ # Merely containing braces is not templating: the array literal opens
+ # like a template and is abandoned unterminated, and the JSON literal
is
+ # never even mistaken for one.
+ pytest.param("SELECT '{{1,2},{3,4}}'::int[]", False,
id="postgres_array"),
+ pytest.param("""SELECT '{"a": 1}'::json""", False, id="json_literal"),
+ # A real template alongside an array literal is still a template: the
+ # first construct closes before the lexer gives up on the second.
+ pytest.param(
+ "SELECT '{{ current_username() }}', '{{1,2},{3,4}}'::int[]",
+ True,
+ id="template_beside_array",
+ ),
+ ],
+)
+def test_has_template(sql: str, expected: bool) -> None:
Review Comment:
<!-- Bito Reply -->
The addition of the decorator is correct. As noted in the review, the
default feature-flag state is disabled, so the decorator is necessary to ensure
the test correctly exercises the template processing logic.
**tests/unit_tests/jinja_context_test.py**
```
@pytest.mark.parametrize(
"sql,expected",
[
pytest.param("SELECT 1", False, id="plain"),
pytest.param("SELECT '{{ current_username() }}'", True,
id="expression"),
pytest.param("{% set a = 1 %}SELECT {{ a }}", True, id="statement"),
# A comment leaves no trace in a parsed template, but still has to be
# expanded away before the SQL is SQL.
pytest.param("SELECT 1 {# a comment #}", True, id="comment"),
# A whole query that is one macro lexes without a `data` token at
all.
pytest.param("{{ dataset(1) }}", True, id="template_only"),
# Merely containing braces is not templating: the array literal opens
# like a template and is abandoned unterminated, and the JSON
literal is
# never even mistaken for one.
pytest.param("SELECT '{{1,2},{3,4}}'::int[]", False,
id="postgres_array"),
pytest.param("""SELECT '{"a": 1}'::json""", False,
id="json_literal"),
# A real template alongside an array literal is still a template: the
# first construct closes before the lexer gives up on the second.
pytest.param(
"SELECT '{{ current_username() }}', '{{1,2},{3,4}}'::int[]",
True,
id="template_beside_array",
),
],
)
def test_has_template(sql: str, expected: bool) -> None:
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]