• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# This file is part of pyasn1 software.
3#
4# Copyright (c) 2005-2018, Ilya Etingof <etingof@gmail.com>
5# License: http://snmplabs.com/pyasn1/license.html
6#
7import sys
8
9try:
10    import unittest2 as unittest
11except ImportError:
12    import unittest
13
14from tests.base import BaseTestCase
15
16from pyasn1.compat import integer
17
18
19class IntegerTestCase(BaseTestCase):
20
21    if sys.version_info[0] > 2:
22
23        def test_from_bytes_zero(self):
24            assert 0 == integer.from_bytes(bytes([0]), signed=False)
25
26        def test_from_bytes_unsigned(self):
27            assert -66051 == integer.from_bytes(bytes([254, 253, 253]), signed=True)
28
29        def test_from_bytes_signed(self):
30            assert 66051 == integer.from_bytes(bytes([0, 1, 2, 3]), signed=False)
31
32        def test_from_bytes_empty(self):
33            assert 0 == integer.from_bytes(bytes([]))
34
35    else:
36
37        def test_from_bytes_zero(self):
38            assert 0 == integer.from_bytes('\x00', signed=False)
39
40        def test_from_bytes_unsigned(self):
41            assert -66051 == integer.from_bytes('\xfe\xfd\xfd', signed=True)
42
43        def test_from_bytes_signed(self):
44            assert 66051 == integer.from_bytes('\x01\x02\x03', signed=False)
45
46        def test_from_bytes_empty(self):
47            assert 0 == integer.from_bytes('')
48
49
50suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
51
52if __name__ == '__main__':
53    unittest.TextTestRunner(verbosity=2).run(suite)
54