self.assertIs(dt.tzinfo, timezone.utc)
+ def test_fromisoformat_utc_subsecond_offset(self):
+ # A UTC offset whose whole-second part is zero but with a non-zero
+ # microsecond part must be preserved, not collapsed to UTC.
+ for us in (1, -1, 999999, -999999):
+ with self.subTest(microseconds=us):
+ tz = timezone(timedelta(microseconds=us))
+ dt = self.theclass(2020, 6, 15, 12, 34, 56, tzinfo=tz)
+ rt = self.theclass.fromisoformat(dt.isoformat())
+ self.assertEqual(rt.utcoffset(), timedelta(microseconds=us))
+ self.assertEqual(rt, dt)
+ self.assertIsNot(rt.tzinfo, timezone.utc)
+
+ tz = timezone(timedelta(hours=5, minutes=30, seconds=15,
+ microseconds=123456))
+ dt = self.theclass(2020, 6, 15, 12, 34, 56, tzinfo=tz)
+ rt = self.theclass.fromisoformat(dt.isoformat())
+ self.assertEqual(rt.utcoffset(), tz.utcoffset(None))
+ self.assertEqual(rt, dt)
+
+ for tstr in ('2020-06-15T12:34:56+00:00',
+ '2020-06-15T12:34:56+00:00:00.000000',
+ '2020-06-15T12:34:56Z'):
+ with self.subTest(tstr=tstr):
+ self.assertIs(self.theclass.fromisoformat(tstr).tzinfo,
+ timezone.utc)
+
def test_fromisoformat_subclass(self):
class DateTimeSubclass(self.theclass):
pass