()
| 1301 | |
| 1302 | |
| 1303 | def test_DateLocator(): |
| 1304 | locator = mdates.DateLocator() |
| 1305 | # Test nonsingular |
| 1306 | assert locator.nonsingular(0, np.inf) == (0, 1) |
| 1307 | assert locator.nonsingular(0, 1) == (0, 1) |
| 1308 | assert locator.nonsingular(1, 0) == (0, 1) |
| 1309 | assert locator.nonsingular(0, 0) == (-2, 2) |
| 1310 | locator.create_dummy_axis() |
| 1311 | # default values |
| 1312 | assert locator.datalim_to_dt() == ( |
| 1313 | datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc), |
| 1314 | datetime.datetime(1970, 1, 2, 0, 0, tzinfo=datetime.timezone.utc)) |
| 1315 | |
| 1316 | # Check default is UTC |
| 1317 | assert locator.tz == mdates.UTC |
| 1318 | tz_str = 'Iceland' |
| 1319 | iceland_tz = dateutil.tz.gettz(tz_str) |
| 1320 | # Check not Iceland |
| 1321 | assert locator.tz != iceland_tz |
| 1322 | # Set it to Iceland |
| 1323 | locator.set_tzinfo('Iceland') |
| 1324 | # Check now it is Iceland |
| 1325 | assert locator.tz == iceland_tz |
| 1326 | locator.create_dummy_axis() |
| 1327 | locator.axis.set_data_interval(*mdates.date2num(["2022-01-10", |
| 1328 | "2022-01-08"])) |
| 1329 | assert locator.datalim_to_dt() == ( |
| 1330 | datetime.datetime(2022, 1, 8, 0, 0, tzinfo=iceland_tz), |
| 1331 | datetime.datetime(2022, 1, 10, 0, 0, tzinfo=iceland_tz)) |
| 1332 | |
| 1333 | # Set rcParam |
| 1334 | plt.rcParams['timezone'] = tz_str |
| 1335 | |
| 1336 | # Create a new one in a similar way |
| 1337 | locator = mdates.DateLocator() |
| 1338 | # Check now it is Iceland |
| 1339 | assert locator.tz == iceland_tz |
| 1340 | |
| 1341 | # Test invalid tz values |
| 1342 | with pytest.raises(ValueError, match="Aiceland is not a valid timezone"): |
| 1343 | mdates.DateLocator(tz="Aiceland") |
| 1344 | with pytest.raises(TypeError, |
| 1345 | match="tz must be string or tzinfo subclass."): |
| 1346 | mdates.DateLocator(tz=1) |
| 1347 | |
| 1348 | |
| 1349 | def test_datestr2num(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…