def test_tokenizer_filters5(): query = ''' query Sample { field1 [((* == 4) and (* <= 3)) or (* != 9)] } ''' assert tuple(tokenize(query)) == ( Toks.RootQueryToken(query_model='Sample'), Toks.AttributeToken(attribute_name='field1'), Toks.FilterStartToken(), Toks.FilterOpenParanToken(), Toks.FilterOpenParanToken(), Toks.FilterBoolToken(sel='*', op='==', val=4), Toks.FilterCloseParanToken(), Toks.FilterBinaryLogicToken(logic_op='and'), Toks.FilterOpenParanToken(), Toks.FilterBoolToken(sel='*', op='<=', val=3), Toks.FilterCloseParanToken(), Toks.FilterCloseParanToken(), Toks.FilterBinaryLogicToken(logic_op='or'), Toks.FilterOpenParanToken(), Toks.FilterBoolToken(sel='*', op='!=', val=9), Toks.FilterCloseParanToken(), Toks.FilterEndToken(), Toks.CloseObjectToken(), )
def test_tokenizer_parser_test_1(): query = ''' query Sample { id tube { name type [any in ['a', 'b'] or all != 'c'] } date [((* < '3/9/2017') or * == '3/3/2017') and ((* > '3/10/2017'))] } ''' assert tuple(tokenize(query)) == ( Toks.RootQueryToken(query_model='Sample'), Toks.AttributeToken(attribute_name='id'), Toks.OpenObjectToken(rel='tube'), Toks.AttributeToken(attribute_name='name'), Toks.AttributeToken(attribute_name='type'), Toks.FilterStartToken(), Toks.FilterBoolToken(sel='any', op='in', val=['a', 'b']), Toks.FilterBinaryLogicToken(logic_op='or'), Toks.FilterBoolToken(sel='all', op='!=', val='c'), Toks.FilterEndToken(), Toks.CloseObjectToken(), Toks.AttributeToken(attribute_name='date'), Toks.FilterStartToken(), Toks.FilterOpenParanToken(), Toks.FilterOpenParanToken(), Toks.FilterBoolToken(sel='*', op='<', val='3/9/2017'), Toks.FilterCloseParanToken(), Toks.FilterBinaryLogicToken(logic_op='or'), Toks.FilterBoolToken(sel='*', op='==', val='3/3/2017'), Toks.FilterCloseParanToken(), Toks.FilterBinaryLogicToken(logic_op='and'), Toks.FilterOpenParanToken(), Toks.FilterOpenParanToken(), Toks.FilterBoolToken(sel='*', op='>', val='3/10/2017'), Toks.FilterCloseParanToken(), Toks.FilterCloseParanToken(), Toks.FilterEndToken(), Toks.CloseObjectToken(), )
Toks.AttributeToken(attribute_name='id'), Toks.OpenObjectToken(rel='tube'), Toks.AttributeToken(attribute_name='name'), Toks.AttributeToken(attribute_name='type'), Toks.FilterStartToken(), Toks.FilterBoolToken(sel='any', op='in', val=['a', 'b']), Toks.FilterBinaryLogicToken(logic_op='or'), Toks.FilterBoolToken(sel='all', op='!=', val='c'), Toks.FilterEndToken(), Toks.CloseObjectToken(), Toks.AttributeToken(attribute_name='date'), Toks.FilterStartToken(), Toks.FilterOpenParanToken(), Toks.FilterOpenParanToken(), Toks.FilterBoolToken(sel='*', op='<', val='3/9/2017'), Toks.FilterCloseParanToken(), Toks.FilterBinaryLogicToken(logic_op='or'), Toks.FilterBoolToken(sel='*', op='==', val='3/3/2017'), Toks.FilterCloseParanToken(), Toks.FilterBinaryLogicToken(logic_op='and'), Toks.FilterOpenParanToken(), Toks.FilterOpenParanToken(), Toks.FilterBoolToken(sel='*', op='>', val='3/10/2017'), Toks.FilterCloseParanToken(), Toks.FilterCloseParanToken(), Toks.FilterEndToken(), Toks.CloseObjectToken(), )) test_token_ast_1 = RootNode(mock_registry, 'Sample', children=[ AttributeNode(mock_registry, Sample, 'id'),