def test_is_timeseries_supported(self): v = (2, 7, 11) self.assertEqual(True, is_timeseries_supported(v)) v = (2, 7, 12) self.assertEqual(True, is_timeseries_supported(v)) v = (3, 3, 6) self.assertEqual(False, is_timeseries_supported(v)) v = (3, 4, 3) self.assertEqual(False, is_timeseries_supported(v))
def test_conv_datetime_to_unix_millis(self): # This is the "native" Python unix timestamp including # microseconds, as float. timedelta "total_seconds()" # returns a value like this if is_timeseries_supported(): v = 144379690.987000 d = datetime.datetime.utcfromtimestamp(v) utm = unix_time_millis(d) self.assertEqual(utm, 144379690987) else: pass
def test_is_timeseries_supported(self): v = (2, 7, 10) self.assertEqual(True, is_timeseries_supported(v)) v = (2, 7, 11) self.assertEqual(True, is_timeseries_supported(v)) v = (2, 7, 12) self.assertEqual(True, is_timeseries_supported(v)) v = (3, 3, 6) self.assertEqual(False, is_timeseries_supported(v)) v = (3, 4, 3) self.assertEqual(False, is_timeseries_supported(v)) v = (3, 4, 4) self.assertEqual(True, is_timeseries_supported(v)) v = (3, 4, 5) self.assertEqual(True, is_timeseries_supported(v)) v = (3, 5, 0) self.assertEqual(False, is_timeseries_supported(v)) v = (3, 5, 1) self.assertEqual(True, is_timeseries_supported(v))
def test_unix_millis_small_value(self): if is_timeseries_supported(): # this is what would be stored in Riak TS v = 1001 dt = datetime_from_unix_time_millis(v) # This is how Python represents the above utp = 1.001 dtp = datetime.datetime.utcfromtimestamp(utp) self.assertEqual(dt, dtp) utm = unix_time_millis(dt) self.assertEqual(v, utm) else: pass
def test_conv_ms_timestamp_to_datetime_and_back(self): if is_timeseries_supported(): # this is what would be stored in Riak TS v = 144379690987 dt = datetime_from_unix_time_millis(v) # This is how Python represents the above utp = 144379690.987000 dtp = datetime.datetime.utcfromtimestamp(utp) self.assertEqual(dt, dtp) utm = unix_time_millis(dt) self.assertEqual(v, utm) else: pass
boolean_a = Atom('boolean') table_name = 'GeoCheckin' str0 = 'ascii-0' str1 = 'ascii-1' bd0 = six.u('时间序列') bd1 = six.u('временные ряды') fiveMins = datetime.timedelta(0, 300) ts0 = datetime.datetime(2015, 1, 1, 12, 1, 2, 987000) ts1 = ts0 + fiveMins @unittest.skipUnless(is_timeseries_supported(), "Timeseries not supported") class TimeseriesTtbUnitTests(unittest.TestCase): def setUp(self): self.table = Table(None, table_name) def test_encode_data_for_get(self): keylist = [ str_to_bytes('hash1'), str_to_bytes('user2'), unix_time_millis(ts0) ] req = tsgetreq_a, str_to_bytes(table_name), keylist, udef_a req_test = encode(req) test_key = ['hash1', 'user2', ts0] c = TtbCodec()
boolean_a = Atom('boolean') table_name = 'GeoCheckin' str0 = 'ascii-0' str1 = 'ascii-1' bd0 = six.u('时间序列') bd1 = six.u('временные ряды') fiveMins = datetime.timedelta(0, 300) ts0 = datetime.datetime(2015, 1, 1, 12, 1, 2, 987000) ts1 = ts0 + fiveMins @unittest.skipUnless(is_timeseries_supported(), "Timeseries not supported") class TimeseriesTtbUnitTests(unittest.TestCase): def setUp(self): self.table = Table(None, table_name) def test_encode_data_for_get(self): keylist = [ str_to_bytes('hash1'), str_to_bytes('user2'), unix_time_millis(ts0) ] req = tsgetreq_a, str_to_bytes(table_name), keylist, udef_a req_test = encode(req) test_key = ['hash1', 'user2', ts0] c = TtbCodec() msg = c.encode_timeseries_keyreq(self.table, test_key) self.assertEqual(req_test, msg.data)