Test that the axes domains are updated correctly when a figure is first drawn
()
| 23 | |
| 24 | @requires_application() |
| 25 | def test_plot_widget_axes(): |
| 26 | """Test that the axes domains are updated correctly when a figure is first drawn""" |
| 27 | fig = vp.Fig(size=(800, 800), show=False) |
| 28 | point = (0, 100) |
| 29 | fig[0, 0].plot((point, point)) |
| 30 | # mocking the AxisVisual domain.setter |
| 31 | domain_setter = mock.Mock(wraps=AxisVisual.domain.fset) |
| 32 | mock_property = AxisVisual.domain.setter(domain_setter) |
| 33 | |
| 34 | with mock.patch.object(AxisVisual, "domain", mock_property): |
| 35 | # note: fig.show() must be called for this test to work... otherwise |
| 36 | # Grid._update_child_widget_dim is not triggered and the axes aren't updated |
| 37 | fig.show(run=False) |
| 38 | # currently, the AxisWidget adds a buffer of 5% of the |
| 39 | # full range to either end of the axis domain |
| 40 | buffer = (point[1] - point[0]) * 0.05 |
| 41 | expectation = [point[0] - buffer, point[1] + buffer] |
| 42 | for call in domain_setter.call_args_list: |
| 43 | assert [round(x, 2) for x in call[0][1]] == expectation |
| 44 | |
| 45 | |
| 46 | run_tests_if_main() |