77import os
88import sys
99from test import support
10- from test .support import skip_if_buggy_ucrt_strfptime
10+ from test .support import skip_if_buggy_ucrt_strfptime , warnings_helper
1111from datetime import date as datetime_date
1212
1313import _strptime
@@ -120,7 +120,7 @@ def setUp(self):
120120
121121def test_pattern (self ):
122122# Test TimeRE.pattern
123- pattern_string = self .time_re .pattern (r"%a %A %d" )
123+ pattern_string = self .time_re .pattern (r"%a %A %d %Y " )
124124self .assertTrue (pattern_string .find (self .locale_time .a_weekday [2 ])!= - 1 ,
125125"did not find abbreviated weekday in pattern string '%s'" %
126126pattern_string )
@@ -160,10 +160,11 @@ def test_compile(self):
160160found .group ('b' )))
161161for directive in ('a' ,'A' ,'b' ,'B' ,'c' ,'d' ,'G' ,'H' ,'I' ,'j' ,'m' ,'M' ,'p' ,
162162'S' ,'u' ,'U' ,'V' ,'w' ,'W' ,'x' ,'X' ,'y' ,'Y' ,'Z' ,'%' ):
163- compiled = self .time_re .compile ("%" + directive )
164- found = compiled .match (time .strftime ("%" + directive ))
163+ fmt = "%d %Y" if directive == 'd' else "%" + directive
164+ compiled = self .time_re .compile (fmt )
165+ found = compiled .match (time .strftime (fmt ))
165166self .assertTrue (found ,"Matching failed on '%s' using '%s' regex" %
166- (time .strftime ("%" + directive ),
167+ (time .strftime (fmt ),
167168compiled .pattern ))
168169
169170def test_blankpattern (self ):
@@ -290,8 +291,9 @@ def test_unconverteddata(self):
290291
291292def helper (self ,directive ,position ):
292293"""Helper fxn in testing."""
293- strf_output = time .strftime ("%" + directive ,self .time_tuple )
294- strp_output = _strptime ._strptime_time (strf_output ,"%" + directive )
294+ fmt = "%d %Y" if directive == 'd' else "%" + directive
295+ strf_output = time .strftime (fmt ,self .time_tuple )
296+ strp_output = _strptime ._strptime_time (strf_output ,fmt )
295297self .assertTrue (strp_output [position ]== self .time_tuple [position ],
296298"testing of '%s' directive failed; '%s' -> %s != %s" %
297299 (directive ,strf_output ,strp_output [position ],
@@ -497,9 +499,11 @@ def test_escaping(self):
497499need_escaping = r".^$*+?{}\[]|)("
498500self .assertTrue (_strptime ._strptime_time (need_escaping ,need_escaping ))
499501
502+ @warnings_helper .ignore_warnings (category = DeprecationWarning )# gh-70647
500503def test_feb29_on_leap_year_without_year (self ):
501504time .strptime ("Feb 29" ,"%b %d" )
502505
506+ @warnings_helper .ignore_warnings (category = DeprecationWarning )# gh-70647
503507def test_mar1_comes_after_feb29_even_when_omitting_the_year (self ):
504508self .assertLess (
505509time .strptime ("Feb 29" ,"%b %d" ),
@@ -679,33 +683,33 @@ class CacheTests(unittest.TestCase):
679683def test_time_re_recreation (self ):
680684# Make sure cache is recreated when current locale does not match what
681685# cached object was created with.
682- _strptime ._strptime_time ("10" ,"%d" )
686+ _strptime ._strptime_time ("10 2004 " ,"%d %Y " )
683687_strptime ._strptime_time ("2005" ,"%Y" )
684688_strptime ._TimeRE_cache .locale_time .lang = "Ni"
685689original_time_re = _strptime ._TimeRE_cache
686- _strptime ._strptime_time ("10" ,"%d" )
690+ _strptime ._strptime_time ("10 2004 " ,"%d %Y " )
687691self .assertIsNot (original_time_re ,_strptime ._TimeRE_cache )
688692self .assertEqual (len (_strptime ._regex_cache ),1 )
689693
690694def test_regex_cleanup (self ):
691695# Make sure cached regexes are discarded when cache becomes "full".
692696try :
693- del _strptime ._regex_cache ['%d' ]
697+ del _strptime ._regex_cache ['%d %Y ' ]
694698except KeyError :
695699pass
696700bogus_key = 0
697701while len (_strptime ._regex_cache )<= _strptime ._CACHE_MAX_SIZE :
698702_strptime ._regex_cache [bogus_key ]= None
699703bogus_key += 1
700- _strptime ._strptime_time ("10" ,"%d" )
704+ _strptime ._strptime_time ("10 2004 " ,"%d %Y " )
701705self .assertEqual (len (_strptime ._regex_cache ),1 )
702706
703707def test_new_localetime (self ):
704708# A new LocaleTime instance should be created when a new TimeRE object
705709# is created.
706710locale_time_id = _strptime ._TimeRE_cache .locale_time
707711_strptime ._TimeRE_cache .locale_time .lang = "Ni"
708- _strptime ._strptime_time ("10" ,"%d" )
712+ _strptime ._strptime_time ("10 2004 " ,"%d %Y " )
709713self .assertIsNot (locale_time_id ,_strptime ._TimeRE_cache .locale_time )
710714
711715def test_TimeRE_recreation_locale (self ):
@@ -716,13 +720,13 @@ def test_TimeRE_recreation_locale(self):
716720except locale .Error :
717721self .skipTest ('test needs en_US.UTF8 locale' )
718722try :
719- _strptime ._strptime_time ('10' ,'%d' )
723+ _strptime ._strptime_time ('10 2004 ' ,'%d %Y ' )
720724# Get id of current cache object.
721725first_time_re = _strptime ._TimeRE_cache
722726try :
723727# Change the locale and force a recreation of the cache.
724728locale .setlocale (locale .LC_TIME , ('de_DE' ,'UTF8' ))
725- _strptime ._strptime_time ('10' ,'%d' )
729+ _strptime ._strptime_time ('10 2004 ' ,'%d %Y ' )
726730# Get the new cache object's id.
727731second_time_re = _strptime ._TimeRE_cache
728732# They should not be equal.