File: reference_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 (73 lines) | stat: -rw-r--r-- 2,106 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""Test components for working with object and table references."""

import pytest

from sqlfluff.core.rules import reference


@pytest.mark.parametrize(
    "possible_references, targets, result",
    [
        # Empty list of references is always True.
        [[], [("abc",)], True],
        # Simple cases: one reference, one target.
        [[("agent1",)], [("agent1",)], True],
        [[("agent1",)], [("customer",)], False],
        # Multiple references. If any match, good.
        [[("bar",), ("user_id",)], [("bar",)], True],
        [[("foo",), ("user_id",)], [("bar",)], False],
        # Multiple targets. If any reference matches, good.
        [[("table1",)], [("table1",), ("table2",), ("table3",)], True],
        [[("tbl2",)], [("db", "sc", "tbl1")], False],
        [[("tbl2",)], [("db", "sc", "tbl2")], True],
        # Multi-part references and targets. If one tuple is shorter than
        # the other, checks for a suffix match.
        [
            [
                (
                    "rc",
                    "tbl1",
                )
            ],
            [("db", "sc", "tbl1")],
            False,
        ],
        [
            [
                (
                    "sc",
                    "tbl1",
                )
            ],
            [("db", "sc", "tbl1")],
            True,
        ],
        [
            [
                (
                    "cb",
                    "sc",
                    "tbl1",
                )
            ],
            [("db", "sc", "tbl1")],
            False,
        ],
        [
            [
                (
                    "db",
                    "sc",
                    "tbl1",
                )
            ],
            [("db", "sc", "tbl1")],
            True,
        ],
        [[("public", "agent1")], [("agent1",)], True],
        [[("public", "agent1")], [("public",)], False],
    ],
)
def test_object_ref_matches_table(possible_references, targets, result):
    """Test object_ref_matches_table()."""
    assert reference.object_ref_matches_table(possible_references, targets) == result