return what
try:
- from dateutil.tz import tzutc
+ from dateutil.tz import UTC as tzUTC
except ImportError: # pragma: no cover
- tzutc = None
+ tzUTC = "missing"
__version__ = "9.1"
return self._value
def totzdatetime(self):
- if tzutc is None:
+ try:
+ return self._value.replace(tzinfo=tzUTC)
+ except TypeError as err:
raise NotImplementedError(
"Package python-dateutil is required to use this feature",
- )
- return self._value.replace(tzinfo=tzutc())
+ ) from err
def __repr__(self):
return pp_console_row(next(self.pps()))
from unittest import TestCase
from unittest.mock import patch
-from dateutil.tz import tzutc
from dateutil.tz import UTC
from hypothesis import assume
from hypothesis import given
UTCTime(datetime(2000, 1, 1, 1, tzinfo=UTC))
def test_raises_if_no_dateutil(self):
- with patch("pyderasn.tzutc", new=None):
- with self.assertRaisesRegex(
- NotImplementedError,
- "Package python-dateutil is required to use this feature",
- ):
+ with patch("pyderasn.tzUTC", new="missing"):
+ with self.assertRaisesRegex(NotImplementedError, "dateutil"):
UTCTime(datetime.now()).totzdatetime()
def test_tzinfo_gives_datetime_with_tzutc_tzinfo(self):
- self.assertEqual(UTCTime(datetime.now()).totzdatetime().tzinfo, tzutc())
+ self.assertEqual(UTCTime(datetime.now()).totzdatetime().tzinfo, UTC)
@composite