]> Cypherpunks.ru repositories - pyderasn.git/blobdiff - tests/test_pyderasn.py
Add `totzdatetime` method to UTCTime
[pyderasn.git] / tests / test_pyderasn.py
index 78448b86ca8eda107bf98829fab6f5db8031dc4d..f31967375c2f0e123051ebed97f071941ce22367 100644 (file)
@@ -32,7 +32,9 @@ from string import whitespace
 from time import mktime
 from time import time
 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
@@ -5062,6 +5064,17 @@ class TestUTCTime(TimeMixin, CommonMixin, TestCase):
         with self.assertRaisesRegex(ValueError, "only naive"):
             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",
+            ):
+                UTCTime(datetime.now()).totzdatetime()
+
+    def test_tzinfo_gives_datetime_with_tzutc_tzinfo(self):
+        self.assertEqual(UTCTime(datetime.now()).totzdatetime().tzinfo, tzutc())
+
 
 @composite
 def tlv_value_strategy(draw):