#NEWLINE# @ mock . patch ( 'logcabin.event.datetime' ) #NEWLINE# def test_log( self , mock_datetime ) : #NEWLINE# #INDENT# now = datetime ( 2013 , 1 , 1 , 2 , 34 , 56 , 789012 ) #NEWLINE# t_now = int ( time . mktime ( now . timetuple ( ) ) ) #NEWLINE# mock_datetime . utcnow . side_effect = ( lambda : now ) #NEWLINE# port = random . randint ( 1024 , 65535 ) #NEWLINE# received = [ ] #NEWLINE# def handle( socket , address ) : #NEWLINE# #INDENT# ( length , ) = struct . unpack ( '!L' , socket . recv ( 4 ) ) #NEWLINE# d = socket . recv ( length ) #NEWLINE# received . append ( pickle . loads ( d ) ) #NEWLINE# #UNINDENT# server = gevent . server . StreamServer ( ( '' , port ) , handle ) #NEWLINE# server . start ( ) #NEWLINE# self . create ( { #NEWLINE# #INDENT# 'port' : port , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . input . put ( Event ( metric = 'a.b.c' , stats = { #NEWLINE# #INDENT# 'mean' : 1.5 , #NEWLINE# 'min' : 1.0 , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# self . waitForEmpty ( ) #NEWLINE# self . i . stop ( ) #NEWLINE# self . assertEquals ( 0 , self . input . qsize ( ) ) #NEWLINE# server . stop ( ) #NEWLINE# self . assertEquals ( 1 , len ( received ) ) #NEWLINE# self . assertEquals ( [ ( 'a.b.c.min' , ( t_now , 1.0 ) ) , ( 'a.b.c.mean' , ( t_now , 1.5 ) ) ] , received [ 0 ] )