config_test.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import os, sys
  2. sys.path.append(os.path.split(os.path.realpath(__file__))[0] + "/../lib")
  3. from cnstream import *
  4. class TestConfig:
  5. def test_profiler_config(self):
  6. str = '{' \
  7. ' "enable_profiling" : true,' \
  8. ' "enable_tracing" : false,' \
  9. ' "trace_event_capacity" : 100' \
  10. '}'
  11. config = ProfilerConfig()
  12. assert config.parse_by_json_str(str)
  13. assert config.enable_profiling
  14. assert not config.enable_tracing
  15. assert 100 == config.trace_event_capacity
  16. def test_module_config(self):
  17. str = '{' \
  18. ' "class_name" : "test_class_name",' \
  19. ' "max_input_queue_size" : 200,' \
  20. ' "parallelism" : 100,' \
  21. ' "next_modules" : ["next1", "next2"],' \
  22. ' "custom_params" : {' \
  23. ' "param1" : "value1",' \
  24. ' "param2" : "value2"' \
  25. ' }' \
  26. '}'
  27. config = CNModuleConfig()
  28. assert config.parse_by_json_str(str)
  29. assert "test_class_name" == config.class_name
  30. assert 100 == config.parallelism
  31. assert 200 == config.max_input_queue_size
  32. assert "next1" in config.next
  33. assert "next2" in config.next
  34. assert "value1" == config.parameters["param1"]
  35. assert "value2" == config.parameters["param2"]
  36. def test_subgraph_config(self):
  37. str = '{' \
  38. ' "config_path" : "test_config_path",' \
  39. ' "next_modules" : ["next1", "next2"]' \
  40. '}'
  41. config = CNSubgraphConfig()
  42. assert config.parse_by_json_str(str)
  43. assert "test_config_path" == config.config_path
  44. assert "next1" in config.next
  45. assert "next2" in config.next
  46. def test_graph_config(self):
  47. str = '{' \
  48. ' "profiler_config" : {' \
  49. ' "enable_profiling" : true,' \
  50. ' "enable_tracing" : true' \
  51. ' },' \
  52. ' "module1": {' \
  53. ' "parallelism": 3,' \
  54. ' "max_input_queue_size": 20,' \
  55. ' "class_name": "test_class_name",' \
  56. ' "next_modules": ["subgraph:subgraph1"],' \
  57. ' "custom_params" : {' \
  58. ' "param" : "value"' \
  59. ' }' \
  60. ' },' \
  61. ' "subgraph:subgraph1" : {' \
  62. ' "config_path" : "test_config_file"' \
  63. ' }' \
  64. '}'
  65. config = CNGraphConfig()
  66. assert config.parse_by_json_str(str)
  67. assert config.profiler_config.enable_profiling
  68. assert config.profiler_config.enable_tracing
  69. assert 1 == len(config.module_configs)
  70. assert "module1" == config.module_configs[0].name
  71. assert 3 == config.module_configs[0].parallelism
  72. assert 20 == config.module_configs[0].max_input_queue_size
  73. assert "test_class_name" == config.module_configs[0].class_name
  74. assert "subgraph:subgraph1" in config.module_configs[0].next
  75. assert "value" == config.module_configs[0].parameters["param"]
  76. assert 1 == len(config.subgraph_configs)
  77. assert "subgraph:subgraph1" == config.subgraph_configs[0].name
  78. assert "test_config_file" == config.subgraph_configs[0].config_path
  79. def test_get_relative_path(self):
  80. module_params = {"json_file_dir" : "/home/"}
  81. relative_path = get_path_relative_to_config_file("test.data", module_params)
  82. assert "/home/test.data" == relative_path