-
Notifications
You must be signed in to change notification settings - Fork 463
/
selector_test.py
68 lines (54 loc) · 2.33 KB
/
selector_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import bqplot
from unittest.mock import Mock
import numpy as np
from bqplot.traits import _array_equal
def test_brush_selector():
selector = bqplot.interacts.BrushSelector()
mock = Mock()
selector.observe(mock.on_selected, 'selected')
selector.observe(mock.on_selected_x, 'selected_x')
selector.observe(mock.on_selected_y, 'selected_y')
# should evaluate to false
assert not selector.selected_x
assert not selector.selected_y
assert not selector.selected
# test getter
selector.selected_x = [0, 1]
mock.on_selected_x.assert_called_once()
mock.on_selected_y.assert_not_called()
mock.on_selected.assert_not_called()
selector.selected_y = [1, 2]
mock.on_selected_x.assert_called_once()
mock.on_selected_y.assert_called_once()
mock.on_selected.assert_called_once()
assert selector.selected.tolist() == [[0, 1], [1, 2]]
# test setter
selector.selected = [[3, 4], [5, 6]]
assert selector.selected_x.tolist() == [3, 5]
assert selector.selected_y.tolist() == [4, 6]
selector.selected_x = None
assert selector.selected is None
assert selector.selected_x is None
assert selector.selected_y.tolist() == [4, 6]
selector.selected_y = None
assert selector.selected is None
assert selector.selected_x is None
assert selector.selected_y is None
selector.selected = [[np.nan, 4], [5, 6]]
assert _array_equal(selector.selected_x.tolist(), [np.nan, 5])
assert _array_equal(selector.selected_y.tolist(), [4, 6])
selector.selected = [[3, np.nan], [5, 6]]
assert _array_equal(selector.selected_x.tolist(), [3, 5])
assert _array_equal(selector.selected_y.tolist(), [np.nan, 6])
selector.selected = [3, 4], [5, 6]
assert _array_equal(selector.selected_x.tolist(), [3, 5])
assert _array_equal(selector.selected_y.tolist(), [4, 6])
selector.selected_x = [3, np.nan]
assert _array_equal(selector.selected_x.tolist(), [3, np.nan])
assert _array_equal(selector.selected_y.tolist(), [4, 6])
selector.selected = [3, 4], [5, 6]
assert _array_equal(selector.selected_x.tolist(), [3, 5])
assert _array_equal(selector.selected_y.tolist(), [4, 6])
selector.selected_y = [4, np.nan]
assert _array_equal(selector.selected_x.tolist(), [3, 5])
assert _array_equal(selector.selected_y.tolist(), [4, np.nan])