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)
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)
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()
def test_parser_params(value, params): pp = Parser(value) assert set(params) == set(pp.params)
def test_words(value, exp): res = Parser(value).parse() assert repr(res) == exp assert res.name == 'stuff'