cli_test.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import io
  2. import pathlib
  3. import subprocess
  4. import unittest.mock
  5. import icalendar
  6. import ics2vdir
  7. # pylint: disable=protected-access
  8. def test_entrypoint_help():
  9. subprocess.run(["ics2vdir", "--help"], check=True, stdout=subprocess.PIPE)
  10. def test__main_create(
  11. temp_dir_path: pathlib.Path, google_calendar_file: io.BufferedReader
  12. ):
  13. with unittest.mock.patch("sys.stdin", google_calendar_file):
  14. with unittest.mock.patch("sys.argv", ["", "--output-dir", str(temp_dir_path)]):
  15. ics2vdir._main()
  16. created_item_paths = sorted(temp_dir_path.iterdir())
  17. assert [p.name for p in created_item_paths] == [
  18. "1234567890qwertyuiopasdfgh@google.com.ics",
  19. "recurr1234567890qwertyuiop@google.com.20150908T090000+0200.ics",
  20. "recurr1234567890qwertyuiop@google.com.20150924T090000+0200.ics",
  21. ]
  22. event = icalendar.cal.Event.from_ical(created_item_paths[1].read_bytes())
  23. assert isinstance(event, icalendar.cal.Event)
  24. assert event["UID"] == "recurr1234567890qwertyuiop@google.com"
  25. assert event["SUMMARY"] == "recurring"