diff options
author | Ilya Etingof <etingof@gmail.com> | 2019-11-23 09:57:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-23 09:57:24 +0100 |
commit | 2b646e07d5d83f0892fa2a809ae4c981430cb12c (patch) | |
tree | 20b10450bced84c425ca0735b4ee7202e68ee1ec /tests | |
parent | 788af3c44edc2ebd079eda3f7a4ae2f9931446fd (diff) | |
parent | f10434e31f9293c4e739ac6c5d1519f407bd1540 (diff) | |
download | pyasn1-git-2b646e07d5d83f0892fa2a809ae4c981430cb12c.tar.gz |
Merge branch 'master' into streamoptimum37
Diffstat (limited to 'tests')
29 files changed, 56 insertions, 267 deletions
diff --git a/tests/__main__.py b/tests/__main__.py index 14ef28a..5340b83 100644 --- a/tests/__main__.py +++ b/tests/__main__.py @@ -4,11 +4,7 @@ # Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com> # License: http://snmplabs.com/pyasn1/license.html # -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest suite = unittest.TestLoader().loadTestsFromNames( ['tests.test_debug.suite', diff --git a/tests/base.py b/tests/base.py index 07f06dc..1274049 100644 --- a/tests/base.py +++ b/tests/base.py @@ -4,12 +4,7 @@ # Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com> # License: http://snmplabs.com/pyasn1/license.html # - -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest from pyasn1 import debug diff --git a/tests/codec/__main__.py b/tests/codec/__main__.py index 9c2fc94..ec81462 100644 --- a/tests/codec/__main__.py +++ b/tests/codec/__main__.py @@ -4,11 +4,7 @@ # Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com> # License: http://snmplabs.com/pyasn1/license.html # -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest suite = unittest.TestLoader().loadTestsFromNames( ['tests.codec.test_streaming.suite', diff --git a/tests/codec/ber/__main__.py b/tests/codec/ber/__main__.py index 59c0c2b..a1e1b16 100644 --- a/tests/codec/ber/__main__.py +++ b/tests/codec/ber/__main__.py @@ -4,11 +4,7 @@ # Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com> # License: http://snmplabs.com/pyasn1/license.html # -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest suite = unittest.TestLoader().loadTestsFromNames( ['tests.codec.ber.test_encoder.suite', diff --git a/tests/codec/ber/test_decoder.py b/tests/codec/ber/test_decoder.py index 17483db..4e2a984 100644 --- a/tests/codec/ber/test_decoder.py +++ b/tests/codec/ber/test_decoder.py @@ -9,12 +9,8 @@ import io import os import sys import tempfile +import unittest import zipfile -try: - import unittest2 as unittest - -except ImportError: - import unittest from tests.base import BaseTestCase @@ -488,10 +484,9 @@ class RealDecoderTestCase(BaseTestCase): assert 0, 'accepted too-short real' -if sys.version_info[0:2] > (2, 5): - class UniversalStringDecoderTestCase(BaseTestCase): - def testDecoder(self): - assert decoder.decode(ints2octs((28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99))) == (char.UniversalString(sys.version_info[0] >= 3 and 'abc' or unicode('abc')), null) +class UniversalStringDecoderTestCase(BaseTestCase): + def testDecoder(self): + assert decoder.decode(ints2octs((28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99))) == (char.UniversalString(sys.version_info[0] >= 3 and 'abc' or unicode('abc')), null) class BMPStringDecoderTestCase(BaseTestCase): diff --git a/tests/codec/ber/test_encoder.py b/tests/codec/ber/test_encoder.py index b880285..49eb91d 100644 --- a/tests/codec/ber/test_encoder.py +++ b/tests/codec/ber/test_encoder.py @@ -5,12 +5,7 @@ # License: http://snmplabs.com/pyasn1/license.html # import sys - -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest from tests.base import BaseTestCase @@ -433,18 +428,17 @@ class RealEncoderWithSchemaTestCase(BaseTestCase): ) == ints2octs((9, 7, 3, 49, 50, 51, 69, 49, 49)) -if sys.version_info[0:2] > (2, 5): - class UniversalStringEncoderTestCase(BaseTestCase): - def testEncoding(self): - assert encoder.encode(char.UniversalString(sys.version_info[0] >= 3 and 'abc' or unicode('abc'))) == ints2octs( - (28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99)), 'Incorrect encoding' +class UniversalStringEncoderTestCase(BaseTestCase): + def testEncoding(self): + assert encoder.encode(char.UniversalString(sys.version_info[0] >= 3 and 'abc' or unicode('abc'))) == ints2octs( + (28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99)), 'Incorrect encoding' - class UniversalStringEncoderWithSchemaTestCase(BaseTestCase): - def testEncoding(self): - assert encoder.encode( - sys.version_info[0] >= 3 and 'abc' or unicode('abc'), asn1Spec=char.UniversalString() - ) == ints2octs((28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99)), 'Incorrect encoding' +class UniversalStringEncoderWithSchemaTestCase(BaseTestCase): + def testEncoding(self): + assert encoder.encode( + sys.version_info[0] >= 3 and 'abc' or unicode('abc'), asn1Spec=char.UniversalString() + ) == ints2octs((28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99)), 'Incorrect encoding' class BMPStringEncoderTestCase(BaseTestCase): diff --git a/tests/codec/cer/__main__.py b/tests/codec/cer/__main__.py index e3643a1..787d9d6 100644 --- a/tests/codec/cer/__main__.py +++ b/tests/codec/cer/__main__.py @@ -4,11 +4,7 @@ # Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com> # License: http://snmplabs.com/pyasn1/license.html # -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest suite = unittest.TestLoader().loadTestsFromNames( ['tests.codec.cer.test_encoder.suite', diff --git a/tests/codec/cer/test_decoder.py b/tests/codec/cer/test_decoder.py index d628061..ea435e1 100644 --- a/tests/codec/cer/test_decoder.py +++ b/tests/codec/cer/test_decoder.py @@ -5,11 +5,7 @@ # License: http://snmplabs.com/pyasn1/license.html # import sys - -try: - import unittest2 as unittest -except ImportError: - import unittest +import unittest from tests.base import BaseTestCase diff --git a/tests/codec/cer/test_encoder.py b/tests/codec/cer/test_encoder.py index ce26387..4535927 100644 --- a/tests/codec/cer/test_encoder.py +++ b/tests/codec/cer/test_encoder.py @@ -5,11 +5,7 @@ # License: http://snmplabs.com/pyasn1/license.html # import sys - -try: - import unittest2 as unittest -except ImportError: - import unittest +import unittest from tests.base import BaseTestCase diff --git a/tests/codec/der/__main__.py b/tests/codec/der/__main__.py index bfa4ee0..8099af2 100644 --- a/tests/codec/der/__main__.py +++ b/tests/codec/der/__main__.py @@ -4,11 +4,7 @@ # Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com> # License: http://snmplabs.com/pyasn1/license.html # -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest suite = unittest.TestLoader().loadTestsFromNames( ['tests.codec.der.test_encoder.suite', diff --git a/tests/codec/der/test_decoder.py b/tests/codec/der/test_decoder.py index 51ce296..e5b2663 100644 --- a/tests/codec/der/test_decoder.py +++ b/tests/codec/der/test_decoder.py @@ -5,12 +5,7 @@ # License: http://snmplabs.com/pyasn1/license.html # import sys - -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest from tests.base import BaseTestCase diff --git a/tests/codec/der/test_encoder.py b/tests/codec/der/test_encoder.py index 912e32c..6b8417b 100644 --- a/tests/codec/der/test_encoder.py +++ b/tests/codec/der/test_encoder.py @@ -5,12 +5,7 @@ # License: http://snmplabs.com/pyasn1/license.html # import sys - -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest from tests.base import BaseTestCase diff --git a/tests/codec/native/__main__.py b/tests/codec/native/__main__.py index 640f586..01308d8 100644 --- a/tests/codec/native/__main__.py +++ b/tests/codec/native/__main__.py @@ -4,11 +4,7 @@ # Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com> # License: http://snmplabs.com/pyasn1/license.html # -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest suite = unittest.TestLoader().loadTestsFromNames( ['tests.codec.native.test_encoder.suite', diff --git a/tests/codec/native/test_decoder.py b/tests/codec/native/test_decoder.py index 654e2cc..948e7e8 100644 --- a/tests/codec/native/test_decoder.py +++ b/tests/codec/native/test_decoder.py @@ -5,12 +5,7 @@ # License: http://snmplabs.com/pyasn1/license.html # import sys - -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest from tests.base import BaseTestCase diff --git a/tests/codec/native/test_encoder.py b/tests/codec/native/test_encoder.py index 25c9979..d0f6587 100644 --- a/tests/codec/native/test_encoder.py +++ b/tests/codec/native/test_encoder.py @@ -5,12 +5,7 @@ # License: http://snmplabs.com/pyasn1/license.html # import sys - -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest from tests.base import BaseTestCase diff --git a/tests/compat/__main__.py b/tests/compat/__main__.py index 296d70c..53a3579 100644 --- a/tests/compat/__main__.py +++ b/tests/compat/__main__.py @@ -4,15 +4,10 @@ # Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com> # License: http://snmplabs.com/pyasn1/license.html # -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest suite = unittest.TestLoader().loadTestsFromNames( - ['tests.compat.test_binary.suite', - 'tests.compat.test_integer.suite', + ['tests.compat.test_integer.suite', 'tests.compat.test_octets.suite'] ) diff --git a/tests/compat/test_binary.py b/tests/compat/test_binary.py deleted file mode 100644 index 3e0949f..0000000 --- a/tests/compat/test_binary.py +++ /dev/null @@ -1,56 +0,0 @@ -# -# This file is part of pyasn1 software. -# -# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com> -# License: http://snmplabs.com/pyasn1/license.html -# -import sys - -try: - import unittest2 as unittest -except ImportError: - import unittest - -from tests.base import BaseTestCase - -from pyasn1.compat import binary - - -class BinaryTestCase(BaseTestCase): - - def test_bin_zero(self): - assert '0b0' == binary.bin(0) - - - def test_bin_noarg(self): - try: - binary.bin() - - except TypeError: - pass - - except: - assert 0, 'bin() tolerates no arguments' - - - def test_bin_allones(self): - assert '0b1111111111111111111111111111111111111111111111111111111111111111' == binary.bin(0xffffffffffffffff) - - - def test_bin_allzeros(self): - assert '0b0' == binary.bin(0x0000000) - - - - def test_bin_pos(self): - assert '0b1000000010000000100000001' == binary.bin(0x01010101) - - - def test_bin_neg(self): - assert '-0b1000000010000000100000001' == binary.bin(-0x01010101) - - -suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) - -if __name__ == '__main__': - unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/tests/compat/test_integer.py b/tests/compat/test_integer.py index 04fd86a..716256c 100644 --- a/tests/compat/test_integer.py +++ b/tests/compat/test_integer.py @@ -5,11 +5,7 @@ # License: http://snmplabs.com/pyasn1/license.html # import sys - -try: - import unittest2 as unittest -except ImportError: - import unittest +import unittest from tests.base import BaseTestCase diff --git a/tests/compat/test_octets.py b/tests/compat/test_octets.py index 5a9bc7c..d2b8021 100644 --- a/tests/compat/test_octets.py +++ b/tests/compat/test_octets.py @@ -5,11 +5,7 @@ # License: http://snmplabs.com/pyasn1/license.html # import sys - -try: - import unittest2 as unittest -except ImportError: - import unittest +import unittest from tests.base import BaseTestCase diff --git a/tests/test_debug.py b/tests/test_debug.py index 9e33f93..1cd4c05 100644 --- a/tests/test_debug.py +++ b/tests/test_debug.py @@ -5,12 +5,7 @@ # License: http://snmplabs.com/pyasn1/license.html # import sys - -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest from tests.base import BaseTestCase diff --git a/tests/type/__main__.py b/tests/type/__main__.py index fcc66e7..d6f44e6 100644 --- a/tests/type/__main__.py +++ b/tests/type/__main__.py @@ -4,11 +4,7 @@ # Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com> # License: http://snmplabs.com/pyasn1/license.html # -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest suite = unittest.TestLoader().loadTestsFromNames( ['tests.type.test_constraint.suite', diff --git a/tests/type/test_char.py b/tests/type/test_char.py index 8540a3e..e2fac73 100644 --- a/tests/type/test_char.py +++ b/tests/type/test_char.py @@ -6,12 +6,7 @@ # import pickle import sys - -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest from tests.base import BaseTestCase @@ -111,9 +106,8 @@ class AbstractStringTestCase(object): assert self.pythonString in self.asn1String assert self.pythonString + self.pythonString not in self.asn1String - if sys.version_info[:2] > (2, 4): - def testReverse(self): - assert list(reversed(self.asn1String)) == list(reversed(self.pythonString)) + def testReverse(self): + assert list(reversed(self.asn1String)) == list(reversed(self.pythonString)) def testSchemaPickling(self): old_asn1 = self.asn1Type() diff --git a/tests/type/test_constraint.py b/tests/type/test_constraint.py index 7ef6293..8a88731 100644 --- a/tests/type/test_constraint.py +++ b/tests/type/test_constraint.py @@ -5,12 +5,7 @@ # License: http://snmplabs.com/pyasn1/license.html # import sys - -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest from tests.base import BaseTestCase diff --git a/tests/type/test_namedtype.py b/tests/type/test_namedtype.py index 7cff45e..e2ab60b 100644 --- a/tests/type/test_namedtype.py +++ b/tests/type/test_namedtype.py @@ -5,12 +5,7 @@ # License: http://snmplabs.com/pyasn1/license.html # import sys - -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest from tests.base import BaseTestCase diff --git a/tests/type/test_namedval.py b/tests/type/test_namedval.py index 4ac08cf..eae6b4d 100644 --- a/tests/type/test_namedval.py +++ b/tests/type/test_namedval.py @@ -5,12 +5,7 @@ # License: http://snmplabs.com/pyasn1/license.html # import sys - -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest from tests.base import BaseTestCase @@ -23,10 +18,10 @@ class NamedValuesCaseBase(BaseTestCase): self.e = namedval.NamedValues(('off', 0), ('on', 1)) def testDict(self): - assert set(self.e.items()) == set([('off', 0), ('on', 1)]) - assert set(self.e.keys()) == set(['off', 'on']) - assert set(self.e) == set(['off', 'on']) - assert set(self.e.values()) == set([0, 1]) + assert set(self.e.items()) == {('off', 0), ('on', 1)} + assert set(self.e.keys()) == {'off', 'on'} + assert set(self.e) == {'off', 'on'} + assert set(self.e.values()) == {0, 1} assert 'on' in self.e and 'off' in self.e and 'xxx' not in self.e assert 0 in self.e and 1 in self.e and 2 not in self.e diff --git a/tests/type/test_opentype.py b/tests/type/test_opentype.py index ff6788f..a3efbf0 100644 --- a/tests/type/test_opentype.py +++ b/tests/type/test_opentype.py @@ -5,12 +5,7 @@ # License: http://snmplabs.com/pyasn1/license.html # import sys - -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest from tests.base import BaseTestCase diff --git a/tests/type/test_tag.py b/tests/type/test_tag.py index e8dd7a3..7e8f694 100644 --- a/tests/type/test_tag.py +++ b/tests/type/test_tag.py @@ -5,12 +5,7 @@ # License: http://snmplabs.com/pyasn1/license.html # import sys - -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest from tests.base import BaseTestCase diff --git a/tests/type/test_univ.py b/tests/type/test_univ.py index 124e5e9..04923bb 100644 --- a/tests/type/test_univ.py +++ b/tests/type/test_univ.py @@ -7,12 +7,7 @@ import math import pickle import sys - -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest from tests.base import BaseTestCase @@ -148,21 +143,11 @@ class NoValueTestCase(BaseTestCase): def testSizeOf(self): try: - if hasattr(sys, 'getsizeof'): - sys.getsizeof(univ.noValue) - - # TODO: remove when Py2.5 support is gone - elif sys.version_info > (2, 6): - raise unittest.SkipTest("no sys.getsizeof() method") + sys.getsizeof(univ.noValue) except PyAsn1Error: assert False, 'sizeof failed for NoValue object' - except TypeError: - # TODO: remove when Py2.5 support is gone - if sys.version_info > (2, 6): - raise unittest.SkipTest("sys.getsizeof() raises TypeError") - class IntegerTestCase(BaseTestCase): def testStr(self): @@ -278,9 +263,8 @@ class IntegerTestCase(BaseTestCase): def testCeil(self): assert math.ceil(univ.Integer(1)) == 1, '__ceil__() fails' - if sys.version_info[0:2] > (2, 5): - def testTrunc(self): - assert math.trunc(univ.Integer(1)) == 1, '__trunc__() fails' + def testTrunc(self): + assert math.trunc(univ.Integer(1)) == 1, '__trunc__() fails' def testPrettyIn(self): assert univ.Integer('3') == 3, 'prettyIn() fails' @@ -437,9 +421,8 @@ class BitStringTestCase(BaseTestCase): assert self.b.clone("'A98A'H")[1] == 0 assert self.b.clone("'A98A'H")[2] == 1 - if sys.version_info[:2] > (2, 4): - def testReverse(self): - assert list(reversed(univ.BitString([0, 0, 1]))) == list(univ.BitString([1, 0, 0])) + def testReverse(self): + assert list(reversed(univ.BitString([0, 0, 1]))) == list(univ.BitString([1, 0, 0])) def testAsOctets(self): assert self.b.clone(hexValue='A98A').asOctets() == ints2octs((0xa9, 0x8a)), 'testAsOctets() fails' @@ -539,9 +522,8 @@ class OctetStringWithUnicodeMixIn(object): assert self.encodedPythonString in s assert self.encodedPythonString * 2 not in s - if sys.version_info[:2] > (2, 4): - def testReverse(self): - assert list(reversed(univ.OctetString(self.encodedPythonString))) == list(reversed(self.encodedPythonString)) + def testReverse(self): + assert list(reversed(univ.OctetString(self.encodedPythonString))) == list(reversed(self.encodedPythonString)) class OctetStringWithAsciiTestCase(OctetStringWithUnicodeMixIn, BaseTestCase): @@ -565,11 +547,6 @@ class OctetStringUnicodeErrorTestCase(BaseTestCase): except PyAsn1UnicodeEncodeError: pass - # TODO: remove when Py2.5 support is gone - else: - if sys.version_info > (2, 6): - assert False, 'Unicode encoding error not caught' - def testDecodeError(self): serialized = ints2octs((0xff, 0xfe)) @@ -585,11 +562,6 @@ class OctetStringUnicodeErrorTestCase(BaseTestCase): except PyAsn1UnicodeDecodeError: pass - # TODO: remove when Py2.5 support is gone - else: - if sys.version_info > (2, 6): - assert False, 'Unicode decoding error not caught' - class OctetStringWithUtf8TestCase(OctetStringWithUnicodeMixIn, BaseTestCase): initializer = (208, 176, 208, 177, 208, 178) @@ -860,9 +832,8 @@ class RealTestCase(BaseTestCase): def testCeil(self): assert math.ceil(univ.Real(1.2)) == 2.0, '__ceil__() fails' - if sys.version_info[0:2] > (2, 5): - def testTrunc(self): - assert math.trunc(univ.Real(1.1)) == 1.0, '__trunc__() fails' + def testTrunc(self): + assert math.trunc(univ.Real(1.1)) == 1.0, '__trunc__() fails' def testTag(self): assert univ.Real().tagSet == tag.TagSet( diff --git a/tests/type/test_useful.py b/tests/type/test_useful.py index 8a5ab30..5078232 100644 --- a/tests/type/test_useful.py +++ b/tests/type/test_useful.py @@ -8,12 +8,7 @@ import datetime import pickle import sys from copy import deepcopy - -try: - import unittest2 as unittest - -except ImportError: - import unittest +import unittest from tests.base import BaseTestCase |