示例#1
0
def test_schema_qualified_function_name(completer):
    text = 'SELECT custom.func'
    result = result_set(completer, text)
    assert result == set([
        function('func3()', -len('func')),
        function('set_returning_func()', -len('func'))
    ])
def test_user_function_name_completion_matches_anywhere(completer):
    result = result_set(completer, 'SELECT om')
    assert result == set([
        function('custom_fun()', -2),
        function('_custom_fun()', -2),
        function('custom_func1()', -2),
        function('custom_func2()', -2)
    ])
示例#3
0
def test_table_casing(completer, text):
    result = result_set(completer, text)
    assert result == set(cased_schemas + [
        table('users'),
        table('Orders'),
        table('"select"'),
        function('Func1()'),
        function('func2()')
    ])
示例#4
0
def test_aliases_with_casing(completer, text):
    result = result_set(completer, text)
    assert result == set(cased_schemas + [
        table('users u'),
        table('Orders O' if text == 'SELECT * FROM ' else 'Orders O2'),
        table('"select" s'),
        function('Func1() F'),
        function('func2() f')
    ])
示例#5
0
def test_table_aliases(completer, text):
    result = result_set(completer, text)
    assert result == set(testdata.schemas() + [
        table('users u'),
        table('orders o' if text == 'SELECT * FROM ' else 'orders o2'),
        table('"select" s'),
        function('func1() f'),
        function('func2() f')
    ])
def test_user_function_name_completion(completer):
    result = result_set(completer, 'SELECT cu')
    assert result == set([
        function('custom_fun()', -2),
        function('_custom_fun()', -2),
        function('custom_func1()', -2),
        function('custom_func2()', -2),
        keyword('CURRENT', -2),
    ])
def test_duplicate_table_aliases(completer, text):
    result = result_set(completer, text)
    assert result == set(testdata.schemas() + [
        table('orders o2'),
        table('users u'),
        table('"Users" U'),
        table('"select" s'),
        view('user_emails ue'),
        view('functions f'),
        function('_custom_fun() cf'),
        function('custom_fun() cf'),
        function('custom_func1() cf'),
        function('custom_func2() cf'),
        function('set_returning_func(x := , y := ) srf',
                 display='set_returning_func(x, y) srf'),
    ])
def test_builtin_function_name_completion(completer):
    result = result_set(completer, 'SELECT MA')
    assert result == set([
        function('MAX', -2),
        keyword('MAXEXTENTS', -2),
        keyword('MATERIALIZED VIEW', -2)
    ])
def test_duplicate_aliases_with_casing(completer, text):
    result = result_set(completer, text)
    assert result == set([
        schema('PUBLIC'),
        table('Orders O2'),
        table('Users U'),
        table('"Users" U'),
        table('"select" s'),
        view('User_Emails UE'),
        view('Functions F'),
        function('_custom_fun() cf'),
        function('Custom_Fun() CF'),
        function('Custom_Func1() CF'),
        function('custom_func2() cf'),
        function('set_returning_func(x := , y := ) srf',
                 display='set_returning_func(x, y) srf'),
    ])
示例#10
0
def test_all_schema_objects_with_aliases(completer):
    text = ('SELECT * FROM ')
    result = result_set(completer, text)
    assert result >= set(
        [table(x) for x in ('orders o', '"select" s', 'custom.shipments s')] +
        [function(x) for x in ('func2() f', 'custom.func3() f')])
示例#11
0
def test_all_schema_objects_with_casing(completer):
    text = 'SELECT * FROM '
    result = result_set(completer, text)
    assert result >= set(
        [table(x) for x in ('Orders', '"select"', 'CUSTOM.shipments')] +
        [function(x + '()') for x in ('func2', 'CUSTOM.func3')])
示例#12
0
def test_all_schema_objects(completer):
    text = ('SELECT * FROM ')
    result = result_set(completer, text)
    assert result >= set(
        [table(x) for x in ('orders', '"select"', 'custom.shipments')] +
        [function(x + '()') for x in ('func2', 'custom.func3')])
def test_drop_alter_function(completer, action):
    assert get_result(completer, action + ' FUNCTION set_ret') == [
        function('set_returning_func(x integer, y integer)', -len('set_ret'))
    ]
def test_list_functions_for_special(completer):
    result = result_set(completer, r'\df ')
    assert result == set([schema('PUBLIC')] +
                         [function(f) for f in cased_func_names])
testdata = MetaData(metadata)

cased_users_col_names = ['ID', 'PARENTID', 'Email', 'First_Name', 'last_name']
cased_users2_col_names = ['UserID', 'UserName']
cased_func_names = [
    'Custom_Fun', '_custom_fun', 'Custom_Func1', 'custom_func2',
    'set_returning_func'
]
cased_tbls = ['Users', 'Orders']
cased_views = ['User_Emails', 'Functions']
casing = (['SELECT', 'PUBLIC'] + cased_func_names + cased_tbls + cased_views +
          cased_users_col_names + cased_users2_col_names)
# Lists for use in assertions
cased_funcs = [
    function(f) for f in ('Custom_Fun()', '_custom_fun()', 'Custom_Func1()',
                          'custom_func2()')
] + [
    function('set_returning_func(x := , y := )',
             display='set_returning_func(x, y)')
]
cased_tbls = [table(t) for t in (cased_tbls + ['"Users"', '"select"'])]
cased_rels = [view(t) for t in cased_views] + cased_funcs + cased_tbls
cased_users_cols = [column(c) for c in cased_users_col_names]
aliased_rels = [
    table(t) for t in ('users u', '"Users" U', 'orders o', '"select" s')
] + [view('user_emails ue'), view('functions f')] + [
    function(f) for f in ('_custom_fun() cf', 'custom_fun() cf',
                          'custom_func1() cf', 'custom_func2() cf')
] + [
    function('set_returning_func(x := , y := ) srf',