Home | History | Annotate | Download | only in compat
      1 #
      2 # This file is part of pyasn1 software.
      3 #
      4 # Copyright (c) 2005-2018, Ilya Etingof <etingof (at] gmail.com>
      5 # License: http://snmplabs.com/pyasn1/license.html
      6 #
      7 import sys
      8 
      9 try:
     10     import unittest2 as unittest
     11 except ImportError:
     12     import unittest
     13 
     14 from tests.base import BaseTestCase
     15 
     16 from pyasn1.compat import integer
     17 
     18 
     19 class 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 
     50 suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
     51 
     52 if __name__ == '__main__':
     53     unittest.TextTestRunner(verbosity=2).run(suite)
     54