Browse Source

_write_event: added missing unit test for temp file cleanup

Fabian Peter Hammerle 4 years ago
parent
commit
818dcf2d0a
1 changed files with 12 additions and 0 deletions
  1. 12 0
      tests/vdir_test.py

+ 12 - 0
tests/vdir_test.py

@@ -16,7 +16,9 @@
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 import copy
+import os
 import pathlib
+import unittest.mock
 
 import icalendar.cal
 import pytest
@@ -49,6 +51,16 @@ END:VEVENT
 # pylint: disable=protected-access
 
 
+def test__write_event_cleanup(tmpdir):
+    event = icalendar.cal.Event.from_ical(_SINGLE_EVENT_ICAL)
+    with unittest.mock.patch("os.unlink") as unlink_mock:
+        with pytest.raises(IsADirectoryError):
+            ical2vdir._write_event(event, pathlib.Path(tmpdir))
+    unlink_mock.assert_called_once()
+    unlink_args, _ = unlink_mock.call_args
+    os.unlink(unlink_args[0])
+
+
 @pytest.mark.parametrize(
     ("event_ical", "expected_filename"),
     [