summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2017-10-19 13:45:35 +0200
committerGitHub <noreply@github.com>2017-10-19 13:45:35 +0200
commit69c29f0522fe118262c813005590fbb256dfd679 (patch)
tree657e1850541f513dcc269b4f60b0c5968f39e49b /tests
parent7c9d627eb90002a9f437e6a95f51c16649dadd17 (diff)
downloadpyasn1-git-69c29f0522fe118262c813005590fbb256dfd679.tar.gz
Constructed types schema inspection (#87)
* the `instantiate=True` parameter added to constructed types .getComponentBy*() * Choice.clear() fixed to fully reset its internal state
Diffstat (limited to 'tests')
-rw-r--r--tests/type/test_univ.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/type/test_univ.py b/tests/type/test_univ.py
index c40b512..166af44 100644
--- a/tests/type/test_univ.py
+++ b/tests/type/test_univ.py
@@ -1012,6 +1012,21 @@ class SequenceOf(BaseTestCase):
assert n == o
+
+ def testGetComponentNoInstantiation(self):
+
+ class SequenceOf(univ.SequenceOf):
+ componentType = univ.OctetString()
+
+ s = SequenceOf()
+ assert s.getComponentByPosition(0, instantiate=False) is univ.noValue
+ s[0] = 'test'
+ assert s.getComponentByPosition(0, instantiate=False) is not univ.noValue
+ assert s.getComponentByPosition(0, instantiate=False) == str2octs('test')
+ s.clear()
+ assert s.getComponentByPosition(0, instantiate=False) is univ.noValue
+
+
class Sequence(BaseTestCase):
def setUp(self):
BaseTestCase.setUp(self)
@@ -1214,6 +1229,24 @@ class Sequence(BaseTestCase):
s['name'] = 'abc'
assert s['name'] == str2octs('abc')
+ def testGetComponentNoInstantiation(self):
+
+ class Sequence(univ.Sequence):
+ componentType = namedtype.NamedTypes(
+ namedtype.NamedType('name', univ.OctetString('')),
+ namedtype.OptionalNamedType('nick', univ.OctetString()),
+ )
+
+ s = Sequence()
+ assert s[0] == str2octs('')
+ assert s.getComponentByPosition(1, instantiate=False) is univ.noValue
+ assert s.getComponentByName('nick', instantiate=False) is univ.noValue
+ s[1] = 'test'
+ assert s.getComponentByPosition(1, instantiate=False) is not univ.noValue
+ assert s.getComponentByPosition(1, instantiate=False) == str2octs('test')
+ s.clear()
+ assert s.getComponentByPosition(1, instantiate=False) is univ.noValue
+
class SequenceWithoutSchema(BaseTestCase):
@@ -1390,6 +1423,25 @@ class Set(BaseTestCase):
s['name'] = 'abc'
assert s['name'] == str2octs('abc')
+ def testGetComponentNoInstantiation(self):
+
+ class Set(univ.Set):
+ componentType = namedtype.NamedTypes(
+ namedtype.NamedType('id', univ.Integer(123)),
+ namedtype.OptionalNamedType('nick', univ.OctetString()),
+ )
+
+ s = Set()
+ assert s[0] == 123
+ assert s.getComponentByPosition(1, instantiate=False) is univ.noValue
+ assert s.getComponentByName('nick', instantiate=False) is univ.noValue
+ assert s.getComponentByType(univ.OctetString.tagSet, instantiate=False) is univ.noValue
+ s[1] = 'test'
+ assert s.getComponentByPosition(1, instantiate=False) is not univ.noValue
+ assert s.getComponentByPosition(1, instantiate=False) == str2octs('test')
+ s.clear()
+ assert s.getComponentByPosition(1, instantiate=False) is univ.noValue
+
class Choice(BaseTestCase):
def setUp(self):
@@ -1516,6 +1568,27 @@ class Choice(BaseTestCase):
c.setComponentByType(univ.OctetString.tagSet, 'abc')
assert c.getName() == 'name'
+ def testGetComponentNoInstantiation(self):
+
+ s = univ.Choice(
+ componentType=namedtype.NamedTypes(
+ namedtype.NamedType('name', univ.OctetString()),
+ namedtype.NamedType('id', univ.Integer())
+ )
+ )
+
+ assert s.getComponentByPosition(0, instantiate=False) is univ.noValue
+ assert s.getComponentByPosition(1, instantiate=False) is univ.noValue
+ assert s.getComponentByName('name', instantiate=False) is univ.noValue
+ assert s.getComponentByName('id', instantiate=False) is univ.noValue
+ assert s.getComponentByType(univ.OctetString.tagSet, instantiate=False) is univ.noValue
+ assert s.getComponentByType(univ.Integer.tagSet, instantiate=False) is univ.noValue
+ s[1] = 123
+ assert s.getComponentByPosition(1, instantiate=False) is not univ.noValue
+ assert s.getComponentByPosition(1, instantiate=False) == 123
+ s.clear()
+ assert s.getComponentByPosition(1, instantiate=False) is univ.noValue
+
suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])