summaryrefslogtreecommitdiff
path: root/tests/codec/cer/test_encoder.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/codec/cer/test_encoder.py')
-rw-r--r--tests/codec/cer/test_encoder.py50
1 files changed, 32 insertions, 18 deletions
diff --git a/tests/codec/cer/test_encoder.py b/tests/codec/cer/test_encoder.py
index 7b0cc8c..32d87b0 100644
--- a/tests/codec/cer/test_encoder.py
+++ b/tests/codec/cer/test_encoder.py
@@ -5,18 +5,21 @@
# License: http://pyasn1.sf.net/license.html
#
import sys
+
try:
import unittest2 as unittest
except ImportError:
import unittest
+from tests.base import BaseTestCase
+
from pyasn1.type import namedtype, univ, useful
from pyasn1.codec.cer import encoder
from pyasn1.compat.octets import ints2octs
from pyasn1.error import PyAsn1Error
-class BooleanEncoderTestCase(unittest.TestCase):
+class BooleanEncoderTestCase(BaseTestCase):
def testTrue(self):
assert encoder.encode(univ.Boolean(1)) == ints2octs((1, 1, 255))
@@ -24,7 +27,7 @@ class BooleanEncoderTestCase(unittest.TestCase):
assert encoder.encode(univ.Boolean(0)) == ints2octs((1, 1, 0))
-class BitStringEncoderTestCase(unittest.TestCase):
+class BitStringEncoderTestCase(BaseTestCase):
def testShortMode(self):
assert encoder.encode(
univ.BitString((1, 0) * 5)
@@ -34,7 +37,7 @@ class BitStringEncoderTestCase(unittest.TestCase):
assert encoder.encode(univ.BitString((1, 0) * 501)) == ints2octs((3, 127, 6) + (170,) * 125 + (128,))
-class OctetStringEncoderTestCase(unittest.TestCase):
+class OctetStringEncoderTestCase(BaseTestCase):
def testShortMode(self):
assert encoder.encode(
univ.OctetString('Quick brown fox')
@@ -46,7 +49,7 @@ class OctetStringEncoderTestCase(unittest.TestCase):
) == ints2octs((36, 128, 4, 130, 3, 232) + (81,) * 1000 + (4, 1, 81, 0, 0))
-class GeneralizedTimeEncoderTestCase(unittest.TestCase):
+class GeneralizedTimeEncoderTestCase(BaseTestCase):
# def testExtraZeroInSeconds(self):
# try:
# assert encoder.encode(
@@ -104,7 +107,7 @@ class GeneralizedTimeEncoderTestCase(unittest.TestCase):
) == ints2octs((24, 13, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 90))
-class UTCTimeEncoderTestCase(unittest.TestCase):
+class UTCTimeEncoderTestCase(BaseTestCase):
def testFractionOfSecond(self):
try:
assert encoder.encode(
@@ -146,7 +149,7 @@ class UTCTimeEncoderTestCase(unittest.TestCase):
) == ints2octs((23, 11, 57, 57, 48, 56, 48, 49, 49, 50, 48, 49, 90))
-class SequenceOfEncoderTestCase(unittest.TestCase):
+class SequenceOfEncoderTestCase(BaseTestCase):
def testEmpty(self):
s = univ.SequenceOf()
assert encoder.encode(s) == ints2octs((48, 128, 0, 0))
@@ -176,8 +179,9 @@ class SequenceOfEncoderTestCase(unittest.TestCase):
assert encoder.encode(s) == ints2octs((48, 128, 4, 1, 97, 4, 1, 98, 0, 0))
-class SequenceOfEncoderWithSchemaTestCase(unittest.TestCase):
+class SequenceOfEncoderWithSchemaTestCase(BaseTestCase):
def setUp(self):
+ BaseTestCase.setUp(self)
self.s = univ.SequenceOf(componentType=univ.OctetString())
def testEmpty(self):
@@ -209,7 +213,7 @@ class SequenceOfEncoderWithSchemaTestCase(unittest.TestCase):
assert encoder.encode(self.s) == ints2octs((48, 128, 4, 1, 97, 4, 1, 98, 0, 0))
-class SetOfEncoderTestCase(unittest.TestCase):
+class SetOfEncoderTestCase(BaseTestCase):
def testEmpty(self):
s = univ.SetOf()
assert encoder.encode(s) == ints2octs((49, 128, 0, 0))
@@ -239,8 +243,9 @@ class SetOfEncoderTestCase(unittest.TestCase):
assert encoder.encode(s) == ints2octs((49, 128, 4, 1, 97, 4, 1, 98, 0, 0))
-class SetOfEncoderWithSchemaTestCase(unittest.TestCase):
+class SetOfEncoderWithSchemaTestCase(BaseTestCase):
def setUp(self):
+ BaseTestCase.setUp(self)
self.s = univ.SetOf(componentType=univ.OctetString())
def testEmpty(self):
@@ -276,8 +281,9 @@ class SetOfEncoderWithSchemaTestCase(unittest.TestCase):
assert encoder.encode(self.s) == ints2octs((49, 128, 4, 1, 97, 4, 1, 98, 0, 0))
-class SetEncoderTestCase(unittest.TestCase):
+class SetEncoderTestCase(BaseTestCase):
def setUp(self):
+ BaseTestCase.setUp(self)
self.s = univ.Set()
self.s.setComponentByPosition(0, univ.Null(''))
self.s.setComponentByPosition(1, univ.OctetString('quick brown'))
@@ -302,8 +308,9 @@ class SetEncoderTestCase(unittest.TestCase):
) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0))
-class SetEncoderWithSchemaTestCase(unittest.TestCase):
+class SetEncoderWithSchemaTestCase(BaseTestCase):
def setUp(self):
+ BaseTestCase.setUp(self)
self.s = univ.Set(componentType=namedtype.NamedTypes(
namedtype.NamedType('place-holder', univ.Null('')),
namedtype.OptionalNamedType('first-name', univ.OctetString()),
@@ -353,8 +360,9 @@ class SetEncoderWithSchemaTestCase(unittest.TestCase):
) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0))
-class SetWithChoiceWithSchemaEncoderTestCase(unittest.TestCase):
+class SetWithChoiceWithSchemaEncoderTestCase(BaseTestCase):
def setUp(self):
+ BaseTestCase.setUp(self)
c = univ.Choice(componentType=namedtype.NamedTypes(
namedtype.NamedType('actual', univ.Boolean(0))
))
@@ -370,8 +378,9 @@ class SetWithChoiceWithSchemaEncoderTestCase(unittest.TestCase):
assert encoder.encode(self.s) == ints2octs((49, 128, 1, 1, 255, 5, 0, 0, 0))
-class SetEncoderTestCase(unittest.TestCase):
+class SetEncoderTestCase(BaseTestCase):
def setUp(self):
+ BaseTestCase.setUp(self)
self.s = univ.Set()
self.s.setComponentByPosition(0, univ.Null(''))
self.s.setComponentByPosition(1, univ.OctetString('quick brown'))
@@ -396,8 +405,9 @@ class SetEncoderTestCase(unittest.TestCase):
) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0))
-class SequenceEncoderTestCase(unittest.TestCase):
+class SequenceEncoderTestCase(BaseTestCase):
def setUp(self):
+ BaseTestCase.setUp(self)
self.s = univ.Sequence()
self.s.setComponentByPosition(0, univ.Null(''))
self.s.setComponentByPosition(1, univ.OctetString('quick brown'))
@@ -422,8 +432,9 @@ class SequenceEncoderTestCase(unittest.TestCase):
) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0))
-class SequenceEncoderWithSchemaTestCase(unittest.TestCase):
+class SequenceEncoderWithSchemaTestCase(BaseTestCase):
def setUp(self):
+ BaseTestCase.setUp(self)
self.s = univ.Sequence(
componentType=namedtype.NamedTypes(
namedtype.NamedType('place-holder', univ.Null('')),
@@ -475,8 +486,9 @@ class SequenceEncoderWithSchemaTestCase(unittest.TestCase):
) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0))
-class NestedOptionalSequenceEncoderTestCase(unittest.TestCase):
+class NestedOptionalSequenceEncoderTestCase(BaseTestCase):
def setUp(self):
+ BaseTestCase.setUp(self)
inner = univ.Sequence(
componentType=namedtype.NamedTypes(
namedtype.OptionalNamedType('first-name', univ.OctetString()),
@@ -564,8 +576,9 @@ class NestedOptionalSequenceEncoderTestCase(unittest.TestCase):
assert encoder.encode(s) == ints2octs((48, 128, 48, 128, 2, 1, 123, 0, 0, 0, 0))
-class NestedOptionalChoiceEncoderTestCase(unittest.TestCase):
+class NestedOptionalChoiceEncoderTestCase(BaseTestCase):
def setUp(self):
+ BaseTestCase.setUp(self)
layer3 = univ.Sequence(
componentType=namedtype.NamedTypes(
namedtype.OptionalNamedType('first-name', univ.OctetString()),
@@ -625,8 +638,9 @@ class NestedOptionalChoiceEncoderTestCase(unittest.TestCase):
assert encoder.encode(s) == ints2octs((48, 128, 0, 0))
-class NestedOptionalSequenceOfEncoderTestCase(unittest.TestCase):
+class NestedOptionalSequenceOfEncoderTestCase(BaseTestCase):
def setUp(self):
+ BaseTestCase.setUp(self)
layer2 = univ.SequenceOf(
componentType=univ.OctetString()
)