Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

test_cbpy.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. """
  2. Test Module for CBPY
  3. Total of 4 tests that ensure that the correct library is being used to
  4. negotiate with the NSP, and that channel configuration is working properly.
  5. @Author: Ali Zaidi
  6. @Date: 18.09.2018
  7. """
  8. import time
  9. import unittest
  10. import cerebus.cbpy as cb
  11. class TestNSP(unittest.TestCase):
  12. @classmethod
  13. def setUp(self):
  14. self.channels = list(range(1, 97))
  15. def test_1_versionComptability(self):
  16. print("Testing version compatibility between NSP and CBSDK library")
  17. ver = cb.version()
  18. self.assertEqual(ver[1].get('major'), ver[1].get('nsp_major'))
  19. self.assertEqual(ver[1].get('minor'), ver[1].get('nsp_minor'))
  20. # def test_2_channelConfigWithDifferentSamplingRates(self):
  21. # print("Configuring 5 channels into different sampling groups")
  22. # for channel in self.channels:
  23. # res = cb.set_channel_config(channel, chaninfo={'smpgroup': channel})
  24. # # time.sleep(0.1)
  25. # cb.trial_config(reset=True, buffer_parameter={'continuous_length': 30001})
  26. # time.sleep(0.2)
  27. # dat = cb.trial_continuous(reset=True)
  28. # self.assertEqual(dat[1][0][2], 500)
  29. # self.assertEqual(dat[1][1][2], 1000)
  30. # self.assertEqual(dat[1][2][2], 2000)
  31. # self.assertEqual(dat[1][3][2], 10000)
  32. # self.assertEqual(dat[1][4][2], 30000)
  33. def test_3_channelConfigWith30kBufferSize(self):
  34. print("Configuring 96 channels at 30k and buffer size to 30000 samples")
  35. for channel in self.channels:
  36. res = cb.set_channel_config(channel, chaninfo={'smpgroup': 5})
  37. time.sleep(0.02)
  38. res = cb.trial_config(reset=True, buffer_parameter={'continuous_length': 30001})
  39. time.sleep(1.1)
  40. print("Ensuring channels return data with 30k samples")
  41. dat = cb.trial_continuous(reset=True)
  42. for channel in self.channels:
  43. self.assertEqual(len(dat[1][channel-1][1]), 30000)
  44. # def test_4_nChansReturned(self):
  45. # print("Ensuring only channels that have been configured return data")
  46. # cb.trial_config(reset=True)
  47. # time.sleep(1)
  48. # dat = cb.trial_continuous(reset=True)
  49. # self.assertEqual(len(dat[1]), 5)
  50. # def test_5_nspResponseTime(self):
  51. # import timeit
  52. # s = "cb.trial_data()"
  53. # time = timeit.timeit(stmt=s, number=10000, setup="from __main__ import cb")
  54. # self.assertLessEqual(time, 50.)
  55. # def test_6_wrongCommandToNsp(self):
  56. # with self.assertRaises(AttributeError):
  57. # res = cb.trial_cont()
  58. # def test_7_wrongParamtoNsp(self):
  59. # with self.assertRaises(TypeError):
  60. # res = cb.trial_config(reset=True, buffer_parameters={'continuous': 10000})
  61. # @classmethod
  62. # def tearDown(self):
  63. # pass
  64. if __name__ == '__main__':
  65. import sys
  66. print("\n\nSTARTING TEST SUITE \n\n")
  67. res = cb.open()
  68. print("NSP instance number = {}".format(res[0]))
  69. if res[0] <= 0:
  70. sys.exit("Could not connect to NSP! Please make sure NSP is online")
  71. unittest.main(verbosity=2)
  72. cb.close()