diff options
author | Ilya Etingof <etingof@gmail.com> | 2019-08-25 15:17:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-25 15:17:38 +0200 |
commit | 41ce2e5cfeef488f847c3f58ff3d9d0fceb9ded7 (patch) | |
tree | 742135c2f6a578a45bac4850fb72f915f136e464 /tests | |
parent | 66afc8921e4f5d3a41e407ab6d95ce7e4ec5383a (diff) | |
download | pyasn1-41ce2e5cfeef488f847c3f58ff3d9d0fceb9ded7.tar.gz |
Deprecate `sizeSpec` in favor of `subtypeSpec` (#172)
This commit deprecates `subtypeSpec` attributes and keyword argument.
It is now recommended to pass `ValueSizeConstraint`, as well as all
other constraints, to `subtypeSpec`.
By way of the change mentioned above, this commit fixes a design bug
in a way of how the items assigned to constructed types are verified.
Now if `Asn1Type`-based object is assigned, its compatibility is
verified based on having all tags and constraint objects as the type
in field definition. When a bare Python value is assigned, then field
type object is cloned and initialized with the bare value (constraints
verificaton would run at this moment).
Diffstat (limited to 'tests')
-rw-r--r-- | tests/type/test_univ.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/tests/type/test_univ.py b/tests/type/test_univ.py index 4cbfa01..d9f921b 100644 --- a/tests/type/test_univ.py +++ b/tests/type/test_univ.py @@ -992,11 +992,13 @@ class SequenceOf(BaseTestCase): assert self.s1 == self.s2, '__cmp__() fails' def testSubtypeSpec(self): - s = self.s1.clone(subtypeSpec=constraint.ConstraintsUnion( - constraint.SingleValueConstraint(str2octs('abc')) - )) + s = self.s1.clone( + componentType=univ.OctetString().subtype( + subtypeSpec=constraint.SingleValueConstraint(str2octs('abc')))) try: - s.setComponentByPosition(0, univ.OctetString('abc')) + s.setComponentByPosition( + 0, univ.OctetString().subtype( + 'abc', subtypeSpec=constraint.SingleValueConstraint(str2octs('abc')))) except PyAsn1Error: assert 0, 'constraint fails' try: @@ -1006,7 +1008,7 @@ class SequenceOf(BaseTestCase): s.setComponentByPosition(1, univ.OctetString('Abc'), verifyConstraints=False) except PyAsn1Error: - assert 0, 'constraint failes with verifyConstraints=True' + assert 0, 'constraint fails with verifyConstraints=False' else: assert 0, 'constraint fails' @@ -1041,7 +1043,7 @@ class SequenceOf(BaseTestCase): pass def testConsistency(self): - s = self.s1.clone(sizeSpec=constraint.ConstraintsUnion( + s = self.s1.clone(subtypeSpec=constraint.ConstraintsUnion( constraint.ValueSizeConstraint(1, 1) )) s.setComponentByPosition(0, univ.OctetString('abc')) @@ -1057,15 +1059,13 @@ class SequenceOf(BaseTestCase): def testSubtype(self): subtype = self.s1.subtype( implicitTag=tag.Tag(tag.tagClassPrivate, tag.tagFormatSimple, 2), - subtypeSpec=constraint.SingleValueConstraint(1, 3), - sizeSpec=constraint.ValueSizeConstraint(0, 1) + subtypeSpec=constraint.ValueSizeConstraint(0, 1) ) subtype.clear() clone = self.s1.clone( tagSet=tag.TagSet(tag.Tag(tag.tagClassPrivate, tag.tagFormatSimple, 2)), - subtypeSpec=constraint.ConstraintsIntersection(constraint.SingleValueConstraint(1, 3)), - sizeSpec=constraint.ValueSizeConstraint(0, 1) + subtypeSpec=constraint.ValueSizeConstraint(0, 1) ) clone.clear() assert clone == subtype |