summaryrefslogtreecommitdiff
path: root/tests/type
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2017-08-31 19:26:06 +0200
committerIlya Etingof <etingof@gmail.com>2017-09-01 15:01:02 +0200
commit154f81e322439094bb2d5118de707f7586f3ea6d (patch)
tree99ed12d5a953daaef0d903485c5985394a71a28d /tests/type
parent976d8c90f5f0c8b22c43a13d8aa624c16fd5685a (diff)
downloadpyasn1-git-154f81e322439094bb2d5118de707f7586f3ea6d.tar.gz
schema-less SET/SEQUENCE dict duck-typing
Diffstat (limited to 'tests/type')
-rw-r--r--tests/type/test_univ.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/type/test_univ.py b/tests/type/test_univ.py
index 7d843a9..c9da0b2 100644
--- a/tests/type/test_univ.py
+++ b/tests/type/test_univ.py
@@ -1101,6 +1101,56 @@ class Sequence(unittest.TestCase):
assert s['name'] == str2octs('abc')
+class SequenceWithoutSchema(unittest.TestCase):
+
+ def testIter(self):
+ s = univ.Sequence()
+ s.setComponentByPosition(0, univ.OctetString('abc'))
+ s.setComponentByPosition(1, univ.Integer(123))
+ assert list(s) == ['field-0', 'field-1']
+
+ def testKeys(self):
+ s = univ.Sequence()
+ s.setComponentByPosition(0, univ.OctetString('abc'))
+ s.setComponentByPosition(1, univ.Integer(123))
+ assert list(s.keys()) == ['field-0', 'field-1']
+
+ def testValues(self):
+ s = univ.Sequence()
+ s.setComponentByPosition(0, univ.OctetString('abc'))
+ s.setComponentByPosition(1, univ.Integer(123))
+ assert list(s.values()) == [str2octs('abc'), 123]
+
+ def testItems(self):
+ s = univ.Sequence()
+ s.setComponentByPosition(0, univ.OctetString('abc'))
+ s.setComponentByPosition(1, univ.Integer(123))
+ assert list(s.items()) == [('field-0', str2octs('abc')), ('field-1', 123)]
+
+ def testUpdate(self):
+ s = univ.Sequence()
+ assert not s
+ s.setComponentByPosition(0, univ.OctetString('abc'))
+ s.setComponentByPosition(1, univ.Integer(123))
+ assert s
+ assert list(s.keys()) == ['field-0', 'field-1']
+ assert list(s.values()) == [str2octs('abc'), 123]
+ assert list(s.items()) == [('field-0', str2octs('abc')), ('field-1', 123)]
+ s['field-0'] = univ.OctetString('def')
+ assert list(s.values()) == [str2octs('def'), 123]
+ s['field-1'] = univ.OctetString('ghi')
+ assert list(s.values()) == [str2octs('def'), str2octs('ghi')]
+ try:
+ s['field-2'] = univ.OctetString('xxx')
+ except error.PyAsn1Error:
+ pass
+ else:
+ assert False, 'unknown field at schema-less object tolerated'
+ assert 'field-0' in s
+ s.clear()
+ assert 'field-0' not in s
+
+
class SetOf(unittest.TestCase):
def setUp(self):
self.s1 = univ.SetOf(componentType=univ.OctetString(''))