<commit_before>import datetime

from exchangelib.errors import ErrorInvalidOperation, ErrorItemNotFound
from exchangelib.ewsdatetime import UTC
from exchangelib.folders import Calendar
from exchangelib.items import CalendarItem, BulkCreateResult
from exchangelib.items.calendar_item import SINGLE, OCCURRENCE, EXCEPTION, RECURRING_MASTER
from exchangelib.recurrence import Recurrence, DailyPattern, Occurrence, FirstOccurrence, LastOccurrence, \
    DeletedOccurrence

from ..common import get_random_string, get_random_datetime_range, get_random_date
from .test_basics import CommonItemTest


class CalendarTest(CommonItemTest):
    TEST_FOLDER = 'calendar'
    FOLDER_CLASS = Calendar
    ITEM_CLASS = CalendarItem

    def match_cat(self, i):
        return set(i.categories or []) == set(self.categories)

    def test_cancel(self):
        item = self.get_test_item().save()
        res = item.cancel()  # Returns (id, changekey) of cancelled item
        self.assertIsInstance(res, BulkCreateResult)
        with self.assertRaises(ErrorItemNotFound):
            # Item is already cancelled
            item.cancel()

    def test_updating_timestamps(self):
        # Test that we can update an item without changing anything, and maintain the hidden timezone fields as local
        # timezones, and that returned timestamps are in UTC.
        item = self.get_test_item()
        item.reminder_is_set = True<commit_msg>Don't try to match if this is an exception instance<commit_after>import datetime

from exchangelib.errors import ErrorInvalidOperation, ErrorItemNotFound
from exchangelib.ewsdatetime import UTC
from exchangelib.folders import Calendar
from exchangelib.items import CalendarItem, BulkCreateResult
from exchangelib.items.calendar_item import SINGLE, OCCURRENCE, EXCEPTION, RECURRING_MASTER
from exchangelib.recurrence import Recurrence, DailyPattern, Occurrence, FirstOccurrence, LastOccurrence, \
    DeletedOccurrence

from ..common import get_random_string, get_random_datetime_range, get_random_date
from .test_basics import CommonItemTest


class CalendarTest(CommonItemTest):
    TEST_FOLDER = 'calendar'
    FOLDER_CLASS = Calendar
    ITEM_CLASS = CalendarItem

    def match_cat(self, i):
        if isinstance(i, Exception):
            return False
        return set(i.categories or []) == set(self.categories)

    def test_cancel(self):
        item = self.get_test_item().save()
        res = item.cancel()  # Returns (id, changekey) of cancelled item
        self.assertIsInstance(res, BulkCreateResult)
        with self.assertRaises(ErrorItemNotFound):
            # Item is already cancelled
            item.cancel()

    def test_updating_timestamps(self):
        # Test that we can update an item without changing anything, and maintain the hidden timezone fields as local
        # timezones, and that returned timestamps are in UTC.
        item = self.get_test_item()
        item.reminder_is_set = True
{'fraction_non_alphanumeric': 0.06398104265402843, 'fraction_numerical': 0.0, 'mean_word_length': 3.949748743718593, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2634753', 'n_tokens_mistral': 859, 'n_tokens_neox': 825, 'n_words': 241}