For datetime object dt, check DateFormatter fields
(dt)
| 227 | as well as a few related issues for years before 1900. |
| 228 | """ |
| 229 | def test_strftime_fields(dt): |
| 230 | """For datetime object dt, check DateFormatter fields""" |
| 231 | # Note: the last couple of %%s are to check multiple %s are handled |
| 232 | # properly; %% should get replaced by %. |
| 233 | formatter = mdates.DateFormatter("%w %d %m %y %Y %H %I %M %S %%%f %%x") |
| 234 | # Compute date fields without using datetime.strftime, |
| 235 | # since datetime.strftime does not work before year 1900 |
| 236 | formatted_date_str = ( |
| 237 | "{weekday} {day:02d} {month:02d} {year:02d} {full_year:04d} " |
| 238 | "{hour24:02d} {hour12:02d} {minute:02d} {second:02d} " |
| 239 | "%{microsecond:06d} %x" |
| 240 | .format( |
| 241 | weekday=str((dt.weekday() + 1) % 7), |
| 242 | day=dt.day, |
| 243 | month=dt.month, |
| 244 | year=dt.year % 100, |
| 245 | full_year=dt.year, |
| 246 | hour24=dt.hour, |
| 247 | hour12=((dt.hour-1) % 12) + 1, |
| 248 | minute=dt.minute, |
| 249 | second=dt.second, |
| 250 | microsecond=dt.microsecond)) |
| 251 | with pytest.warns(MatplotlibDeprecationWarning): |
| 252 | assert formatter.strftime(dt) == formatted_date_str |
| 253 | |
| 254 | try: |
| 255 | # Test strftime("%x") with the current locale. |
| 256 | import locale # Might not exist on some platforms, such as Windows |
| 257 | locale_formatter = mdates.DateFormatter("%x") |
| 258 | locale_d_fmt = locale.nl_langinfo(locale.D_FMT) |
| 259 | expanded_formatter = mdates.DateFormatter(locale_d_fmt) |
| 260 | with pytest.warns(MatplotlibDeprecationWarning): |
| 261 | assert locale_formatter.strftime(dt) == \ |
| 262 | expanded_formatter.strftime(dt) |
| 263 | except (ImportError, AttributeError): |
| 264 | pass |
| 265 | |
| 266 | for year in range(1, 3000, 71): |
| 267 | # Iterate through random set of years |
no test coverage detected