001-message.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import pathlib
  2. test_file = pathlib.Path(__file__)
  3. test_dir = test_file.parent
  4. project_dir = test_dir.parent
  5. import sys
  6. sys.path.append(str(project_dir.absolute()))
  7. import source as communication
  8. def main():
  9. message = communication \
  10. .message_builder() \
  11. .set_key("test_key", "10") \
  12. .set_key("other", "20") \
  13. .set_key("in_section", "a", "sect") \
  14. .set_key("protocol", "https", "conn") \
  15. .set_key("ip", "10.0.0.1", "conn") \
  16. .build()
  17. def check_key(key: str, section: str | None, value: any) -> None:
  18. result = message.get_key(key, section) == value
  19. section = "default" if section is None else section
  20. if result:
  21. print("Work [" + section + "." + key + "]!")
  22. return
  23. print("Not work [" + section + "." + key + "]!")
  24. raise RuntimeError("Not property value!.")
  25. check_key("test_key", None, "10")
  26. check_key("other", None, "20")
  27. check_key("in_section", "sect", "a")
  28. check_key("protocol", "conn", "https")
  29. check_key("ip", "conn", "10.0.0.1")
  30. if __name__ == "__main__":
  31. main()