test_neo.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import unittest
  2. import time
  3. import numpy as np
  4. from device.trigger_box import TriggerNeuracle
  5. from device.data_client import NeuracleDataClient
  6. from settings.config import settings
  7. class TestNeo(unittest.TestCase):
  8. @classmethod
  9. def setUpClass(cls):
  10. config_info = settings.CONFIG_INFO
  11. cls.receiver = NeuracleDataClient(n_channel=len(config_info['channel_labels']),
  12. samplerate=config_info['sample_rate'])
  13. cls.trigger = TriggerNeuracle()
  14. @classmethod
  15. def tearDownClass(cls) -> None:
  16. cls.receiver.close()
  17. return super().tearDownClass()
  18. def test_is_active(self):
  19. self.assertTrue(self.receiver.is_active())
  20. def test_get_data(self):
  21. time.sleep(1)
  22. fs, event, data = self.receiver.get_trial_data(clear=True)
  23. self.assertTrue(data.shape[1] == settings.CONFIG_INFO['sample_rate'] * self.receiver.BUFFER_LEN)
  24. self.assertTrue(data.shape[0] == len(settings.CONFIG_INFO['channel_labels']) - 1)
  25. self.assertTrue(event.size == 0)
  26. def test_send_trigger_and_receive(self):
  27. time.sleep(1)
  28. for i in range(5):
  29. self.trigger.send_trigger(i+1)
  30. time.sleep(0.1)
  31. fs, event, data = self.receiver.get_trial_data(clear=True)
  32. print(event.shape)
  33. self.assertTrue(event.shape[0] == 5)
  34. self.assertTrue(np.allclose(event[:, 2], np.arange(1, 6)))
  35. self.assertTrue(data.shape[1] == settings.CONFIG_INFO['sample_rate'] * self.receiver.BUFFER_LEN)