File: std_LT02_LT11_combo_test.py

package info (click to toggle)
sqlfluff 3.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,000 kB
  • sloc: python: 106,131; sql: 34,188; makefile: 52; sh: 8
file content (46 lines) | stat: -rw-r--r-- 1,272 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""Tests the combination of LT02 and LT11.

LT02: Indentation not consistent with previous lines
LT11: Set operators should be surrounded by newlines

Auto fix of LT11 does not insert correct indentation but just Newlines. It relies on
LT02 to sort out the indentation later. This is what is getting tested here.
"""

import sqlfluff


def test__rules__std_LT02_LT11_union_all_in_subquery_lint():
    """Verify a that LT11 reports lint errors in subqueries."""
    sql = (
        "SELECT * FROM (\n"
        "    SELECT 'g' UNION ALL\n"
        "    SELECT 'h'\n"
        "    UNION ALL SELECT 'j'\n"
        ")\n"
    )
    result = sqlfluff.lint(sql)

    assert "LT11" in [r["code"] for r in result]


def test__rules__std_LT02_LT11_union_all_in_subquery_fix():
    """Verify combination of rules LT02 and LT11 produces a correct indentation."""
    sql = (
        "SELECT c FROM (\n"
        "    SELECT 'g' UNION ALL\n"
        "    SELECT 'h'\n"
        "    UNION ALL SELECT 'j'\n"
        ")\n"
    )
    fixed_sql = (
        "SELECT c FROM (\n"
        "    SELECT 'g'\n"
        "    UNION ALL\n"
        "    SELECT 'h'\n"
        "    UNION ALL\n"
        "    SELECT 'j'\n"
        ")\n"
    )
    result = sqlfluff.fix(sql)
    assert result == fixed_sql