<commit_before>import datetime

import dateutil.tz
import pytz
import requests_mock
import warnings
try:
    import zoneinfo
except ImportError:
    from backports import zoneinfo

from exchangelib.errors import UnknownTimeZone, NaiveDateTimeNotAllowed
from exchangelib.ewsdatetime import EWSDateTime, EWSDate, EWSTimeZone, UTC
from exchangelib.winzone import generate_map, CLDR_TO_MS_TIMEZONE_MAP, CLDR_WINZONE_URL, CLDR_WINZONE_TYPE_VERSION, \
    CLDR_WINZONE_OTHER_VERSION
from exchangelib.util import CONNECTION_ERRORS

from .common import TimedTestCase


class EWSDateTimeTest(TimedTestCase):

    def test_super_methods(self):
        tz = EWSTimeZone('Europe/Copenhagen')
        self.assertIsInstance(EWSDateTime.now(), EWSDateTime)
        self.assertIsInstance(EWSDateTime.now(tz=tz), EWSDateTime)
        self.assertIsInstance(EWSDateTime.utcnow(), EWSDateTime)
        self.assertIsInstance(EWSDateTime.fromtimestamp(123456789), EWSDateTime)
        self.assertIsInstance(EWSDateTime.fromtimestamp(123456789, tz=tz), EWSDateTime)
        self.assertIsInstance(EWSDateTime.utcfromtimestamp(123456789), EWSDateTime)

    def test_ewstimezone(self):
        # Test autogenerated translations
        tz = EWSTimeZone('Europe/Copenhagen')
        self.assertIsInstance(tz, EWSTimeZone)
        self.assertEqual(tz.key, 'Europe/Copenhagen')
        self.assertEqual(tz.ms_id, 'Romance Standard Time')
        # self.assertEqual(EWSTimeZone('Europe/Copenhagen').ms_name, '')  # EWS works fine without the ms_name

        # Test localzone()
        tz = EWSTimeZone.localzone()
        self.assertIsInstance(tz, EWSTimeZone)

        # Test common helpers
        tz = EWSTimeZone('UTC')
        self.assertIsInstance(tz, EWSTimeZone)
        self.assertEqual(tz.key, 'UTC')
        self.assertEqual(tz.ms_id, 'UTC')
        tz = EWSTimeZone('GMT')
        self.assertIsInstance(tz, EWSTimeZone)
        self.assertEqual(tz.key, 'GMT')
        self.assertEqual(tz.ms_id, 'UTC')

        # Test mapper contents. Latest map from unicode.org has 394 entries
        self.assertGreater(len(EWSTimeZone.IANA_TO_MS_MAP), 300)
        for k, v in EWSTimeZone.IANA_TO_MS_MAP.items():
            self.assertIsInstance(k, str)
            self.assertIsInstance(v, tuple)
            self.assertEqual(len(v), 2)
            self.assertIsInstance(v[0], str)

        # Test IANA exceptions
        sanitized = list(t for t in zoneinfo.available_timezones() if not t.startswith('SystemV/') and t != 'localzone')
        self.assertEqual(set(sanitized) - set(EWSTimeZone.IANA_TO_MS_MAP), set())

        # Test timezone unknown by ZoneInfo
        with self.assertRaises(UnknownTimeZone) as e:
            EWSTimeZone('UNKNOWN')
        self.assertEqual(e.exception.args[0], 'No time zone found with key UNKNOWN')

        # Test timezone known by IANA but with no Winzone mapping
        with self.assertRaises(UnknownTimeZone) as e:
            del EWSTimeZone.IANA_TO_MS_MAP['Africa/Tripoli']
            EWSTimeZone('Africa/Tripoli')
        self.assertEqual(e.exception.args[0], 'No Windows timezone name found for timezone "Africa/Tripoli"')

        # Test __eq__ with non-EWSTimeZone compare
        self.assertFalse(EWSTimeZone('GMT') == zoneinfo.ZoneInfo('UTC'))

        # Test from_ms_id() with non-standard MS ID
        self.assertEqual(EWSTimeZone('Europe/Copenhagen'), EWSTimeZone.from_ms_id('Europe/Copenhagen'))

    def test_from_timezone(self):
        self.assertEqual(
            EWSTimeZone('Europe/Copenhagen'),
            EWSTimeZone.from_timezone(EWSTimeZone('Europe/Copenhagen'))<commit_msg>Fix spelling<commit_after>import datetime

import dateutil.tz
import pytz
import requests_mock
import warnings
try:
    import zoneinfo
except ImportError:
    from backports import zoneinfo

from exchangelib.errors import UnknownTimeZone, NaiveDateTimeNotAllowed
from exchangelib.ewsdatetime import EWSDateTime, EWSDate, EWSTimeZone, UTC
from exchangelib.winzone import generate_map, CLDR_TO_MS_TIMEZONE_MAP, CLDR_WINZONE_URL, CLDR_WINZONE_TYPE_VERSION, \
    CLDR_WINZONE_OTHER_VERSION
from exchangelib.util import CONNECTION_ERRORS

from .common import TimedTestCase


class EWSDateTimeTest(TimedTestCase):

    def test_super_methods(self):
        tz = EWSTimeZone('Europe/Copenhagen')
        self.assertIsInstance(EWSDateTime.now(), EWSDateTime)
        self.assertIsInstance(EWSDateTime.now(tz=tz), EWSDateTime)
        self.assertIsInstance(EWSDateTime.utcnow(), EWSDateTime)
        self.assertIsInstance(EWSDateTime.fromtimestamp(123456789), EWSDateTime)
        self.assertIsInstance(EWSDateTime.fromtimestamp(123456789, tz=tz), EWSDateTime)
        self.assertIsInstance(EWSDateTime.utcfromtimestamp(123456789), EWSDateTime)

    def test_ewstimezone(self):
        # Test autogenerated translations
        tz = EWSTimeZone('Europe/Copenhagen')
        self.assertIsInstance(tz, EWSTimeZone)
        self.assertEqual(tz.key, 'Europe/Copenhagen')
        self.assertEqual(tz.ms_id, 'Romance Standard Time')
        # self.assertEqual(EWSTimeZone('Europe/Copenhagen').ms_name, '')  # EWS works fine without the ms_name

        # Test localzone()
        tz = EWSTimeZone.localzone()
        self.assertIsInstance(tz, EWSTimeZone)

        # Test common helpers
        tz = EWSTimeZone('UTC')
        self.assertIsInstance(tz, EWSTimeZone)
        self.assertEqual(tz.key, 'UTC')
        self.assertEqual(tz.ms_id, 'UTC')
        tz = EWSTimeZone('GMT')
        self.assertIsInstance(tz, EWSTimeZone)
        self.assertEqual(tz.key, 'GMT')
        self.assertEqual(tz.ms_id, 'UTC')

        # Test mapper contents. Latest map from unicode.org has 394 entries
        self.assertGreater(len(EWSTimeZone.IANA_TO_MS_MAP), 300)
        for k, v in EWSTimeZone.IANA_TO_MS_MAP.items():
            self.assertIsInstance(k, str)
            self.assertIsInstance(v, tuple)
            self.assertEqual(len(v), 2)
            self.assertIsInstance(v[0], str)

        # Test IANA exceptions
        sanitized = list(t for t in zoneinfo.available_timezones() if not t.startswith('SystemV/') and t != 'localtime')
        self.assertEqual(set(sanitized) - set(EWSTimeZone.IANA_TO_MS_MAP), set())

        # Test timezone unknown by ZoneInfo
        with self.assertRaises(UnknownTimeZone) as e:
            EWSTimeZone('UNKNOWN')
        self.assertEqual(e.exception.args[0], 'No time zone found with key UNKNOWN')

        # Test timezone known by IANA but with no Winzone mapping
        with self.assertRaises(UnknownTimeZone) as e:
            del EWSTimeZone.IANA_TO_MS_MAP['Africa/Tripoli']
            EWSTimeZone('Africa/Tripoli')
        self.assertEqual(e.exception.args[0], 'No Windows timezone name found for timezone "Africa/Tripoli"')

        # Test __eq__ with non-EWSTimeZone compare
        self.assertFalse(EWSTimeZone('GMT') == zoneinfo.ZoneInfo('UTC'))

        # Test from_ms_id() with non-standard MS ID
        self.assertEqual(EWSTimeZone('Europe/Copenhagen'), EWSTimeZone.from_ms_id('Europe/Copenhagen'))

    def test_from_timezone(self):
        self.assertEqual(
            EWSTimeZone('Europe/Copenhagen'),
            EWSTimeZone.from_timezone(EWSTimeZone('Europe/Copenhagen'))
{'fraction_non_alphanumeric': 0.09547530095475301, 'fraction_numerical': 0.010239380102393801, 'mean_word_length': 3.4672435105067985, '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': '3069803', 'n_tokens_mistral': 2421, 'n_tokens_neox': 2247, 'n_words': 440}