preproc_test.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import os, sys
  2. sys.path.append(os.path.split(os.path.realpath(__file__))[0] + "/../lib")
  3. from cnstream import *
  4. from cnstream_cpptest import *
  5. # in order to determine whether the python function is called by cpp
  6. init_called = False
  7. execute_called = False
  8. preproc_params = None
  9. class CustomPreproc(Preproc):
  10. def __init__(self):
  11. Preproc.__init__(self)
  12. def init(self, params):
  13. global init_called
  14. global preproc_params
  15. init_called = True
  16. preproc_params = params
  17. return True
  18. def execute(self, input_shapes, finfo):
  19. global execute_called
  20. execute_called = True
  21. results = []
  22. # the shape of return value must be equal to input_shapes
  23. for sp in input_shapes:
  24. data_count = 1
  25. for i in range(len(sp) - 1):
  26. data_count *= sp[i]
  27. results.append(range(data_count))
  28. return results
  29. class TestPreproc:
  30. def test_init(self):
  31. params = {'pyclass_name' : 'test.preproc_test.CustomPreproc', 'param' : 'value'}
  32. assert cpptest_pypreproc(params)
  33. # test cpp call python init function success
  34. assert init_called
  35. # test custom parameters from cpp pass to python success
  36. assert preproc_params['param'] == 'value'
  37. # test cpp call python execute function success
  38. assert execute_called