Esempio n. 1
0
def test_condition(value, exp):
    res = Parser(value).parse()
    assert repr(res) == exp
    assert res.value == '5'
    assert res.fullname == 'a'
    assert res.operator == '>'
    assert isinstance(res, Condition)
Esempio n. 2
0
def test_parser_conditions(value, conditions):
    pp = Parser(value)
    if not isinstance(conditions, list):
        assert repr(pp.conditions) == conditions
        assert isinstance(pp.conditions, Condition)
    else:
        assert isinstance(pp.conditions, list)
        reps = [repr(c) for c in pp.conditions]
        assert reps == conditions
        assert isinstance(pp.conditions[0], Condition)
Esempio n. 3
0
def parse(value, base='sqla'):
    ''' Convenience function to returned a parsed expression

    Returns a parsed string using one of the available Parsers
    in `boolean_parser`.  The ``base`` keyword argument can be used
    to select which ``Parser`` to use.  The availble bases are: "base",
    "sqla".  The default base is "sqla" which uses the :py:class:`boolean_parser.parsers.sqla.SQLAParser`.

    Parameters:
        value: str
            The string expression to evaluate and parse
        base: str:
            The base Parser to use.  Default is sqlalchemy parser.

    Returns:
        A parsed string using a :ref:`api-parsers` object.
    '''
    if base == 'base':
        return Parser(value).parse()
    elif base == 'sqla':
        return SQLAParser(value).parse()
    else:
        return Parser(value).parse()
Esempio n. 4
0
def test_parser_params(value, params):
    pp = Parser(value)
    assert set(params) == set(pp.params)
Esempio n. 5
0
def test_words(value, exp):
    res = Parser(value).parse()
    assert repr(res) == exp
    assert res.name == 'stuff'