]> Cypherpunks.ru repositories - pyderasn.git/blobdiff - tests/test_pyderasn.py
Fix test failing on Windows: it does not support negative timestamps
[pyderasn.git] / tests / test_pyderasn.py
index 8225fc02eaef4be07fc42093a3f28e4cbc88b933..c6621c94bb8eb467fbc60f461c9abe3e5b7dc642 100644 (file)
@@ -33,6 +33,7 @@ from time import mktime
 from time import time
 from unittest import TestCase
 
+from dateutil.tz import UTC
 from hypothesis import assume
 from hypothesis import given
 from hypothesis import settings
@@ -4494,8 +4495,13 @@ class TestGeneralizedTime(TimeMixin, CommonMixin, TestCase):
                 mktime(obj.todatetime().timetuple()),
                 mktime(dt.timetuple()),
             )
-        elif not PY2:
-            self.assertEqual(obj.todatetime().timestamp(), dt.timestamp())
+        else:
+            try:
+                obj.todatetime().timestamp()
+            except:
+                pass
+            else:
+                self.assertEqual(obj.todatetime().timestamp(), dt.timestamp())
         self.assertEqual(obj.ber_encoded, not dered)
         self.assertEqual(obj.bered, not dered)
         self.assertEqual(obj.ber_raw, None if dered else data)
@@ -4727,6 +4733,10 @@ class TestGeneralizedTime(TimeMixin, CommonMixin, TestCase):
             with self.assertRaises(DecodeError):
                 GeneralizedTime(data)
 
+    def test_aware(self):
+        with assertRaisesRegex(self, ValueError, "only naive"):
+            GeneralizedTime(datetime(2000, 1, 1, 1, tzinfo=UTC))
+
 
 class TestUTCTime(TimeMixin, CommonMixin, TestCase):
     base_klass = UTCTime
@@ -5060,6 +5070,10 @@ class TestUTCTime(TimeMixin, CommonMixin, TestCase):
                 junk
             )
 
+    def test_aware(self):
+        with assertRaisesRegex(self, ValueError, "only naive"):
+            UTCTime(datetime(2000, 1, 1, 1, tzinfo=UTC))
+
 
 @composite
 def tlv_value_strategy(draw):