66from synapse .api .channel_pb2 import Channel
77from synapse .utils .ndtp_types import ElectricalBroadbandData
88
9+
910@pytest .mark .asyncio
1011async def test_broadband_source_data_generation ():
1112 node = BroadbandSource (id = 1 )
12-
13+
1314 config = BroadbandSourceConfig (
1415 peripheral_id = 1 ,
1516 bit_width = 12 ,
@@ -19,56 +20,55 @@ async def test_broadband_source_data_generation():
1920 electrode = ElectrodeConfig (
2021 channels = [
2122 Channel (id = 1 , electrode_id = 2 , reference_id = 3 ),
22- Channel (id = 2 , electrode_id = 3 , reference_id = 4 )
23+ Channel (id = 2 , electrode_id = 3 , reference_id = 4 ),
2324 ],
2425 low_cutoff_hz = 500.0 ,
25- high_cutoff_hz = 6000.0
26+ high_cutoff_hz = 6000.0 ,
2627 )
27- )
28+ ),
2829 )
29-
30+
3031 status = node .configure (config )
32+ node .configure_iface_ip ("127.0.0.1" )
3133 assert status .ok ()
3234
3335 data_received = []
3436
3537 async def collect_data (_ , data ):
3638 data_received .append (data )
3739
38- node .add_downstream_node (type ('' , (), {' on_data_received' : collect_data })())
39-
40+ node .add_downstream_node (type ("" , (), {" on_data_received" : collect_data })())
41+
4042 status = node .start ()
4143 assert status .ok ()
42-
44+
4345 await asyncio .sleep (1 )
44-
45- status = node .stop ()
46+
47+ status = node .stop ()
4648 assert status .ok ()
4749
4850 assert len (data_received ) > 0
49-
51+
5052 first_packet = data_received [0 ]
5153 assert isinstance (first_packet , ElectricalBroadbandData )
5254 assert first_packet .bit_width == 12
5355 assert first_packet .sample_rate == 30000
5456 assert not first_packet .is_signed
5557 assert len (first_packet .samples ) == 2
56-
58+
5759 for channel_id , samples in first_packet .samples :
5860 assert channel_id in [1 , 2 ]
5961 for sample in samples :
6062 assert 0 <= sample < 2 ** 12
6163
64+
6265def test_broadband_source_invalid_config ():
6366 node = BroadbandSource (id = 1 )
64-
67+
6568 config = BroadbandSourceConfig (
66- peripheral_id = 1 ,
67- bit_width = 12 ,
68- sample_rate_hz = 30000 ,
69- gain = 20.0
69+ peripheral_id = 1 , bit_width = 12 , sample_rate_hz = 30000 , gain = 20.0
7070 )
71-
71+
7272 status = node .configure (config )
7373 assert status .ok ()
7474 assert not node .running
@@ -79,14 +79,10 @@ def test_broadband_source_invalid_config():
7979 sample_rate_hz = 30000 ,
8080 gain = 20.0 ,
8181 signal = SignalConfig (
82- electrode = ElectrodeConfig (
83- low_cutoff_hz = 500.0 ,
84- high_cutoff_hz = 6000.0
85- )
86- )
82+ electrode = ElectrodeConfig (low_cutoff_hz = 500.0 , high_cutoff_hz = 6000.0 )
83+ ),
8784 )
88-
85+
8986 status = node .configure (config )
9087 assert status .ok ()
9188 assert not node .running
92-
0 commit comments