02-section.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import sys
  2. import pathlib
  3. test_file = pathlib.Path(__file__).absolute()
  4. test_dir = test_file.parent
  5. project_dir = test_dir.parent
  6. source_dir = project_dir / "src"
  7. sys.path.append(str(source_dir))
  8. import CxPini as pini
  9. first = pini.key()
  10. first.name = "first"
  11. first.value = 10
  12. second = pini.key()
  13. second.name = "other"
  14. second.value = "This is other key"
  15. last = pini.key()
  16. last.name = "last"
  17. last.value = 20
  18. last.comment = "And with comment"
  19. sample = pini.section()
  20. sample.add_comment("This is very basic library. ")
  21. sample.add_comment("It could be used as very very very nice. ")
  22. sample.add_comment("It is possible to split this very long comments auto.")
  23. sample.add_comment("I think it is very nice. You have not to do it Yourself.")
  24. sample.name = "Section"
  25. sample.add(first)
  26. sample.add(second)
  27. sample.add(last)
  28. print(sample)
  29. if sample.get("first").value != 10:
  30. print("Can not get first.")
  31. if not sample.exists("other"):
  32. print("Second can not be found.")
  33. if sample.get("last").value != 20:
  34. print("Last return bad content.")
  35. if sample.exists("jiojoijio"):
  36. print("Key which not exists is returned.")
  37. sample.drop(last)
  38. sample.drop("other")
  39. print(sample)