Beispiel #1
0
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
Beispiel #2
0
 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)
Beispiel #3
0
 def test_none(self) -> None:
     self.assertIsNone(tzwrap.timezone(None))
Beispiel #4
0
 def test_wrong_tz(self) -> None:
     with self.assertRaises(tzwrap.UnknownTimeZoneError):
         tzwrap.timezone("ChozoPlanet")
Beispiel #5
0
 def test_shortcut(self) -> None:
     tz: str = "Africa/Monrovia"
     shortcut: str = "Monrovia"
     self.assertEqual(tzwrap.timezone(shortcut), pytz.timezone(tz))
Beispiel #6
0
 def test_classic(self) -> None:
     tz: str = "Africa/Monrovia"
     self.assertEqual(tzwrap.timezone(tz), pytz.timezone(tz))