def test_datetype(self): now_timestamp = time.time() now_datetime = datetime.datetime.utcfromtimestamp(now_timestamp) # same results serialized # (this could change if we follow up on the timestamp multiplication warning in DateType.serialize) self.assertEqual(DateType.serialize(now_datetime, 0), DateType.serialize(now_timestamp, 0)) # from timestamp date_type = DateType(now_timestamp) self.assertEqual(date_type.my_timestamp(), now_timestamp) # from datetime object date_type = DateType(now_datetime) self.assertEqual(date_type.my_timestamp(), now_datetime) # deserialize # epoc expected = 0 self.assertEqual(DateType.deserialize(int64_pack(1000 * expected), 0), datetime.datetime.utcfromtimestamp(expected)) # beyond 32b expected = 2**33 self.assertEqual(DateType.deserialize(int64_pack(1000 * expected), 0), datetime.datetime.utcfromtimestamp(expected)) # less than epoc (PYTHON-119) expected = -770172256 self.assertEqual(DateType.deserialize(int64_pack(1000 * expected), 0), datetime.datetime(1945, 8, 5, 23, 15, 44)) self.assertRaises(ValueError, date_type.interpret_datestring, 'fakestring')
def test_datetype(self): now_timestamp = time.time() now_datetime = datetime.datetime.utcfromtimestamp(now_timestamp) # same results serialized (must scale the timestamp to milliseconds) self.assertEqual(DateType.serialize(now_datetime, 0), DateType.serialize(now_timestamp * 1e3, 0)) # from timestamp date_type = DateType(now_timestamp) self.assertEqual(date_type.my_timestamp(), now_timestamp) # from datetime object date_type = DateType(now_datetime) self.assertEqual(date_type.my_timestamp(), now_datetime) # deserialize # epoc expected = 0 self.assertEqual(DateType.deserialize(int64_pack(1000 * expected), 0), datetime.datetime.utcfromtimestamp(expected)) # beyond 32b expected = 2**33 self.assertEqual(DateType.deserialize(int64_pack(1000 * expected), 0), datetime.datetime.utcfromtimestamp(expected)) # less than epoc (PYTHON-119) expected = -770172256 self.assertEqual(DateType.deserialize(int64_pack(1000 * expected), 0), datetime.datetime(1945, 8, 5, 23, 15, 44)) self.assertRaises(ValueError, date_type.interpret_datestring, 'fakestring')
def test_datetype(self): now_time_seconds = time.time() now_datetime = datetime.datetime.utcfromtimestamp(now_time_seconds) # Cassandra timestamps in millis now_timestamp = now_time_seconds * 1e3 # same results serialized self.assertEqual(DateType.serialize(now_datetime, 0), DateType.serialize(now_timestamp, 0)) # from timestamp date_type = DateType(now_timestamp) self.assertEqual(date_type.my_timestamp(), now_timestamp) # from datetime object date_type = DateType(now_datetime) self.assertEqual(date_type.my_timestamp(), now_datetime) # deserialize # epoc expected = 0 self.assertEqual(DateType.deserialize(int64_pack(1000 * expected), 0), datetime.datetime.utcfromtimestamp(expected)) # beyond 32b expected = 2**33 self.assertEqual(DateType.deserialize(int64_pack(1000 * expected), 0), datetime.datetime.utcfromtimestamp(expected)) # less than epoc (PYTHON-119) expected = -770172256 self.assertEqual(DateType.deserialize(int64_pack(1000 * expected), 0), datetime.datetime(1945, 8, 5, 23, 15, 44)) self.assertRaises(ValueError, date_type.interpret_datestring, 'fakestring')
def test_datetype(self): now_time_seconds = time.time() now_datetime = datetime.datetime.utcfromtimestamp(now_time_seconds) # Cassandra timestamps in millis now_timestamp = now_time_seconds * 1e3 # same results serialized self.assertEqual(DateType.serialize(now_datetime, 0), DateType.serialize(now_timestamp, 0)) # from timestamp date_type = DateType(now_timestamp) self.assertEqual(date_type.my_timestamp(), now_timestamp) # from datetime object date_type = DateType(now_datetime) self.assertEqual(date_type.my_timestamp(), now_datetime) # deserialize # epoc expected = 0 self.assertEqual(DateType.deserialize(int64_pack(1000 * expected), 0), datetime.datetime.utcfromtimestamp(expected)) # beyond 32b expected = 2**33 self.assertEqual(DateType.deserialize(int64_pack(1000 * expected), 0), datetime.datetime.utcfromtimestamp(expected)) # less than epoc (PYTHON-119) expected = -770172256 self.assertEqual(DateType.deserialize(int64_pack(1000 * expected), 0), datetime.datetime(1945, 8, 5, 23, 15, 44)) self.assertRaises(ValueError, date_type.interpret_datestring, 'fakestring') # work around rounding difference among Python versions (PYTHON-230) expected = 1424817268.274 self.assertEqual( DateType.deserialize(int64_pack(int(1000 * expected)), 0), datetime.datetime(2015, 2, 24, 22, 34, 28, 274000))
def test_datetype(self): now_time_seconds = time.time() now_datetime = datetime.datetime.utcfromtimestamp(now_time_seconds) # Cassandra timestamps in millis now_timestamp = now_time_seconds * 1e3 # same results serialized self.assertEqual(DateType.serialize(now_datetime, 0), DateType.serialize(now_timestamp, 0)) # from timestamp date_type = DateType(now_timestamp) self.assertEqual(date_type.my_timestamp(), now_timestamp) # from datetime object date_type = DateType(now_datetime) self.assertEqual(date_type.my_timestamp(), now_datetime) # deserialize # epoc expected = 0 self.assertEqual(DateType.deserialize(int64_pack(1000 * expected), 0), datetime.datetime.utcfromtimestamp(expected)) # beyond 32b expected = 2 ** 33 self.assertEqual(DateType.deserialize(int64_pack(1000 * expected), 0), datetime.datetime.utcfromtimestamp(expected)) # less than epoc (PYTHON-119) expected = -770172256 self.assertEqual(DateType.deserialize(int64_pack(1000 * expected), 0), datetime.datetime(1945, 8, 5, 23, 15, 44)) self.assertRaises(ValueError, date_type.interpret_datestring, 'fakestring') # work around rounding difference among Python versions (PYTHON-230) expected = 1424817268.274 self.assertEqual(DateType.deserialize(int64_pack(int(1000 * expected)), 0), datetime.datetime(2015, 2, 24, 22, 34, 28, 274000))
def test_DateType(self): now = datetime.datetime.now() date_type = DateType(now) self.assertEqual(date_type.my_timestamp(), now) self.assertRaises(ValueError, date_type.interpret_datestring, 'fakestring')