(
data_offset,
noise,
oom_center_desired,
oom_noise_desired
)
| 1654 | ] |
| 1655 | ) |
| 1656 | def test_engformatter_offset_oom( |
| 1657 | data_offset, |
| 1658 | noise, |
| 1659 | oom_center_desired, |
| 1660 | oom_noise_desired |
| 1661 | ): |
| 1662 | UNIT = "eV" |
| 1663 | fig, ax = plt.subplots() |
| 1664 | ydata = data_offset + np.arange(-5, 7, dtype=float)*noise |
| 1665 | ax.plot(ydata) |
| 1666 | formatter = mticker.EngFormatter(useOffset=True, unit=UNIT) |
| 1667 | # So that offset strings will always have the same size |
| 1668 | formatter.ENG_PREFIXES[0] = "_" |
| 1669 | ax.yaxis.set_major_formatter(formatter) |
| 1670 | fig.canvas.draw() |
| 1671 | offset_got = formatter.get_offset() |
| 1672 | ticks_got = [labl.get_text() for labl in ax.get_yticklabels()] |
| 1673 | # Predicting whether offset should be 0 or not is essentially testing |
| 1674 | # ScalarFormatter._compute_offset . This function is pretty complex and it |
| 1675 | # would be nice to test it, but this is out of scope for this test which |
| 1676 | # only makes sure that offset text and the ticks gets the correct unit |
| 1677 | # prefixes and the ticks. |
| 1678 | if formatter.offset: |
| 1679 | prefix_noise_got = offset_got[2] |
| 1680 | prefix_noise_desired = formatter.ENG_PREFIXES[oom_noise_desired] |
| 1681 | prefix_center_got = offset_got[-1-len(UNIT)] |
| 1682 | prefix_center_desired = formatter.ENG_PREFIXES[oom_center_desired] |
| 1683 | assert prefix_noise_desired == prefix_noise_got |
| 1684 | assert prefix_center_desired == prefix_center_got |
| 1685 | # Make sure the ticks didn't get the UNIT |
| 1686 | for tick in ticks_got: |
| 1687 | assert UNIT not in tick |
| 1688 | else: |
| 1689 | assert oom_center_desired == 0 |
| 1690 | assert offset_got == "" |
| 1691 | # Make sure the ticks contain now the prefixes |
| 1692 | for tick in ticks_got: |
| 1693 | # 0 is zero on all orders of magnitudes, no matter what is |
| 1694 | # oom_noise_desired |
| 1695 | prefix_idx = 0 if tick[0] == "0" else oom_noise_desired |
| 1696 | assert tick.endswith(formatter.ENG_PREFIXES[prefix_idx] + UNIT) |
| 1697 | |
| 1698 | |
| 1699 | class TestPercentFormatter: |
nothing calls this directly
no test coverage detected
searching dependent graphs…