Lines Matching refs:self
17 def test_basic(self):
18 self.assertEqual(_strptime._getlang(), locale.getlocale(locale.LC_TIME))
28 def setUp(self):
30 self.time_tuple = time.localtime()
31 self.LT_ins = _strptime.LocaleTime()
33 def compare_against_time(self, testing, directive, tuple_position,
39 strftime_output = time.strftime(directive, self.time_tuple).lower()
40 comparison = testing[self.time_tuple[tuple_position]]
41 self.assertIn(strftime_output, testing,
43 self.assertEqual(comparison, strftime_output,
47 def test_weekday(self):
50 self.compare_against_time(self.LT_ins.f_weekday, '%A', 6,
52 self.compare_against_time(self.LT_ins.a_weekday, '%a', 6,
55 def test_month(self):
58 self.compare_against_time(self.LT_ins.f_month, '%B', 1,
60 self.compare_against_time(self.LT_ins.a_month, '%b', 1,
63 def test_am_pm(self):
65 strftime_output = time.strftime("%p", self.time_tuple).lower()
66 self.assertIn(strftime_output, self.LT_ins.am_pm,
68 if self.time_tuple[3] < 12: position = 0
70 self.assertEqual(self.LT_ins.am_pm[position], strftime_output,
76 def test_timezone(self):
78 timezone = time.strftime("%Z", self.time_tuple).lower()
80 self.assertTrue(timezone in self.LT_ins.timezone[0] or
81 timezone in self.LT_ins.timezone[1],
83 (timezone, self.LT_ins.timezone))
85 def test_date_time(self):
94 self.assertEqual(time.strftime(self.LT_ins.LC_date_time, magic_date),
97 self.assertEqual(time.strftime(self.LT_ins.LC_date, magic_date),
100 self.assertEqual(time.strftime(self.LT_ins.LC_time, magic_date),
104 self.assertTrue(LT.LC_time, "LocaleTime's LC directives cannot handle "
107 def test_lang(self):
109 # Assuming locale has not changed between now and when self.LT_ins was created
110 self.assertEqual(self.LT_ins.lang, _strptime._getlang())
116 def setUp(self):
118 self.time_re = _strptime.TimeRE()
119 self.locale_time = _strptime.LocaleTime()
121 def test_pattern(self):
123 pattern_string = self.time_re.pattern(r"%a %A %d")
124 self.assertTrue(pattern_string.find(self.locale_time.a_weekday[2]) != -1,
127 self.assertTrue(pattern_string.find(self.locale_time.f_weekday[4]) != -1,
130 self.assertTrue(pattern_string.find(self.time_re['d']) != -1,
134 def test_pattern_escaping(self):
137 pattern_string = self.time_re.pattern(r"\d+")
138 self.assertIn(r"\\d\+", pattern_string,
143 def test_compile(self):
145 found = self.time_re.compile(r"%A").match(self.locale_time.f_weekday[6])
146 self.assertTrue(found and found.group('A') == self.locale_time.f_weekday[6],
148 compiled = self.time_re.compile(r"%a %b")
149 found = compiled.match("%s %s" % (self.locale_time.a_weekday[4],
150 self.locale_time.a_month[4]))
151 self.assertTrue(found,
153 (compiled.pattern, "%s %s" % (self.locale_time.a_weekday[4],
154 self.locale_time.a_month[4])))
155 self.assertTrue(found.group('a') == self.locale_time.a_weekday[4] and
156 found.group('b') == self.locale_time.a_month[4],
163 compiled = self.time_re.compile("%" + directive)
165 self.assertTrue(found, "Matching failed on '%s' using '%s' regex" %
169 def test_blankpattern(self):
174 self.assertEqual(_strptime.TimeRE(test_locale).pattern("%Z"), '',
177 def test_matching_with_escapes(self):
179 compiled_re = self.time_re.compile(r"\w+ %m")
181 self.assertTrue(found, r"Escaping failed of format '\w+ 10'")
183 def test_locale_data_w_regex_metacharacters(self):
192 self.assertTrue(time_re.compile("%Z").match("Tokyo (standard time)"),
196 def test_whitespace_substitution(self):
200 pattern = self.time_re.pattern('%j %H')
201 self.assertFalse(re.match(pattern, "180"))
202 self.assertTrue(re.match(pattern, "18 0"))
208 def setUp(self):
210 self.time_tuple = time.gmtime()
212 def test_ValueError(self):
214 self.assertRaises(ValueError, _strptime._strptime_time, data_string="%d",
222 self.fail("'%s' raised %s, not ValueError" %
225 self.fail("'%s' did not raise ValueError" % bad_format)
230 with self.assertRaises(ValueError):
233 with self.assertRaises(ValueError):
237 with self.assertRaises(ValueError):
240 with self.assertRaises(ValueError):
243 with self.assertRaises(ValueError):
247 def test_strptime_exception_context(self):
249 with self.assertRaises(ValueError) as e:
251 self.assertIs(e.exception.__suppress_context__, True)
253 with self.assertRaises(ValueError) as e:
255 self.assertIs(e.exception.__suppress_context__, True)
257 def test_unconverteddata(self):
259 self.assertRaises(ValueError, _strptime._strptime_time, "10 12", "%m")
261 def helper(self, directive, position):
263 strf_output = time.strftime("%" + directive, self.time_tuple)
265 self.assertTrue(strp_output[position] == self.time_tuple[position],
268 self.time_tuple[position]))
270 def test_year(self):
273 self.helper(directive, 0)
279 self.assertTrue(strp_output[0] == expected_result,
283 def test_month(self):
286 self.helper(directive, 1)
288 def test_day(self):
290 self.helper('d', 2)
292 def test_hour(self):
294 self.helper('H', 3)
295 strf_output = time.strftime("%I %p", self.time_tuple)
297 self.assertTrue(strp_output[3] == self.time_tuple[3],
299 (strf_output, strp_output[3], self.time_tuple[3]))
301 def test_minute(self):
303 self.helper('M', 4)
305 def test_second(self):
307 self.helper('S', 5)
309 def test_fraction(self):
314 self.assertEqual(frac, d.microsecond)
316 def test_weekday(self):
319 self.helper(directive,6)
321 def test_julian(self):
323 self.helper('j', 7)
325 def test_offset(self):
330 self.assertEqual(offset, one_hour + half_hour)
331 self.assertEqual(offset_fraction, 0)
333 self.assertEqual(offset, -one_hour)
334 self.assertEqual(offset_fraction, 0)
336 self.assertEqual(offset, -(one_hour + half_hour + half_minute))
337 self.assertEqual(offset_fraction, 0)
339 self.assertEqual(offset, -(one_hour + half_hour + half_minute))
340 self.assertEqual(offset_fraction, -1)
342 self.assertEqual(offset, one_hour)
343 self.assertEqual(offset_fraction, 0)
345 self.assertEqual(offset, -(one_hour + half_hour))
346 self.assertEqual(offset_fraction, 0)
348 self.assertEqual(offset, -(one_hour + half_hour + half_minute))
349 self.assertEqual(offset_fraction, 0)
351 self.assertEqual(offset, -(one_hour + half_hour + half_minute))
352 self.assertEqual(offset_fraction, -1)
354 self.assertEqual(offset, one_hour + half_hour + half_minute)
355 self.assertEqual(offset_fraction, 1000)
357 self.assertEqual(offset, 0)
358 self.assertEqual(offset_fraction, 0)
360 def test_bad_offset(self):
361 with self.assertRaises(ValueError):
363 with self.assertRaises(ValueError):
365 with self.assertRaises(ValueError):
367 with self.assertRaises(ValueError):
369 with self.assertRaises(ValueError) as err:
371 self.assertEqual("Inconsistent use of : in -01:3030", str(err.exception))
377 def test_timezone(self):
383 self.assertEqual(strp_output.tm_isdst, 0)
385 self.assertEqual(strp_output.tm_isdst, 0)
391 self.assertTrue(strp_output[8] == time_tuple[8],
395 self.assertTrue(strp_output[8] == -1,
402 def test_bad_timezone(self):
407 self.skipTest('need non-UTC/GMT timezone')
415 self.assertEqual(tz_value, -1,
420 def test_date_time(self):
423 self.helper('c', position)
425 def test_date(self):
428 self.helper('x', position)
430 def test_time(self):
433 self.helper('X', position)
435 def test_percent(self):
437 strf_output = time.strftime("%m %% %Y", self.time_tuple)
439 self.assertTrue(strp_output[0] == self.time_tuple[0] and
440 strp_output[1] == self.time_tuple[1],
443 def test_caseinsensitive(self):
445 strf_output = time.strftime("%B", self.time_tuple)
446 self.assertTrue(_strptime._strptime_time(strf_output.upper(), "%B"),
448 self.assertTrue(_strptime._strptime_time(strf_output.lower(), "%B"),
450 self.assertTrue(_strptime._strptime_time(strf_output.capitalize(), "%B"),
453 def test_defaults(self):
457 self.assertTrue(strp_output == defaults,
461 def test_escaping(self):
468 self.assertTrue(_strptime._strptime_time(need_escaping, need_escaping))
470 def test_feb29_on_leap_year_without_year(self):
473 def test_mar1_comes_after_feb29_even_when_omitting_the_year(self):
474 self.assertLess(
481 def test_twelve_noon_midnight(self):
482 eq = self.assertEqual
492 def test_all_julian_days(self):
493 eq = self.assertEqual
501 def setUp(self):
502 self.time_tuple = time.gmtime()
505 def test_julian_calculation(self):
508 result = _strptime._strptime_time(time.strftime(format_string, self.time_tuple),
510 self.assertTrue(result.tm_yday == self.time_tuple.tm_yday,
512 (result.tm_yday, self.time_tuple.tm_yday))
515 def test_gregorian_calculation(self):
518 result = _strptime._strptime_time(time.strftime(format_string, self.time_tuple),
520 self.assertTrue(result.tm_year == self.time_tuple.tm_year and
521 result.tm_mon == self.time_tuple.tm_mon and
522 result.tm_mday == self.time_tuple.tm_mday,
526 self.time_tuple.tm_year, self.time_tuple.tm_mon,
527 self.time_tuple.tm_mday))
530 def test_day_of_week_calculation(self):
533 result = _strptime._strptime_time(time.strftime(format_string, self.time_tuple),
535 self.assertTrue(result.tm_wday == self.time_tuple.tm_wday,
537 "%s != %s" % (result.tm_wday, self.time_tuple.tm_wday))
551 def test_week_of_year_and_day_of_week_calculation(self):
556 if (year_week_format in self._formats_excluded and
557 ymd_tuple in self._ymd_excluded):
561 with self.subTest(test_reason,
571 self.assertEqual(strp_output[:3], ymd_tuple, msg)
598 def test_week_0(self):
600 self.assertEqual(_strptime._strptime_time(value, format)[:-1], expected)
649 def test_time_re_recreation(self):
657 self.assertIsNot(original_time_re, _strptime._TimeRE_cache)
658 self.assertEqual(len(_strptime._regex_cache), 1)
660 def test_regex_cleanup(self):
671 self.assertEqual(len(_strptime._regex_cache), 1)
673 def test_new_localetime(self):
679 self.assertIsNot(locale_time_id, _strptime._TimeRE_cache.locale_time)
681 def test_TimeRE_recreation_locale(self):
687 self.skipTest('test needs en_US.UTF8 locale')
699 self.assertIsNot(first_time_re, second_time_re)
704 self.skipTest('test needs de_DE.UTF8 locale')
711 def test_TimeRE_recreation_timezone(self):
715 self.assertEqual(tm.tm_isdst, 0)
717 self.assertEqual(tm.tm_isdst, 1)
724 self.assertEqual(tm.tm_isdst, 0)
726 self.assertEqual(tm.tm_isdst, 1)
730 self.assertIsNot(first_time_re, second_time_re)
732 with self.assertRaises(ValueError):
734 with self.assertRaises(ValueError):