| 453 | |
| 454 | |
| 455 | class TzWinFoldMixin: |
| 456 | def get_args(self, tzname): |
| 457 | return (tzname, ) |
| 458 | |
| 459 | class context: |
| 460 | def __init__(*args, **kwargs): |
| 461 | pass |
| 462 | |
| 463 | def __enter__(*args, **kwargs): |
| 464 | pass |
| 465 | |
| 466 | def __exit__(*args, **kwargs): |
| 467 | pass |
| 468 | |
| 469 | def get_utc_transitions(self, tzi, year, gap): |
| 470 | dston, dstoff = tzi.transitions(year) |
| 471 | if gap: |
| 472 | t_n = dston - timedelta(minutes=30) |
| 473 | |
| 474 | t0_u = t_n.replace(tzinfo=tzi).astimezone(tz.UTC) |
| 475 | t1_u = t0_u + timedelta(hours=1) |
| 476 | else: |
| 477 | # Get 1 hour before the first ambiguous date |
| 478 | t_n = dstoff - timedelta(minutes=30) |
| 479 | |
| 480 | t0_u = t_n.replace(tzinfo=tzi).astimezone(tz.UTC) |
| 481 | t_n += timedelta(hours=1) # Naive ambiguous date |
| 482 | t0_u = t0_u + timedelta(hours=1) # First ambiguous date |
| 483 | t1_u = t0_u + timedelta(hours=1) # Second ambiguous date |
| 484 | |
| 485 | return t_n, t0_u, t1_u |
| 486 | |
| 487 | def testFoldPositiveUTCOffset(self): |
| 488 | # Test that we can resolve ambiguous times |
| 489 | tzname = 'AUS Eastern Standard Time' |
| 490 | args = self.get_args(tzname) |
| 491 | |
| 492 | with self.context(tzname): |
| 493 | # Calling fromutc() alters the tzfile object |
| 494 | SYD = self.tzclass(*args) |
| 495 | |
| 496 | # Get the transition time in UTC from the object, because |
| 497 | # Windows doesn't store historical info |
| 498 | t_n, t0_u, t1_u = self.get_utc_transitions(SYD, 2012, False) |
| 499 | |
| 500 | # Using fresh tzfiles |
| 501 | t0_syd = t0_u.astimezone(SYD) |
| 502 | t1_syd = t1_u.astimezone(SYD) |
| 503 | |
| 504 | self.assertEqual(t0_syd.replace(tzinfo=None), t_n) |
| 505 | |
| 506 | self.assertEqual(t1_syd.replace(tzinfo=None), t_n) |
| 507 | |
| 508 | self.assertEqual(t0_syd.utcoffset(), timedelta(hours=11)) |
| 509 | self.assertEqual(t1_syd.utcoffset(), timedelta(hours=10)) |
| 510 | self.assertNotEqual(t0_syd.tzname(), t1_syd.tzname()) |
| 511 | |
| 512 | def testGapPositiveUTCOffset(self): |
nothing calls this directly
no outgoing calls
no test coverage detected