frame_test.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. class TestCNFrameInfo():
  6. def test_frame_info(self):
  7. stream_id = "stream_id_0"
  8. frame = CNFrameInfo(stream_id)
  9. ts = 1000
  10. frame.timestamp = ts
  11. assert not frame.is_eos()
  12. assert not frame.is_removed()
  13. assert not frame.is_invalid()
  14. assert stream_id == frame.stream_id
  15. assert ts == frame.timestamp
  16. # eos frame
  17. frame = CNFrameInfo(stream_id, True)
  18. assert frame.is_eos()
  19. def test_py_collection(self):
  20. class userData:
  21. def add(self, a ,b):
  22. return a + b
  23. # frame info created in cpp
  24. cpp_test_helper = CppCNFrameInfoTestHelper()
  25. frame = cpp_test_helper.get_frame_info()
  26. # pyCollection
  27. user_dict = frame.get_py_collection()
  28. # insert data to pyCollection
  29. user_dict[1] = "hi"
  30. user_dict["name"] = "cns"
  31. user_dict["user_data"] = userData()
  32. # get data from pyCollection
  33. user_dict = frame.get_py_collection()
  34. assert len(frame.get_py_collection().keys()) == 3
  35. assert user_dict[1] == frame.get_py_collection()[1]
  36. assert user_dict["name"] == frame.get_py_collection()["name"]
  37. assert user_dict["user_data"] == frame.get_py_collection()["user_data"]
  38. assert 3 == frame.get_py_collection()["user_data"].add(1, 2)
  39. # delete a key-value from pyCollection
  40. del user_dict["user_data"]
  41. assert len(frame.get_py_collection().keys()) == 2
  42. assert not "user_data" in frame.get_py_collection().keys()
  43. # clear pyCollection
  44. user_dict.clear()
  45. assert len(frame.get_py_collection().keys()) == 0
  46. # add a key-value to pyCollection
  47. user_dict["age"] = 25
  48. assert "age" in frame.get_py_collection()
  49. assert frame.get_py_collection()["age"] == 25
  50. user_dict = None
  51. assert "age" in frame.get_py_collection()
  52. assert frame.get_py_collection()["age"] == 25