def get_tz(where: Optional[str]) -> Optional[tzwrap.PyTzInfo]: """Returns the `pytz <https://pythonhosted.org/pytz/>`_'s :py:class:`tzinfo` associated with the string input :param where: The queried timezone found by the parse. Can be ``None``. :returns: The associated `pytz <https://pythonhosted.org/pytz/>`_'s :py:class:`tzinfo` if ``where`` is a valid timezone, ``None`` otherwise. """ timezone = None try: timezone = tzwrap.timezone(where) except tzwrap.UnknownTimeZoneError: pass return timezone
def test_missing_file(self, mopen: TMagicMock) -> None: logging.disable(logging.WARNING) mopen.side_effect = OSError() with self.assertRaises(pytz.UnknownTimeZoneError): print(tzwrap.timezone("Dublin")) logging.disable(logging.NOTSET)
def test_none(self) -> None: self.assertIsNone(tzwrap.timezone(None))
def test_wrong_tz(self) -> None: with self.assertRaises(tzwrap.UnknownTimeZoneError): tzwrap.timezone("ChozoPlanet")
def test_shortcut(self) -> None: tz: str = "Africa/Monrovia" shortcut: str = "Monrovia" self.assertEqual(tzwrap.timezone(shortcut), pytz.timezone(tz))
def test_classic(self) -> None: tz: str = "Africa/Monrovia" self.assertEqual(tzwrap.timezone(tz), pytz.timezone(tz))