def test_w_millis(self): import datetime import pytz from gcloud.bigquery._helpers import _total_seconds NOW = datetime.datetime.utcnow().replace(tzinfo=pytz.utc) EPOCH = datetime.datetime(1970, 1, 1, tzinfo=pytz.utc) MILLIS = _total_seconds(NOW - EPOCH) * 1000 self.assertEqual(self._callFUT(MILLIS), NOW)
def test_w_utc_datetime(self): import datetime import pytz from gcloud.bigquery._helpers import _total_seconds NOW = datetime.datetime.utcnow().replace(tzinfo=pytz.utc) EPOCH = datetime.datetime(1970, 1, 1, tzinfo=pytz.utc) MILLIS = int(_total_seconds(NOW - EPOCH) * 1000) result = self._callFUT(NOW) self.assertTrue(isinstance(result, int)) self.assertEqual(result, MILLIS)
def test_w_non_utc_datetime(self): import datetime import pytz from gcloud.bigquery._helpers import _total_seconds eastern = pytz.timezone('US/Eastern') NOW = datetime.datetime(2015, 7, 28, 16, 34, 47, tzinfo=eastern) EPOCH = datetime.datetime(1970, 1, 1, tzinfo=pytz.utc) MILLIS = int(_total_seconds(NOW - EPOCH) * 1000) result = self._callFUT(NOW) self.assertTrue(isinstance(result, int)) self.assertEqual(result, MILLIS)