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