module_test.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. open_param = ""
  7. process_called = False
  8. close_called = False
  9. on_eos_called = False
  10. class CustomModule(Module):
  11. def __init__(self, name):
  12. Module.__init__(self, name)
  13. def open(self, params):
  14. global open_param
  15. open_param = params["param"]
  16. return True
  17. def close(self):
  18. global close_called
  19. close_called = True
  20. def process(self, data):
  21. global process_called
  22. process_called = True
  23. return 1
  24. def on_eos(self, stream_id):
  25. global on_eos_called
  26. on_eos_called = True
  27. class CustomModuleEx(ModuleEx):
  28. def __init__(self, name):
  29. ModuleEx.__init__(self, name)
  30. class TestModule:
  31. def test_transmit_permissions(self):
  32. module = CustomModule("test_module")
  33. assert not module.has_transmit()
  34. module = CustomModuleEx("test_module")
  35. assert module.has_transmit()
  36. def test_get_name(self):
  37. module = CustomModule("test_module")
  38. assert "test_module" == module.get_name()
  39. module = CustomModuleEx("test_module")
  40. assert "test_module" == module.get_name()
  41. def test_pymodule(self):
  42. global open_param
  43. global process_called
  44. global close_called
  45. global on_eos_called
  46. open_param = ""
  47. process_called = False
  48. close_called = False
  49. on_eos_called = False
  50. params = {"pyclass_name" : "test.module_test.CustomModule", "param" : "value"}
  51. assert cpptest_pymodule(params)
  52. assert "value" == open_param
  53. assert process_called
  54. assert close_called
  55. assert on_eos_called