diff options
author | Ilya Etingof <etingof@gmail.com> | 2019-06-29 08:50:35 +0200 |
---|---|---|
committer | Ilya Etingof <etingof@gmail.com> | 2019-06-29 09:24:35 +0200 |
commit | 4a9abf7ae867e9ebabc850320d87a7c1230acfad (patch) | |
tree | 98e32bd72e9a5054703a2c32a711a724d28c75b3 /tests | |
parent | fe2725f8c80039d9d82af2bd3299abc174417c27 (diff) | |
download | pyasn1-4a9abf7ae867e9ebabc850320d87a7c1230acfad.tar.gz |
Rename pyasn1 unicode exceptions
The new exception classes names are `PyAsn1UnicodeDecodeError`
and `PyAsn1UnicodeEncodeError`.
Also, unit tests added.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/type/test_univ.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/tests/type/test_univ.py b/tests/type/test_univ.py index 3cd125b..169b73e 100644 --- a/tests/type/test_univ.py +++ b/tests/type/test_univ.py @@ -22,8 +22,9 @@ from pyasn1.type import constraint from pyasn1.type import namedtype from pyasn1.type import namedval from pyasn1.type import error -from pyasn1.compat.octets import str2octs, ints2octs, octs2ints +from pyasn1.compat.octets import str2octs, ints2octs, octs2ints, octs2str from pyasn1.error import PyAsn1Error +from pyasn1.error import PyAsn1UnicodeEncodeError, PyAsn1UnicodeDecodeError class NoValueTestCase(BaseTestCase): @@ -543,6 +544,32 @@ class OctetStringWithAsciiTestCase(OctetStringWithUnicodeMixIn, BaseTestCase): encoding = 'us-ascii' +class OctetStringUnicodeErrorTestCase(BaseTestCase): + def testEncodeError(self): + text = octs2str(ints2octs((0xff, 0xfe))) + + try: + univ.OctetString(text, encoding='us-ascii') + + except PyAsn1UnicodeEncodeError: + pass + + else: + assert False, 'Unicode encoding error not caught' + + def testDecodeError(self): + serialized = ints2octs((0xff, 0xfe)) + + try: + str(univ.OctetString(serialized, encoding='us-ascii')) + + except PyAsn1UnicodeDecodeError: + pass + + else: + assert False, 'Unicode decoding error not caught' + + class OctetStringWithUtf8TestCase(OctetStringWithUnicodeMixIn, BaseTestCase): initializer = (208, 176, 208, 177, 208, 178) encoding = 'utf-8' |