MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_strptime_tz

Method test_strptime_tz

Lib/test/datetimetester.py:4029–4063  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

4027 self.assertIs(type(got), self.theclass)
4028
4029 def test_strptime_tz(self):
4030 strptime = self.theclass.strptime
4031 self.assertEqual(strptime("+0002", "%z").utcoffset(), 2 * MINUTE)
4032 self.assertEqual(strptime("-0002", "%z").utcoffset(), -2 * MINUTE)
4033 self.assertEqual(
4034 strptime("-00:02:01.000003", "%z").utcoffset(),
4035 -timedelta(minutes=2, seconds=1, microseconds=3)
4036 )
4037 # Only local timezone and UTC are supported
4038 for tzseconds, tzname in ((0, 'UTC'), (0, 'GMT'),
4039 (-_time.timezone, _time.tzname[0])):
4040 if tzseconds < 0:
4041 sign = '-'
4042 seconds = -tzseconds
4043 else:
4044 sign ='+'
4045 seconds = tzseconds
4046 hours, minutes = divmod(seconds//60, 60)
4047 tstr = "{}{:02d}{:02d} {}".format(sign, hours, minutes, tzname)
4048 with self.subTest(tstr=tstr):
4049 t = strptime(tstr, "%z %Z")
4050 self.assertEqual(t.utcoffset(), timedelta(seconds=tzseconds))
4051 self.assertEqual(t.tzname(), tzname)
4052 self.assertIs(type(t), self.theclass)
4053
4054 # Can produce inconsistent time
4055 tstr, fmt = "+1234 UTC", "%z %Z"
4056 t = strptime(tstr, fmt)
4057 self.assertEqual(t.utcoffset(), 12 * HOUR + 34 * MINUTE)
4058 self.assertEqual(t.tzname(), 'UTC')
4059 # yet will roundtrip
4060 self.assertEqual(t.strftime(fmt), tstr)
4061
4062 # Produce naive time if no %z is provided
4063 self.assertEqual(strptime("UTC", "%Z").tzinfo, None)
4064
4065 def test_strptime_errors(self):
4066 for tzstr in ("-2400", "-000", "z"):

Callers

nothing calls this directly

Calls 10

timedeltaClass · 0.90
strptimeFunction · 0.85
subTestMethod · 0.80
divmodFunction · 0.50
assertEqualMethod · 0.45
utcoffsetMethod · 0.45
formatMethod · 0.45
tznameMethod · 0.45
assertIsMethod · 0.45
strftimeMethod · 0.45

Tested by

no test coverage detected