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
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):
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",
).encode(),
hexdec("43054A6F6E6573"),
)
+
+ def test_3(self):
self.assertSequenceEqual(
Any(
VisibleString(
).encode(),
hexdec("A20743054A6F6E6573"),
)
+
+ def test_4(self):
self.assertSequenceEqual(
OctetString(
VisibleString(
).encode(),
hexdec("670743054A6F6E6573"),
)
+
+ def test_5(self):
self.assertSequenceEqual(
VisibleString("Jones", impl=tag_ctxp(2)).encode(),
hexdec("82054A6F6E6573"),