From 9a971a22de129f721182d38ece36ea522add6b89 Mon Sep 17 00:00:00 2001 From: Neil Vaytet Date: Tue, 26 Sep 2023 11:37:35 +0200 Subject: [PATCH] add some inspector plot tests --- tests/plotting/inspector_test.py | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/plotting/inspector_test.py b/tests/plotting/inspector_test.py index cc2f713f..5edd7f1b 100644 --- a/tests/plotting/inspector_test.py +++ b/tests/plotting/inspector_test.py @@ -39,3 +39,46 @@ def test_raises_ValueError_when_given_binned_data(use_ipympl): da = sc.data.table_xyz(100).bin(x=10, y=20, z=30) with pytest.raises(ValueError, match='Cannot plot binned data'): pp.inspector(da, orientation='vertical') + + +def test_line_creation(use_ipympl): + da = pp.data.data3d() + ip = pp.inspector(da) + fig2d = ip[0][0] + fig1d = ip[0][1] + # Activate the inspector tool + fig2d.toolbar['inspect'].value = True + assert not fig1d.canvas.dims + assert len(fig1d.artists) == 0 + fig2d.toolbar['inspect']._tool.click(10, 10) + assert fig1d.canvas.dims == {'x': da.dims[-1]} + assert len(fig1d.artists) == 1 + fig2d.toolbar['inspect']._tool.click(20, 15) + assert len(fig1d.artists) == 2 + + +def test_line_removal(use_ipympl): + da = pp.data.data3d() + ip = pp.inspector(da) + fig2d = ip[0][0] + fig1d = ip[0][1] + fig2d.toolbar['inspect'].value = True + assert not fig1d.canvas.dims + assert len(fig1d.artists) == 0 + fig2d.toolbar['inspect']._tool.click(10, 10) + assert fig1d.canvas.dims == {'x': da.dims[-1]} + assert len(fig1d.artists) == 1 + fig2d.toolbar['inspect']._tool.click(20, 15) + assert len(fig1d.artists) == 2 + fig2d.toolbar['inspect']._tool.remove(1) + assert len(fig1d.artists) == 1 + fig2d.toolbar['inspect']._tool.remove(0) + assert len(fig1d.artists) == 0 + + +def test_operation(use_ipympl): + da = pp.data.data3d() + ip_sum = pp.inspector(da, operation='sum') + ip_mean = pp.inspector(da, operation='mean') + assert ip_sum[0][0]._view.colormapper.vmax > ip_mean[0][0]._view.colormapper.vmax + assert ip_sum[0][0]._view.colormapper.vmin < ip_mean[0][0]._view.colormapper.vmin