#NEWLINE# def test_scalar_query( self ) : #NEWLINE# #INDENT# data = [ ( 't1' , 1 ) , ( 't1' , 2 ) , ( 't1' , 3 ) , ( 't2' , 10 ) , ( 't2' , 11 ) , ( 't2' , 12 ) , ( 't3' , 0 ) ] #NEWLINE# for ( stat_type , value ) in data : #NEWLINE# #INDENT# Stat . create ( stat_type = stat_type , value = value ) #NEWLINE# #UNINDENT# stat_objects = sorted ( ( stat for stat in Stat . all ( ) ) , key = ( lambda stat : stat . key ) ) #NEWLINE# self . assertEquivalent ( [ stat . _data for stat in stat_objects ] , [ { #NEWLINE# #INDENT# 'key' : 1 , #NEWLINE# 'stat_type' : 't1' , #NEWLINE# 'value' : 1 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'key' : 2 , #NEWLINE# 'stat_type' : 't1' , #NEWLINE# 'value' : 2 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'key' : 3 , #NEWLINE# 'stat_type' : 't1' , #NEWLINE# 'value' : 3 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'key' : 4 , #NEWLINE# 'stat_type' : 't2' , #NEWLINE# 'value' : 10 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'key' : 5 , #NEWLINE# 'stat_type' : 't2' , #NEWLINE# 'value' : 11 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'key' : 6 , #NEWLINE# 'stat_type' : 't2' , #NEWLINE# 'value' : 12 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'key' : 7 , #NEWLINE# 'stat_type' : 't3' , #NEWLINE# 'value' : 0 , #NEWLINE# #UNINDENT# } ] ) #NEWLINE# def assertStats( expr , expected ) : #NEWLINE# #INDENT# stats = Stat . query ( expr ) #NEWLINE# self . assertEquivalent ( sorted ( ( stat . key for stat in stats ) ) , sorted ( expected ) ) #NEWLINE# #UNINDENT# assertStats ( ( Stat . value <= 3 ) , [ 1 , 2 , 3 , 7 ] ) #NEWLINE# assertStats ( ( Stat . value >= 10 ) , [ 4 , 5 , 6 ] ) #NEWLINE# assertStats ( ( Stat . value < 3 ) , [ 1 , 2 , 7 ] ) #NEWLINE# assertStats ( ( Stat . value > 10 ) , [ 5 , 6 ] ) #NEWLINE# assertStats ( ( Stat . value == 3 ) , [ 3 ] ) #NEWLINE# assertStats ( ( Stat . value >= 13 ) , [ ] ) #NEWLINE# assertStats ( ( ( Stat . value <= 2 ) | ( Stat . key >= 7 ) ) , [ 1 , 2 , 7 ] ) #NEWLINE# assertStats ( ( ( ( Stat . value <= 2 ) & ( Stat . key >= 7 ) ) | ( Stat . value >= 11 ) ) , [ 5 , 6 , 7 ] ) #NEWLINE# assertStats ( ( ( ( Stat . value <= 2 ) | ( Stat . key >= 7 ) ) & ( Stat . stat_type == 't1' ) ) , [ 1 , 2 ] ) #NEWLINE# assertStats ( Stat . value . between ( 2 , 11 ) , [ 2 , 3 , 4 , 5 ] ) #NEWLINE# assertStats ( Stat . value . between ( 4 , 12 ) , [ 4 , 5 , 6 ] )