Buckets:
ktongue/docker_container / simsite /venv /lib /python3.14 /site-packages /matplotlib /tests /test_sankey.py
| import pytest | |
| from numpy.testing import assert_allclose, assert_array_equal | |
| from matplotlib.sankey import Sankey | |
| from matplotlib.testing.decorators import check_figures_equal | |
| def test_sankey(): | |
| # lets just create a sankey instance and check the code runs | |
| sankey = Sankey() | |
| sankey.add() | |
| def test_label(): | |
| s = Sankey(flows=[0.25], labels=['First'], orientations=[-1]) | |
| assert s.diagrams[0].texts[0].get_text() == 'First\n0.25' | |
| def test_format_using_callable(): | |
| # test using callable by slightly incrementing above label example | |
| def show_three_decimal_places(value): | |
| return f'{value:.3f}' | |
| s = Sankey(flows=[0.25], labels=['First'], orientations=[-1], | |
| format=show_three_decimal_places) | |
| assert s.diagrams[0].texts[0].get_text() == 'First\n0.250' | |
| def test_sankey_errors(kwargs, msg): | |
| with pytest.raises(ValueError, match=msg): | |
| Sankey(**kwargs) | |
| def test_sankey_add_errors(kwargs, msg): | |
| sankey = Sankey() | |
| with pytest.raises(ValueError, match=msg): | |
| sankey.add(flows=[0.2, -0.2]) | |
| sankey.add(**kwargs) | |
| def test_sankey2(): | |
| s = Sankey(flows=[0.25, -0.25, 0.5, -0.5], labels=['Foo'], | |
| orientations=[-1], unit='Bar') | |
| sf = s.finish() | |
| assert_array_equal(sf[0].flows, [0.25, -0.25, 0.5, -0.5]) | |
| assert sf[0].angles == [1, 3, 1, 3] | |
| assert all([text.get_text()[0:3] == 'Foo' for text in sf[0].texts]) | |
| assert all([text.get_text()[-3:] == 'Bar' for text in sf[0].texts]) | |
| assert sf[0].text.get_text() == '' | |
| assert_allclose(sf[0].tips, | |
| [(-1.375, -0.52011255), | |
| (1.375, -0.75506044), | |
| (-0.75, -0.41522509), | |
| (0.75, -0.8599479)]) | |
| s = Sankey(flows=[0.25, -0.25, 0, 0.5, -0.5], labels=['Foo'], | |
| orientations=[-1], unit='Bar') | |
| sf = s.finish() | |
| assert_array_equal(sf[0].flows, [0.25, -0.25, 0, 0.5, -0.5]) | |
| assert sf[0].angles == [1, 3, None, 1, 3] | |
| assert_allclose(sf[0].tips, | |
| [(-1.375, -0.52011255), | |
| (1.375, -0.75506044), | |
| (0, 0), | |
| (-0.75, -0.41522509), | |
| (0.75, -0.8599479)]) | |
| def test_sankey3(fig_test, fig_ref): | |
| ax_test = fig_test.gca() | |
| s_test = Sankey(ax=ax_test, flows=[0.25, -0.25, -0.25, 0.25, 0.5, -0.5], | |
| orientations=[1, -1, 1, -1, 0, 0]) | |
| s_test.finish() | |
| ax_ref = fig_ref.gca() | |
| s_ref = Sankey(ax=ax_ref) | |
| s_ref.add(flows=[0.25, -0.25, -0.25, 0.25, 0.5, -0.5], | |
| orientations=[1, -1, 1, -1, 0, 0]) | |
| s_ref.finish() | |
Xet Storage Details
- Size:
- 3.9 kB
- Xet hash:
- 52e235e952437ba7f088c5e3c646ce115168b2c3a62d4c65514706fcd1a67bcb
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.