test_neo.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. trigger_port = 'COM6'
  8. class TestNeo(unittest.TestCase):
  9. @classmethod
  10. def setUpClass(cls):
  11. config_info = settings.CONFIG_INFO
  12. cls.buffer_len = 1
  13. cls.receiver = NeuracleDataClient(n_channel=len(config_info['channel_labels']),
  14. samplerate=config_info['sample_rate'],
  15. buffer_len=cls.buffer_len)
  16. cls.trigger = TriggerNeuracle(port=trigger_port)
  17. @classmethod
  18. def tearDownClass(cls) -> None:
  19. cls.receiver.close()
  20. return super().tearDownClass()
  21. def test_is_active(self):
  22. self.assertTrue(self.receiver.is_active())
  23. def test_get_data(self):
  24. time.sleep(1)
  25. fs, event, data = self.receiver.get_trial_data(clear=True)
  26. self.assertTrue(data.shape[1] == settings.CONFIG_INFO['sample_rate'] * self.buffer_len)
  27. self.assertTrue(data.shape[0] == len(settings.CONFIG_INFO['channel_labels']) - 1)
  28. self.assertTrue(event.size == 0)
  29. def test_highpass(self):
  30. time.sleep(5)
  31. fs, event, data = self.receiver.get_trial_data(clear=True)
  32. self.assertTrue(np.mean(data) < 5e-5)
  33. def test_send_trigger_and_receive(self):
  34. time.sleep(1)
  35. for i in range(5):
  36. self.trigger.send_trigger(i+1)
  37. time.sleep(0.1)
  38. fs, event, data = self.receiver.get_trial_data(clear=True)
  39. print(event.shape)
  40. self.assertEqual(event.shape[0], 5)
  41. self.assertTrue(np.allclose(event[:, 2], np.arange(1, 6)))
  42. self.assertTrue(data.shape[1] == settings.CONFIG_INFO['sample_rate'] * self.buffer_len)