<s> '''<STR_LIT>''' <EOL> import time <EOL> import ujson <EOL> from chai import Chai <EOL> from torus . web import Web <EOL> from torus . configuration import Configuration <EOL> SCHEMAS = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:host>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT> <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> } <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:host>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } , <EOL> } <EOL> } <EOL> } <EOL> AGGREGATES = ( <EOL> ( '<STR_LIT:foo>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:foo>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) <EOL> config = Configuration ( ) <EOL> for name , spec in SCHEMAS . iteritems ( ) : <EOL> config . load_schema ( name , spec ) <EOL> config . load_aggregate ( AGGREGATES ) <EOL> config . _transforms [ '<STR_LIT>' ] = lambda dct , duration : len ( dct ) <EOL> config . _macros [ '<STR_LIT>' ] = { <EOL> '<STR_LIT>' : lambda handle , key : handle . hlen ( key ) , <EOL> '<STR_LIT>' : lambda data : sum ( data . values ( ) ) , <EOL> '<STR_LIT>' : lambda data : data , <EOL> '<STR_LIT>' : lambda rows : sum ( rows ) , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> for schema in config . _schemas : <EOL> schema . timeseries . delete ( '<STR_LIT:foo>' ) <EOL> schema . timeseries . delete ( '<STR_LIT>' ) <EOL> schema . timeseries . delete ( '<STR_LIT>' ) <EOL> schema . timeseries . delete ( '<STR_LIT>' ) <EOL> schema . timeseries . delete ( '<STR_LIT>' ) <EOL> schema . timeseries . delete ( '<STR_LIT>' ) <EOL> t = time . time ( ) - <NUM_LIT> <EOL> for x in xrange ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:30> ) : <EOL> config . process ( '<STR_LIT>' , x / <NUM_LIT:15> , t + x ) <EOL> config . process ( '<STR_LIT>' , x / <NUM_LIT:15> , t + x ) <EOL> config . process ( '<STR_LIT>' , x / <NUM_LIT:15> , t + x ) <EOL> web = Web ( configuration = config ) <EOL> class WebTest ( Chai ) : <EOL> def setUp ( self ) : <EOL> super ( WebTest , self ) . setUp ( ) <EOL> def _request ( self , request ) : <EOL> '''<STR_LIT>''' <EOL> result = web . _series ( request ) <EOL> ujson . dumps ( result , double_precision = <NUM_LIT:4> ) <EOL> return result <EOL> def test_series ( self ) : <EOL> request = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> } <EOL> result = self . _request ( request ) <EOL> counts = { } <EOL> for row in result : <EOL> counts [ row [ '<STR_LIT>' ] ] = row [ '<STR_LIT>' ] . values ( ) [ - <NUM_LIT:1> ] <EOL> dog = counts [ '<STR_LIT>' ] <EOL> assert_not_equals ( <NUM_LIT:0> , dog ) <EOL> assert_equals ( dog , counts [ '<STR_LIT>' ] ) <EOL> assert_equals ( dog , counts [ '<STR_LIT>' ] ) <EOL> assert_equals ( <NUM_LIT:2> * dog , counts [ '<STR_LIT>' ] ) <EOL> assert_equals ( <NUM_LIT:3> * dog , counts [ '<STR_LIT>' ] ) <EOL> assert_not_equals ( counts [ '<STR_LIT>' ] , counts [ '<STR_LIT>' ] ) <EOL> assert_not_equals ( counts [ '<STR_LIT>' ] , counts [ '<STR_LIT>' ] ) <EOL> request = { <EOL> '<STR_LIT>' : [ '<STR_LIT:foo>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } <EOL> result = self . _request ( request ) <EOL> assert_equals ( '<STR_LIT>' , result [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> request = { <EOL> '<STR_LIT>' : [ '<STR_LIT:foo>' ] , <EOL> '<STR_LIT:start>' : [ '<STR_LIT>' ] <EOL> } <EOL> result = self . _request ( request ) <EOL> request = { <EOL> '<STR_LIT>' : [ '<STR_LIT:foo>' ] , <EOL> '<STR_LIT:start>' : [ '<STR_LIT>' ] <EOL> } <EOL> result = self . _request ( request ) <EOL> def test_series_with_stat_lists ( self ) : <EOL> request = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> } <EOL> result = self . _request ( request ) <EOL> counts = { } <EOL> for row in result : <EOL> counts [ row [ '<STR_LIT>' ] ] = row [ '<STR_LIT>' ] . values ( ) [ - <NUM_LIT:1> ] <EOL> assert_not_equals ( <NUM_LIT:0> , counts [ '<STR_LIT>' ] ) <EOL> assert_equals ( counts [ '<STR_LIT>' ] , <EOL> counts [ '<STR_LIT>' ] + counts [ '<STR_LIT>' ] ) <EOL> request = { <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT:true>' ] , <EOL> } <EOL> result = self . _request ( request ) <EOL> counts = { } <EOL> for row in result : <EOL> counts [ row [ '<STR_LIT>' ] ] = row [ '<STR_LIT>' ] . values ( ) [ - <NUM_LIT:1> ] <EOL> uniques = filter ( lambda row : row [ '<STR_LIT>' ] == '<STR_LIT>' , result ) <EOL> assert_equals ( <NUM_LIT:3> , len ( uniques ) ) <EOL> assert_equals ( <NUM_LIT:1> , len ( uniques [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) ) <EOL> assert_equals ( <NUM_LIT:1> , len ( uniques [ <NUM_LIT:1> ] [ '<STR_LIT>' ] ) ) <EOL> assert_equals ( <NUM_LIT:1> , len ( uniques [ <NUM_LIT:2> ] [ '<STR_LIT>' ] ) ) <EOL> assert_not_equals ( <NUM_LIT:0> , counts [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> assert_equals ( counts [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , <EOL> counts [ '<STR_LIT>' ] [ <NUM_LIT:0> ] + counts [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> assert_equals ( counts [ '<STR_LIT>' ] , <NUM_LIT> ) <EOL> assert_equals ( counts [ '<STR_LIT>' ] , <EOL> counts [ '<STR_LIT>' ] ) <EOL> assert_equals ( counts [ '<STR_LIT>' ] , <EOL> counts [ '<STR_LIT>' ] ) <EOL> def test_series_with_macros ( self ) : <EOL> request = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> } <EOL> result = self . _request ( request ) <EOL> counts = { } <EOL> for row in result : <EOL> counts [ row [ '<STR_LIT>' ] ] = row [ '<STR_LIT>' ] . values ( ) [ - <NUM_LIT:1> ] <EOL> assert_not_equals ( <NUM_LIT:0> , counts [ '<STR_LIT>' ] ) <EOL> assert_equals ( counts [ '<STR_LIT>' ] , <EOL> counts [ '<STR_LIT>' ] + counts [ '<STR_LIT>' ] ) </s>
