MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_spine_class

Function test_spine_class

lib/matplotlib/tests/test_spines.py:9–55  ·  view source on GitHub ↗

Test Spines and SpinesProxy in isolation.

()

Source from the content-addressed store, hash-verified

7
8
9def test_spine_class():
10 """Test Spines and SpinesProxy in isolation."""
11 class SpineMock:
12 def __init__(self):
13 self.val = None
14
15 def set(self, **kwargs):
16 vars(self).update(kwargs)
17
18 def set_val(self, val):
19 self.val = val
20
21 spines_dict = {
22 'left': SpineMock(),
23 'right': SpineMock(),
24 'top': SpineMock(),
25 'bottom': SpineMock(),
26 }
27 spines = Spines(**spines_dict)
28
29 assert spines['left'] is spines_dict['left']
30 assert spines.left is spines_dict['left']
31
32 spines[['left', 'right']].set_val('x')
33 assert spines.left.val == 'x'
34 assert spines.right.val == 'x'
35 assert spines.top.val is None
36 assert spines.bottom.val is None
37
38 spines[:].set_val('y')
39 assert all(spine.val == 'y' for spine in spines.values())
40
41 spines[:].set(foo='bar')
42 assert all(spine.foo == 'bar' for spine in spines.values())
43
44 with pytest.raises(AttributeError, match='foo'):
45 spines.foo
46 with pytest.raises(KeyError, match='foo'):
47 spines['foo']
48 with pytest.raises(KeyError, match='foo, bar'):
49 spines[['left', 'foo', 'right', 'bar']]
50 with pytest.raises(ValueError, match='single list'):
51 spines['left', 'right']
52 with pytest.raises(ValueError, match='Spines does not support slicing'):
53 spines['left':'right']
54 with pytest.raises(ValueError, match='Spines does not support slicing'):
55 spines['top':]
56
57
58@image_comparison(['spines_axes_positions.png'], style='mpl20')

Callers

nothing calls this directly

Calls 5

SpinesClass · 0.90
SpineMockClass · 0.85
valuesMethod · 0.80
set_valMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…