(self)
| 39 | time.tzset() |
| 40 | |
| 41 | def test_normalize_time(self): |
| 42 | ts_local = datetime.datetime(2000, 1, 1, 12, 0, 0) # Noon on Jan 1. |
| 43 | ts_utc = ts_local + datetime.timedelta(hours=8) # For fake tz. |
| 44 | ts_inv = ts_local - datetime.timedelta(hours=8) |
| 45 | |
| 46 | # Naive datetime. |
| 47 | |
| 48 | # No conversion is applied, as we treat everything as local time. |
| 49 | self.assertEqual(normalize_time(ts_local, utc=False), ts_local) |
| 50 | |
| 51 | # So we provided a naive timestamp from the localtime (us/pacific), |
| 52 | # which is 8 hours behind UTC in January. |
| 53 | self.assertEqual(normalize_time(ts_local, utc=True), ts_utc) |
| 54 | |
| 55 | # TZ-aware datetime in local timezone (Fake US/Pacific). |
| 56 | |
| 57 | # Here we provide a tz-aware timestamp from the localtime (us/pacific). |
| 58 | ts = datetime.datetime(2000, 1, 1, 12, 0, 0, tzinfo=FakePacific()) |
| 59 | |
| 60 | # No conversion, treated as local time. |
| 61 | self.assertEqual(normalize_time(ts, utc=False), ts_local) |
| 62 | |
| 63 | # Converted to UTC according to rules from our fake tzinfo, +8 hours. |
| 64 | self.assertEqual(normalize_time(ts, utc=True), ts_utc) |
| 65 | |
| 66 | # TZ-aware datetime in UTC timezone. |
| 67 | |
| 68 | # Here we provide a tz-aware timestamp using UTC timezone. |
| 69 | ts = datetime.datetime(2000, 1, 1, 12, 0, 0, tzinfo=UTC()) |
| 70 | |
| 71 | # Since we're specifying utc=False, we are dealing with localtimes |
| 72 | # internally. The timestamp passed in is a tz-aware timestamp in UTC. |
| 73 | # To convert to a naive localtime, we subtract 8 hours (since UTC is |
| 74 | # 8 hours ahead of our local time). |
| 75 | self.assertEqual(normalize_time(ts, utc=False), ts_inv) |
| 76 | |
| 77 | # When utc=True there's no change, since the timestamp is already UTC. |
| 78 | self.assertEqual(normalize_time(ts, utc=True), ts_local) |
| 79 | |
| 80 | def test_zero_delay(self): |
| 81 | # A delay of zero means "now" -- it is not treated as missing. |
nothing calls this directly
no test coverage detected