1
0

test_neo.py 1.8 KB

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