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

Method strftest2

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

Source from the content-addressed store, hash-verified

139 % (e[0], e[2], e[1], result))
140
141 def strftest2(self, now):
142 nowsecs = str(int(now))[:-1]
143 now = self.now
144
145 nonstandard_expectations = (
146 # These are standard but don't have predictable output
147 ('%c', fixasctime(time.asctime(now)), 'near-asctime() format'),
148 ('%x', '%02d/%02d/%02d' % (now[1], now[2], (now[0]%100)),
149 '%m/%d/%y %H:%M:%S'),
150 ('%Z', '%s' % self.tz, 'time zone name'),
151
152 # These are some platform specific extensions
153 ('%D', '%02d/%02d/%02d' % (now[1], now[2], (now[0]%100)), 'mm/dd/yy'),
154 ('%e', '%2d' % now[2], 'day of month as number, blank padded ( 0-31)'),
155 ('%h', calendar.month_abbr[now[1]], 'abbreviated month name'),
156 ('%k', '%2d' % now[3], 'hour, blank padded ( 0-23)'),
157 ('%n', '\n', 'newline character'),
158 ('%r', '%02d:%02d:%02d %s' % (self.clock12, now[4], now[5], self.ampm),
159 '%I:%M:%S %p'),
160 ('%R', '%02d:%02d' % (now[3], now[4]), '%H:%M'),
161 ('%s', nowsecs, 'seconds since the Epoch in UCT'),
162 ('%t', '\t', 'tab character'),
163 ('%T', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'),
164 ('%3y', '%03d' % (now[0]%100),
165 'year without century rendered using fieldwidth'),
166 )
167
168
169 for e in nonstandard_expectations:
170 try:
171 result = time.strftime(e[0], now)
172 except ValueError as result:
173 msg = "Error for nonstandard '%s' format (%s): %s" % \
174 (e[0], e[2], str(result))
175 if support.verbose:
176 print(msg)
177 continue
178 if re.match(escapestr(e[1], self.ampm), result):
179 if support.verbose:
180 print("Supports nonstandard '%s' format (%s)" % (e[0], e[2]))
181 elif not result or result[0] == '%':
182 if support.verbose:
183 print("Does not appear to support '%s' format (%s)" % \
184 (e[0], e[2]))
185 else:
186 if support.verbose:
187 print("Conflict for nonstandard '%s' format (%s):" % \
188 (e[0], e[2]))
189 print(" Expected %s, but got %s" % (e[1], result))
190
191
192class Y1900Tests(unittest.TestCase):

Callers 1

test_strftimeMethod · 0.95

Calls 5

strFunction · 0.85
fixasctimeFunction · 0.85
escapestrFunction · 0.85
strftimeMethod · 0.45
matchMethod · 0.45

Tested by

no test coverage detected