diff options
Diffstat (limited to 'tests')
29 files changed, 55 insertions, 247 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 7a4cf20..8f2aaff 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.ber.__main__.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 e3b74df..2921a4f 100644 --- a/tests/codec/ber/test_decoder.py +++ b/tests/codec/ber/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 @@ -483,10 +478,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 df82e7b..3ba658a 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 bb5ce93..47a13eb 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 e155571..9e003a7 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..7d2b098 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 @@ -278,9 +273,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 +431,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 +532,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): @@ -860,9 +852,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 |