7
7
import os
8
8
import sys
9
9
from 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
11
11
from datetime import date as datetime_date
12
12
13
13
import _strptime
@@ -120,7 +120,7 @@ def setUp(self):
120
120
121
121
def test_pattern (self ):
122
122
# 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 " )
124
124
self .assertTrue (pattern_string .find (self .locale_time .a_weekday [2 ]) != - 1 ,
125
125
"did not find abbreviated weekday in pattern string '%s'" %
126
126
pattern_string )
@@ -160,10 +160,11 @@ def test_compile(self):
160
160
found .group ('b' )))
161
161
for directive in ('a' ,'A' ,'b' ,'B' ,'c' ,'d' ,'G' ,'H' ,'I' ,'j' ,'m' ,'M' ,'p' ,
162
162
'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 ))
165
166
self .assertTrue (found , "Matching failed on '%s' using '%s' regex" %
166
- (time .strftime ("%" + directive ),
167
+ (time .strftime (fmt ),
167
168
compiled .pattern ))
168
169
169
170
def test_blankpattern (self ):
@@ -290,8 +291,9 @@ def test_unconverteddata(self):
290
291
291
292
def helper (self , directive , position ):
292
293
"""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 )
295
297
self .assertTrue (strp_output [position ] == self .time_tuple [position ],
296
298
"testing of '%s' directive failed; '%s' -> %s != %s" %
297
299
(directive , strf_output , strp_output [position ],
@@ -497,9 +499,11 @@ def test_escaping(self):
497
499
need_escaping = r".^$*+?{}\[]|)("
498
500
self .assertTrue (_strptime ._strptime_time (need_escaping , need_escaping ))
499
501
502
+ @warnings_helper .ignore_warnings (category = DeprecationWarning ) # gh-70647
500
503
def test_feb29_on_leap_year_without_year (self ):
501
504
time .strptime ("Feb 29" , "%b %d" )
502
505
506
+ @warnings_helper .ignore_warnings (category = DeprecationWarning ) # gh-70647
503
507
def test_mar1_comes_after_feb29_even_when_omitting_the_year (self ):
504
508
self .assertLess (
505
509
time .strptime ("Feb 29" , "%b %d" ),
@@ -679,33 +683,33 @@ class CacheTests(unittest.TestCase):
679
683
def test_time_re_recreation (self ):
680
684
# Make sure cache is recreated when current locale does not match what
681
685
# cached object was created with.
682
- _strptime ._strptime_time ("10" , "%d" )
686
+ _strptime ._strptime_time ("10 2004 " , "%d %Y " )
683
687
_strptime ._strptime_time ("2005" , "%Y" )
684
688
_strptime ._TimeRE_cache .locale_time .lang = "Ni"
685
689
original_time_re = _strptime ._TimeRE_cache
686
- _strptime ._strptime_time ("10" , "%d" )
690
+ _strptime ._strptime_time ("10 2004 " , "%d %Y " )
687
691
self .assertIsNot (original_time_re , _strptime ._TimeRE_cache )
688
692
self .assertEqual (len (_strptime ._regex_cache ), 1 )
689
693
690
694
def test_regex_cleanup (self ):
691
695
# Make sure cached regexes are discarded when cache becomes "full".
692
696
try :
693
- del _strptime ._regex_cache ['%d' ]
697
+ del _strptime ._regex_cache ['%d %Y ' ]
694
698
except KeyError :
695
699
pass
696
700
bogus_key = 0
697
701
while len (_strptime ._regex_cache ) <= _strptime ._CACHE_MAX_SIZE :
698
702
_strptime ._regex_cache [bogus_key ] = None
699
703
bogus_key += 1
700
- _strptime ._strptime_time ("10" , "%d" )
704
+ _strptime ._strptime_time ("10 2004 " , "%d %Y " )
701
705
self .assertEqual (len (_strptime ._regex_cache ), 1 )
702
706
703
707
def test_new_localetime (self ):
704
708
# A new LocaleTime instance should be created when a new TimeRE object
705
709
# is created.
706
710
locale_time_id = _strptime ._TimeRE_cache .locale_time
707
711
_strptime ._TimeRE_cache .locale_time .lang = "Ni"
708
- _strptime ._strptime_time ("10" , "%d" )
712
+ _strptime ._strptime_time ("10 2004 " , "%d %Y " )
709
713
self .assertIsNot (locale_time_id , _strptime ._TimeRE_cache .locale_time )
710
714
711
715
def test_TimeRE_recreation_locale (self ):
@@ -716,13 +720,13 @@ def test_TimeRE_recreation_locale(self):
716
720
except locale .Error :
717
721
self .skipTest ('test needs en_US.UTF8 locale' )
718
722
try :
719
- _strptime ._strptime_time ('10' , '%d' )
723
+ _strptime ._strptime_time ('10 2004 ' , '%d %Y ' )
720
724
# Get id of current cache object.
721
725
first_time_re = _strptime ._TimeRE_cache
722
726
try :
723
727
# Change the locale and force a recreation of the cache.
724
728
locale .setlocale (locale .LC_TIME , ('de_DE' , 'UTF8' ))
725
- _strptime ._strptime_time ('10' , '%d' )
729
+ _strptime ._strptime_time ('10 2004 ' , '%d %Y ' )
726
730
# Get the new cache object's id.
727
731
second_time_re = _strptime ._TimeRE_cache
728
732
# They should not be equal.
0 commit comments