Test Spines and SpinesProxy in isolation.
()
| 7 | |
| 8 | |
| 9 | def 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') |