003-decoder.py 908 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 = "\
  10. width=200\n\
  11. height=100\n\
  12. \n\
  13. [first]\n\
  14. my=iam\n\
  15. \n\
  16. [conn]\n\
  17. ip=dhcp\n\
  18. ssid=name\n\
  19. "
  20. result = communication.decoder(message).process().result()
  21. def check(key: str, value: str, section: str | None = None) -> None:
  22. if result.get_key(key, section) == value:
  23. print("Key " + key + " work.")
  24. return
  25. section = "default" if section is None else section
  26. print("Key " + key + " in section " + section + " NOT WORK.")
  27. check("width", "200")
  28. check("height", "100")
  29. check("my", "iam", "first")
  30. check("ip", "dhcp", "conn")
  31. check("ssid", "name", "conn")
  32. if __name__ == "__main__":
  33. main()