Ejemplo n.º 1
0
def test_2_statements_2nd_current():
    suggestions = suggest_type('select * from a; select * from ',
                               'select * from a; select * from ')
    assert set(suggestions) == set([
        FromClauseItem(schema=None),
        Schema(),
    ])

    suggestions = suggest_type('select * from a; select  from b',
                               'select * from a; select ')
    assert set(suggestions) == set([
        Column(table_refs=((None, 'b', None, False),)),
        Function(schema=None),
        Keyword()
    ])

    # Should work even if first statement is invalid
    suggestions = suggest_type('select * from; select * from ',
                               'select * from; select * from ')
    assert set(suggestions) == set([
        FromClauseItem(schema=None),
        Schema(),
    ])
Ejemplo n.º 2
0
def cols_etc(table, schema=None, alias=None, is_function=False, parent=None):
    return set([
        Column(table_refs=((schema, table, alias, is_function), )),
        Function(schema=parent),
        Keyword()
    ])
Ejemplo n.º 3
0
@pytest.mark.parametrize('text', [
    'SELECT * FROM foo where created > now() - ',
    'select * from foo where bar ',
])
def test_suggest_where_keyword(text):
    # https://github.com/dbcli/mycli/issues/135
    suggestions = suggest_type(text, text)
    assert set(suggestions) == cols_etc('foo')


@pytest.mark.parametrize(
    'text, before, expected',
    [('\\ns abc SELECT ', 'SELECT ',
      [Column(table_refs=()),
       Function(schema=None),
       Keyword()]), ('\\ns abc SELECT foo ', 'SELECT foo ', (Keyword(), )),
     ('\\ns abc SELECT t1. FROM tabl1 t1', 'SELECT t1.', [
         Table(schema='t1'),
         View(schema='t1'),
         Column(table_refs=((None, 'tabl1', 't1', False), )),
         Function(schema='t1')
     ])])
def test_named_query_completion(text, before, expected):
    suggestions = suggest_type(text, before)
    assert set(expected) == set(suggestions)


def test_select_suggests_fields_from_function():
    suggestions = suggest_type('SELECT  FROM func()', 'SELECT ')
    assert set(suggestions) == cols_etc('func', is_function=True)
Ejemplo n.º 4
0
def cols_etc(table, schema=None, alias=None, is_function=False, parent=None):
    return set([
        Column(table_refs=(TableReference(schema, table, alias, is_function),),
               qualifiable=True),
        Function(schema=parent),
        Keyword()])
Ejemplo n.º 5
0
    'select * from foo where bar ',
])
def test_suggest_where_keyword(text):
    # https://github.com/dbcli/mycli/issues/135
    suggestions = suggest_type(text, text)
    assert set(suggestions) == set([
        Column(tables=((None, 'foo', None, False), )),
        Function(schema=None),
        Keyword(),
    ])


@pytest.mark.parametrize(
    'text, before, expected',
    [('\\ns abc SELECT ', 'SELECT ',
      [Column(tables=()), Function(schema=None),
       Keyword()]), ('\\ns abc SELECT foo ', 'SELECT foo ', (Keyword(), )),
     ('\\ns abc SELECT t1. FROM tabl1 t1', 'SELECT t1.', [
         Table(schema='t1'),
         View(schema='t1'),
         Column(tables=((None, 'tabl1', 't1', False), )),
         Function(schema='t1')
     ])])
def test_named_query_completion(text, before, expected):
    suggestions = suggest_type(text, before)
    assert set(expected) == set(suggestions)


def test_select_suggests_fields_from_function():
    suggestions = suggest_type('SELECT  FROM func()', 'SELECT ')
    assert set(suggestions) == set([
Ejemplo n.º 6
0
def test_df_suggests_schema_or_function():
    suggestions = suggest_type("\\df xxx", "\\df xxx")
    assert set(suggestions) == set([Function(schema=None, usage="special"), Schema()])

    suggestions = suggest_type("\\df myschema.xxx", "\\df myschema.xxx")
    assert suggestions == (Function(schema="myschema", usage="special"),)
Ejemplo n.º 7
0
)
def test_suggest_where_keyword(text):
    # https://github.com/dbcli/mycli/issues/135
    suggestions = suggest_type(text, text)
    assert set(suggestions) == cols_etc("foo", last_keyword="WHERE")


@pytest.mark.parametrize(
    "text, before, expected",
    [
        (
            "\\ns abc SELECT ",
            "SELECT ",
            [
                Column(table_refs=(), qualifiable=True),
                Function(schema=None),
                Keyword("SELECT"),
            ],
        ),
        ("\\ns abc SELECT foo ", "SELECT foo ", (Keyword(), )),
        (
            "\\ns abc SELECT t1. FROM tabl1 t1",
            "SELECT t1.",
            [
                Table(schema="t1"),
                View(schema="t1"),
                Column(table_refs=((None, "tabl1", "t1", False), )),
                Function(schema="t1"),
            ],
        ),
    ],