def test_datetime_str_to_proto_ts_conversion(self): now = datetime.utcnow() delta = now - datetime(1970, 1, 1) expected_seconds = int(delta.total_seconds()) expected_nanos = delta.microseconds * 1000 proto_ts = utils.proto_ts_from_datetime_str(now.isoformat() + 'Z') self.assertEqual(proto_ts.seconds, int(expected_seconds)) self.assertEqual(proto_ts.nanos, expected_nanos)
def test_datetime_str_to_proto_ts_conversion_invalid(self): proto_ts = utils.proto_ts_from_datetime_str('2018 08 22 T 11:53') self.assertEquals(proto_ts.seconds, 0) self.assertEquals(proto_ts.nanos, 0)
def test_datetime_str_to_proto_ts_conversion_empty(self): proto_ts = utils.proto_ts_from_datetime_str('') self.assertEquals(proto_ts.seconds, 0) self.assertEquals(proto_ts.nanos, 0)