MCPcopy Create free account
hub / github.com/vispy/vispy / test_plot_widget_axes

Function test_plot_widget_axes

vispy/plot/tests/test_plot.py:25–43  ·  view source on GitHub ↗

Test that the axes domains are updated correctly when a figure is first drawn

()

Source from the content-addressed store, hash-verified

23
24@requires_application()
25def 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
46run_tests_if_main()

Callers

nothing calls this directly

Calls 3

setterMethod · 0.80
plotMethod · 0.45
showMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…