MCPcopy Create free account
hub / github.com/dateutil/dateutil / TestFormat

Class TestFormat

tests/test_parser.py:224–289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

222
223
224class TestFormat:
225
226 def test_ybd(self):
227 # If we have a 4-digit year, a non-numeric month (abbreviated or not),
228 # and a day (1 or 2 digits), then there is no ambiguity as to which
229 # token is a year/month/day. This holds regardless of what order the
230 # terms are in and for each of the separators below.
231
232 seps = ['-', ' ', '/', '.']
233
234 year_tokens = ['%Y']
235 month_tokens = ['%b', '%B']
236 day_tokens = ['%d']
237 if PLATFORM_HAS_DASH_D:
238 day_tokens.append('%-d')
239
240 prods = itertools.product(year_tokens, month_tokens, day_tokens)
241 perms = [y for x in prods for y in itertools.permutations(x)]
242 unambig_fmts = [sep.join(perm) for sep in seps for perm in perms]
243
244 actual = datetime(2003, 9, 25)
245
246 for fmt in unambig_fmts:
247 dstr = actual.strftime(fmt)
248 res = parse(dstr)
249 assert res == actual
250
251 # TODO: some redundancy with PARSER_TEST_CASES cases
252 @pytest.mark.parametrize("fmt,dstr", [
253 ("%a %b %d %Y", "Thu Sep 25 2003"),
254 ("%b %d %Y", "Sep 25 2003"),
255 ("%Y-%m-%d", "2003-09-25"),
256 ("%Y%m%d", "20030925"),
257 ("%Y-%b-%d", "2003-Sep-25"),
258 ("%d-%b-%Y", "25-Sep-2003"),
259 ("%b-%d-%Y", "Sep-25-2003"),
260 ("%m-%d-%Y", "09-25-2003"),
261 ("%d-%m-%Y", "25-09-2003"),
262 ("%Y.%m.%d", "2003.09.25"),
263 ("%Y.%b.%d", "2003.Sep.25"),
264 ("%d.%b.%Y", "25.Sep.2003"),
265 ("%b.%d.%Y", "Sep.25.2003"),
266 ("%m.%d.%Y", "09.25.2003"),
267 ("%d.%m.%Y", "25.09.2003"),
268 ("%Y/%m/%d", "2003/09/25"),
269 ("%Y/%b/%d", "2003/Sep/25"),
270 ("%d/%b/%Y", "25/Sep/2003"),
271 ("%b/%d/%Y", "Sep/25/2003"),
272 ("%m/%d/%Y", "09/25/2003"),
273 ("%d/%m/%Y", "25/09/2003"),
274 ("%Y %m %d", "2003 09 25"),
275 ("%Y %b %d", "2003 Sep 25"),
276 ("%d %b %Y", "25 Sep 2003"),
277 ("%m %d %Y", "09 25 2003"),
278 ("%d %m %Y", "25 09 2003"),
279 ("%y %d %b", "03 25 Sep",),
280 ])
281 def test_strftime_formats_2003Sep25(self, fmt, dstr):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected