|
| 1 | +from packaging import version |
1 | 2 | import pytest |
2 | 3 | import numpy as np |
3 | 4 | from numpy.testing import assert_allclose, assert_array_equal |
4 | 5 | import pandas as pd |
5 | 6 | from pandas.testing import assert_frame_equal, assert_series_equal |
| 7 | +import matplotlib |
6 | 8 |
|
7 | 9 | import darshan |
8 | 10 | from darshan.log_utils import get_log_path |
@@ -272,3 +274,44 @@ def test_combine_hdf5_modules(input_df, expected_df): |
272 | 274 |
|
273 | 275 | # check actual and expected dataframes are identical |
274 | 276 | assert_frame_equal(actual_df, expected_df) |
| 277 | + |
| 278 | + |
| 279 | +@pytest.mark.parametrize( |
| 280 | + "logname, expected_xticks, expected_xlabels", [ |
| 281 | + ( |
| 282 | + "shane_ior-PNETCDF_id438100-438100_11-9-41525-10280033558448664385_1.darshan", |
| 283 | + range(4), |
| 284 | + ["POSIX", "MPIIO", "PNETCDF", "STDIO"] |
| 285 | + ), |
| 286 | + ( |
| 287 | + "imbalanced-io.darshan", |
| 288 | + range(3), |
| 289 | + ["POSIX", "MPIIO", "STDIO"] |
| 290 | + ), |
| 291 | + ], |
| 292 | +) |
| 293 | +def test_plot_io_cost_x_ticks_and_labels(logname, |
| 294 | + expected_xticks, |
| 295 | + expected_xlabels): |
| 296 | + # check the x-axis tick marks are at the appropriate |
| 297 | + # locations and the labels are as expected |
| 298 | + |
| 299 | + logpath = get_log_path(logname) |
| 300 | + with darshan.DarshanReport(logpath) as report: |
| 301 | + fig = plot_io_cost(report=report) |
| 302 | + for i, ax in enumerate(fig.axes): |
| 303 | + if i > 0 and version.parse(matplotlib.__version__) < version.parse("3.6.0"): |
| 304 | + # the second (invisible/twinned) axis is effectively |
| 305 | + # empty in older matplotlib versions |
| 306 | + continue |
| 307 | + # there are only 2 axes, the first being the "raw" data |
| 308 | + # and the second being the normalized data (percent) |
| 309 | + actual_xticks = ax.get_xticks() |
| 310 | + xticklabels = ax.get_xticklabels() |
| 311 | + actual_xticklabels = [tl.get_text() for tl in xticklabels] |
| 312 | + assert_allclose(actual_xticks, expected_xticks) |
| 313 | + assert_array_equal(actual_xticklabels, expected_xlabels) |
| 314 | + # regression test for gh-881 |
| 315 | + expected_rotations = 90 |
| 316 | + x_rotations = [tl.get_rotation() for tl in xticklabels] |
| 317 | + assert_allclose(x_rotations, expected_rotations) |
0 commit comments