<s> '''<STR_LIT>''' <EOL> from datetime import datetime <EOL> from itertools import chain <EOL> from stdnet import getdb <EOL> from stdnet . utils import test , populate , zip <EOL> from examples . models import Calendar , DateValue , Collection , Group <EOL> class ZsetData ( test . DataGenerator ) : <EOL> def generate ( self ) : <EOL> self . dates = self . populate ( '<STR_LIT:date>' ) <EOL> self . values = self . populate ( '<STR_LIT:string>' , min_len = <NUM_LIT:10> , max_len = <NUM_LIT> ) <EOL> class TestSetField ( test . TestCase ) : <EOL> models = ( Collection , Group ) <EOL> def test_simple ( self ) : <EOL> m = yield self . session ( ) . add ( self . model ( ) ) <EOL> yield m . numbers . add ( <NUM_LIT:1> ) <EOL> yield m . numbers . update ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ) ) <EOL> yield self . async . assertEqual ( m . numbers . size ( ) , <NUM_LIT:5> ) <EOL> class TestOrderedSet ( test . TestCase ) : <EOL> multipledb = '<STR_LIT>' <EOL> models = ( Calendar , DateValue ) <EOL> data_cls = ZsetData <EOL> def fill ( self , update = False ) : <EOL> session = self . session ( ) <EOL> c = yield session . add ( Calendar ( name = self . data . random_string ( ) ) ) <EOL> with session . begin ( ) as t : <EOL> for dt , value in zip ( self . data . dates , self . data . values ) : <EOL> t . add ( DateValue ( dt = dt , value = value ) ) <EOL> yield t . on_result <EOL> items = t . saved [ DateValue . _meta ] <EOL> with session . begin ( ) as t : <EOL> if update : <EOL> c . data . update ( items ) <EOL> else : <EOL> for value in items : <EOL> c . data . add ( value ) <EOL> yield t . on_result <EOL> yield c <EOL> def test_add ( self ) : <EOL> return self . fill ( ) <EOL> def test_update ( self ) : <EOL> return self . fill ( True ) <EOL> def test_order ( self ) : <EOL> c = yield self . fill ( ) <EOL> yield self . async . assertEqual ( c . data . size ( ) , self . data . size ) <EOL> dprec = None <EOL> events = yield c . data . items ( ) <EOL> for event in events : <EOL> if dprec : <EOL> self . assertTrue ( event . dt >= dprec ) <EOL> dprec = event . dt <EOL> def test_rank ( self ) : <EOL> c = yield self . fill ( ) <EOL> data = c . data <EOL> vals = yield data . items ( ) <EOL> self . assertEqual ( vals , data . cache . cache ) <EOL> data . cache . clear ( ) <EOL> self . assertEqual ( data . cache . cache , None ) <EOL> ranks = [ ] <EOL> for v in vals : <EOL> ranks . append ( data . rank ( v ) ) <EOL> ranks = yield self . multi_async ( ranks ) </s>
