-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtest_controllers.py
94 lines (72 loc) · 3.5 KB
/
test_controllers.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import unittest
import numpy as np
from hdmf.common import DynamicTable, VectorData
from pynwb.ecephys import Device, ElectrodeGroup
from nwbwidgets.controllers import (
GroupAndSortController,
RangeController,
StartAndDurationController,
)
class FloatRangeControllerTestCase(unittest.TestCase):
def setUp(self):
self.range_controller = RangeController(vmin=0, vmax=10, start_value=(5, 7))
def test_move_range_slider_down_bigger(self):
self.range_controller.value = (4, 6)
self.range_controller.move_down("filler")
assert self.range_controller.value == (2, 4)
def test_move_range_slider_down_smaller(self):
self.range_controller.value = (2, 6)
self.range_controller.move_down("filler")
assert self.range_controller.value == (0, 4)
def test_move_range_slider_up_smaller(self):
self.range_controller.value = (5, 7)
self.range_controller.move_up("filler")
assert self.range_controller.value == (7, 9)
def test_move_range_slider_up_bigger(self):
self.range_controller.value = (5, 8)
self.range_controller.move_up("filler")
assert self.range_controller.value == (7, 10)
class TestGroupAndSortController(unittest.TestCase):
def setUp(self) -> None:
data1 = np.array([1, 2, 2, 3, 1, 1, 3, 2, 3])
data2 = np.array([3, 4, 2, 4, 3, 2, 2, 4, 4])
device = Device(name="device")
eg_1 = ElectrodeGroup(name="electrodegroup1", description="desc", location="brain", device=device)
eg_2 = ElectrodeGroup(name="electrodegroup2", description="desc", location="brain", device=device)
data3 = [eg_1, eg_2, eg_1, eg_1, eg_1, eg_1, eg_1, eg_1, eg_1]
vd1 = VectorData("Data1", "vector data for creating a DynamicTable", data=data1)
vd2 = VectorData("Data2", "vector data for creating a DynamicTable", data=data2)
vd3 = VectorData("ElectrodeGroup", "vector data for creating a DynamicTable", data=data3)
vd = [vd1, vd2, vd3]
self.dynamic_table = DynamicTable(
name="test table",
description="This is a test table",
columns=vd,
colnames=["Data1", "Data2", "ElectrodeGroup"],
)
def test_all_rows(self):
GroupAndSortController(dynamic_table=self.dynamic_table)
def test_keep_rows(self):
keep_rows = np.arange(len(self.dynamic_table) // 2)
GroupAndSortController(dynamic_table=self.dynamic_table, keep_rows=keep_rows)
def test_control(self):
gas = GroupAndSortController(dynamic_table=self.dynamic_table)
gas.group_dd.value = "Data1"
gas.group_dd.value = None
gas.order_dd.value = "Data1"
gas.order_dd.value = None
class TestStartAndDurationController(unittest.TestCase):
def setUp(self) -> None:
self.start_and_duration_controller = StartAndDurationController(10)
def test_set_duration(self):
self.start_and_duration_controller.duration.value = 2
def test_set_start(self):
self.start_and_duration_controller.slider.value = 4
def test_set_start_against_max(self):
self.start_and_duration_controller.slider.value = 9
assert self.start_and_duration_controller.slider.value == 5
def test_buttons(self):
self.start_and_duration_controller.to_end_button.click()
self.start_and_duration_controller.to_start_button.click()
self.start_and_duration_controller.forward_button.click()
self.start_and_duration_controller.backwards_button.click()