MCPcopy Index your code
hub / github.com/python/cpython / strftest1

Method strftest1

Lib/test/test_strftime.py:93–139  ·  view source on GitHub ↗
(self, now)

Source from the content-addressed store, hash-verified

91 self.strftest2(arg)
92
93 def strftest1(self, now):
94 if support.verbose:
95 print("strftime test for", time.ctime(now))
96 now = self.now
97 # Make sure any characters that could be taken as regex syntax is
98 # escaped in escapestr()
99 expectations = (
100 ('%a', calendar.day_abbr[now[6]], 'abbreviated weekday name'),
101 ('%A', calendar.day_name[now[6]], 'full weekday name'),
102 ('%b', calendar.month_abbr[now[1]], 'abbreviated month name'),
103 ('%B', calendar.month_name[now[1]], 'full month name'),
104 # %c see below
105 ('%d', '%02d' % now[2], 'day of month as number (00-31)'),
106 ('%H', '%02d' % now[3], 'hour (00-23)'),
107 ('%I', '%02d' % self.clock12, 'hour (01-12)'),
108 ('%j', '%03d' % now[7], 'julian day (001-366)'),
109 ('%m', '%02d' % now[1], 'month as number (01-12)'),
110 ('%M', '%02d' % now[4], 'minute, (00-59)'),
111 ('%p', self.ampm, 'AM or PM as appropriate'),
112 ('%S', '%02d' % now[5], 'seconds of current time (00-60)'),
113 ('%U', '%02d' % ((now[7] + self.jan1[6])//7),
114 'week number of the year (Sun 1st)'),
115 ('%w', '0?%d' % ((1+now[6]) % 7), 'weekday as a number (Sun 1st)'),
116 ('%W', '%02d' % ((now[7] + (self.jan1[6] - 1)%7)//7),
117 'week number of the year (Mon 1st)'),
118 # %x see below
119 ('%X', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'),
120 ('%y', '%02d' % (now[0]%100), 'year without century'),
121 ('%Y', '%d' % now[0], 'year with century'),
122 # %Z see below
123 ('%%', '%', 'single percent sign'),
124 )
125
126 for e in expectations:
127 # mustn't raise a value error
128 try:
129 result = time.strftime(e[0], now)
130 except ValueError as error:
131 self.fail("strftime '%s' format gave error: %s" % (e[0], error))
132 if re.match(escapestr(e[1], self.ampm), result):
133 continue
134 if not result or result[0] == '%':
135 self.fail("strftime does not support standard '%s' format (%s)"
136 % (e[0], e[2]))
137 else:
138 self.fail("Conflict for %s (%s): expected %s, but got %s"
139 % (e[0], e[2], e[1], result))
140
141 def strftest2(self, now):
142 nowsecs = str(int(now))[:-1]

Callers 1

test_strftimeMethod · 0.95

Calls 5

escapestrFunction · 0.85
ctimeMethod · 0.45
strftimeMethod · 0.45
failMethod · 0.45
matchMethod · 0.45

Tested by

no test coverage detected