]> Cypherpunks.ru repositories - pyderasn.git/blobdiff - tests/test_pyderasn.py
Split TestX690PrefixedType test cases
[pyderasn.git] / tests / test_pyderasn.py
index cd165b857a40b5d628e5839082895b3fdb33a18b..0fa0485ec9680cfe1261bb24dcafe6375d7bd3af 100644 (file)
@@ -60,6 +60,7 @@ from six import iterbytes
 from six import PY2
 from six import text_type
 from six import unichr as six_unichr
+from six.moves import xrange as six_xrange
 from six.moves.cPickle import dumps as pickle_dumps
 from six.moves.cPickle import HIGHEST_PROTOCOL as pickle_proto
 from six.moves.cPickle import loads as pickle_loads
@@ -6899,6 +6900,57 @@ class TestSequenceOf(SeqOfMixing, CommonMixin, TestCase):
         self.assertEqual(obj1, obj2)
         self.assertSequenceEqual(list(obj1), list(obj2))
 
+    def test_iterator_pickling(self):
+        class SeqOf(SequenceOf):
+            schema = Integer()
+        register_class(SeqOf)
+        seqof = SeqOf()
+        pickle_dumps(seqof)
+        seqof = seqof(iter(six_xrange(10)))
+        with assertRaisesRegex(self, ValueError, "iterator"):
+            pickle_dumps(seqof)
+
+    def test_iterator_bounds(self):
+        class SeqOf(SequenceOf):
+            schema = Integer()
+            bounds = (10, 20)
+        seqof = None
+        def gen(n):
+            for i in six_xrange(n):
+                yield Integer(i)
+        for n in (9, 21):
+            seqof = SeqOf(gen(n))
+            self.assertTrue(seqof.ready)
+            with self.assertRaises(BoundsError):
+                seqof.encode()
+            self.assertFalse(seqof.ready)
+            seqof = seqof(gen(n))
+            self.assertTrue(seqof.ready)
+            with self.assertRaises(BoundsError):
+                encode_cer(seqof)
+            self.assertFalse(seqof.ready)
+
+    def test_iterator_twice(self):
+        class SeqOf(SequenceOf):
+            schema = Integer()
+            bounds = (1, float("+inf"))
+        def gen():
+            for i in six_xrange(10):
+                yield Integer(i)
+        seqof = SeqOf(gen())
+        self.assertTrue(seqof.ready)
+        seqof.encode()
+        self.assertFalse(seqof.ready)
+        register_class(SeqOf)
+        pickle_dumps(seqof)
+
+    def test_non_ready_bound_min(self):
+        class SeqOf(SequenceOf):
+            schema = Integer()
+            bounds = (1, float("+inf"))
+        seqof = SeqOf()
+        self.assertFalse(seqof.ready)
+
 
 class TestSetOf(SeqOfMixing, CommonMixin, TestCase):
     class SeqOf(SetOf):
@@ -7513,11 +7565,13 @@ class TestStrictDefaultExistence(TestCase):
 
 
 class TestX690PrefixedType(TestCase):
-    def runTest(self):
+    def test_1(self):
         self.assertSequenceEqual(
             VisibleString("Jones").encode(),
             hexdec("1A054A6F6E6573"),
         )
+
+    def test_2(self):
         self.assertSequenceEqual(
             VisibleString(
                 "Jones",
@@ -7525,6 +7579,8 @@ class TestX690PrefixedType(TestCase):
             ).encode(),
             hexdec("43054A6F6E6573"),
         )
+
+    def test_3(self):
         self.assertSequenceEqual(
             Any(
                 VisibleString(
@@ -7535,6 +7591,8 @@ class TestX690PrefixedType(TestCase):
             ).encode(),
             hexdec("A20743054A6F6E6573"),
         )
+
+    def test_4(self):
         self.assertSequenceEqual(
             OctetString(
                 VisibleString(
@@ -7545,6 +7603,8 @@ class TestX690PrefixedType(TestCase):
             ).encode(),
             hexdec("670743054A6F6E6573"),
         )
+
+    def test_5(self):
         self.assertSequenceEqual(
             VisibleString("Jones", impl=tag_ctxp(2)).encode(),
             hexdec("82054A6F6E6573"),