<s> try : <EOL> import unittest2 as unittest <EOL> except ImportError : <EOL> import unittest <EOL> from cassandra import marshal <EOL> from cassandra import util <EOL> import calendar <EOL> import datetime <EOL> import time <EOL> import uuid <EOL> class TimeUtilTest ( unittest . TestCase ) : <EOL> def test_datetime_from_timestamp ( self ) : <EOL> self . assertEqual ( util . datetime_from_timestamp ( <NUM_LIT:0> ) , datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> self . assertEqual ( util . datetime_from_timestamp ( - <NUM_LIT> ) , datetime . datetime ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> self . assertEqual ( util . datetime_from_timestamp ( - <NUM_LIT> ) , datetime . datetime ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:1> ) ) <EOL> self . assertEqual ( util . datetime_from_timestamp ( <NUM_LIT> ) , datetime . datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> self . assertEqual ( util . datetime_from_timestamp ( <NUM_LIT> ) , datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> ) ) <EOL> self . assertEqual ( util . datetime_from_timestamp ( <NUM_LIT> ) , datetime . datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT> ) ) <EOL> def test_times_from_uuid1 ( self ) : <EOL> node = uuid . getnode ( ) <EOL> now = time . time ( ) <EOL> u = uuid . uuid1 ( node , <NUM_LIT:0> ) <EOL> t = util . unix_time_from_uuid1 ( u ) <EOL> self . assertAlmostEqual ( now , t , <NUM_LIT:2> ) <EOL> dt = util . datetime_from_uuid1 ( u ) <EOL> t = calendar . timegm ( dt . timetuple ( ) ) + dt . microsecond / <NUM_LIT> <EOL> self . assertAlmostEqual ( now , t , <NUM_LIT:2> ) <EOL> def test_uuid_from_time ( self ) : <EOL> t = time . time ( ) <EOL> seq = <NUM_LIT> <EOL> node = uuid . getnode ( ) <EOL> u = util . uuid_from_time ( t , node , seq ) <EOL> self . assertAlmostEqual ( util . unix_time_from_uuid1 ( u ) , t , <NUM_LIT:4> ) <EOL> self . assertEqual ( u . node , node ) <EOL> self . assertEqual ( u . clock_seq , seq ) <EOL> u1 = util . uuid_from_time ( t , clock_seq = seq ) <EOL> u2 = util . uuid_from_time ( t , clock_seq = seq ) <EOL> self . assertAlmostEqual ( util . unix_time_from_uuid1 ( u1 ) , t , <NUM_LIT:4> ) <EOL> self . assertAlmostEqual ( util . unix_time_from_uuid1 ( u2 ) , t , <NUM_LIT:4> ) <EOL> self . assertEqual ( u . clock_seq , seq ) <EOL> self . assertNotEqual ( u1 . node , u2 . node ) <EOL> u1 = util . uuid_from_time ( t , node = node ) <EOL> u2 = util . uuid_from_time ( t , node = node ) <EOL> self . assertAlmostEqual ( util . unix_time_from_uuid1 ( u1 ) , t , <NUM_LIT:4> ) <EOL> self . assertAlmostEqual ( util . unix_time_from_uuid1 ( u2 ) , t , <NUM_LIT:4> ) <EOL> self . assertEqual ( u . node , node ) <EOL> self . assertNotEqual ( u1 . clock_seq , u2 . clock_seq ) <EOL> with self . assertRaises ( ValueError ) : <EOL> u = util . uuid_from_time ( t , node = <NUM_LIT:2> ** <NUM_LIT> ) <EOL> with self . assertRaises ( ValueError ) : <EOL> u = util . uuid_from_time ( t , clock_seq = <NUM_LIT> ) <EOL> dt = util . datetime_from_timestamp ( t ) <EOL> u = util . uuid_from_time ( dt , node , seq ) <EOL> self . assertAlmostEqual ( util . unix_time_from_uuid1 ( u ) , t , <NUM_LIT:4> ) <EOL> self . assertEqual ( u . node , node ) <EOL> self . assertEqual ( u . clock_seq , seq ) <EOL> def test_min_uuid ( self ) : <EOL> u = util . min_uuid_from_time ( <NUM_LIT:0> ) <EOL> for i in range ( <NUM_LIT:8> , <NUM_LIT:16> ) : <EOL> self . assertEqual ( marshal . int8_unpack ( u . bytes [ i : i + <NUM_LIT:1> ] ) , - <NUM_LIT> ) <EOL> def test_max_uuid ( self ) : <EOL> u = util . max_uuid_from_time ( <NUM_LIT:0> ) <EOL> self . assertEqual ( marshal . int8_unpack ( u . bytes [ <NUM_LIT:8> : <NUM_LIT:9> ] ) , - <NUM_LIT> ) <EOL> for i in range ( <NUM_LIT:9> , <NUM_LIT:16> ) : <EOL> self . assertEqual ( marshal . int8_unpack ( u . bytes [ i : i + <NUM_LIT:1> ] ) , <NUM_LIT> ) </s>
