<s> from __future__ import absolute_import , unicode_literals <EOL> import pickle <EOL> from heapq import heappush <EOL> from time import time <EOL> from kombu . clocks import LamportClock , timetuple <EOL> from . case import Mock , Case <EOL> class test_LamportClock ( Case ) : <EOL> def test_clocks ( self ) : <EOL> c1 = LamportClock ( ) <EOL> c2 = LamportClock ( ) <EOL> c1 . forward ( ) <EOL> c2 . forward ( ) <EOL> c1 . forward ( ) <EOL> c1 . forward ( ) <EOL> c2 . adjust ( c1 . value ) <EOL> self . assertEqual ( c2 . value , c1 . value + <NUM_LIT:1> ) <EOL> self . assertTrue ( repr ( c1 ) ) <EOL> c2_val = c2 . value <EOL> c2 . forward ( ) <EOL> c2 . forward ( ) <EOL> c2 . adjust ( c1 . value ) <EOL> self . assertEqual ( c2 . value , c2_val + <NUM_LIT:2> + <NUM_LIT:1> ) <EOL> c1 . adjust ( c2 . value ) <EOL> self . assertEqual ( c1 . value , c2 . value + <NUM_LIT:1> ) <EOL> def test_sort ( self ) : <EOL> c = LamportClock ( ) <EOL> pid1 = '<STR_LIT>' <EOL> pid2 = '<STR_LIT>' <EOL> events = [ ] <EOL> m1 = ( c . forward ( ) , pid1 ) <EOL> heappush ( events , m1 ) <EOL> m2 = ( c . forward ( ) , pid2 ) <EOL> heappush ( events , m2 ) <EOL> m3 = ( c . forward ( ) , pid1 ) <EOL> heappush ( events , m3 ) <EOL> m4 = ( <NUM_LIT:30> , pid1 ) <EOL> heappush ( events , m4 ) <EOL> m5 = ( <NUM_LIT:30> , pid2 ) <EOL> heappush ( events , m5 ) <EOL> self . assertEqual ( str ( c ) , str ( c . value ) ) <EOL> self . assertEqual ( c . sort_heap ( events ) , m1 ) <EOL> self . assertEqual ( c . sort_heap ( [ m4 , m5 ] ) , m4 ) <EOL> self . assertEqual ( c . sort_heap ( [ m4 , m5 , m1 ] ) , m4 ) <EOL> class test_timetuple ( Case ) : <EOL> def test_repr ( self ) : <EOL> x = timetuple ( <NUM_LIT> , time ( ) , '<STR_LIT:id>' , Mock ( ) ) <EOL> self . assertTrue ( repr ( x ) ) <EOL> def test_pickleable ( self ) : <EOL> x = timetuple ( <NUM_LIT> , time ( ) , '<STR_LIT:id>' , '<STR_LIT>' ) <EOL> self . assertEqual ( pickle . loads ( pickle . dumps ( x ) ) , tuple ( x ) ) <EOL> def test_order ( self ) : <EOL> t1 = time ( ) <EOL> t2 = time ( ) + <NUM_LIT> <EOL> a = timetuple ( <NUM_LIT> , t1 , '<STR_LIT:A>' , '<STR_LIT>' ) <EOL> b = timetuple ( <NUM_LIT> , t1 , '<STR_LIT:A>' , '<STR_LIT>' ) <EOL> self . assertTrue ( a . __getnewargs__ ( ) ) <EOL> self . assertEqual ( a . clock , <NUM_LIT> ) <EOL> self . assertEqual ( a . timestamp , t1 ) <EOL> self . assertEqual ( a . id , '<STR_LIT:A>' ) <EOL> self . assertEqual ( a . obj , '<STR_LIT>' ) <EOL> self . assertTrue ( <EOL> a <= b , <EOL> ) <EOL> self . assertTrue ( <EOL> b >= a , <EOL> ) <EOL> self . assertEqual ( <EOL> timetuple ( <NUM_LIT> , time ( ) , '<STR_LIT:A>' , '<STR_LIT>' ) . __lt__ ( tuple ( ) ) , <EOL> NotImplemented , <EOL> ) <EOL> self . assertGreater ( <EOL> timetuple ( <NUM_LIT> , t2 , '<STR_LIT:A>' , '<STR_LIT>' ) , <EOL> timetuple ( <NUM_LIT> , t1 , '<STR_LIT:A>' , '<STR_LIT>' ) , <EOL> ) <EOL> self . assertGreater ( <EOL> timetuple ( <NUM_LIT> , t1 , '<STR_LIT:B>' , '<STR_LIT>' ) , <EOL> timetuple ( <NUM_LIT> , t1 , '<STR_LIT:A>' , '<STR_LIT>' ) , <EOL> ) <EOL> self . assertGreater ( <EOL> timetuple ( None , t2 , '<STR_LIT:B>' , '<STR_LIT>' ) , <EOL> timetuple ( None , t1 , '<STR_LIT:A>' , '<STR_LIT>' ) , <EOL> ) </s>
