test_integer.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #
  2. # This file is part of pyasn1 software.
  3. #
  4. # Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
  5. # License: https://pyasn1.readthedocs.io/en/latest/license.html
  6. #
  7. import sys
  8. import unittest
  9. from __tests__.base import BaseTestCase
  10. from pyasn1.compat import integer
  11. class IntegerTestCase(BaseTestCase):
  12. if sys.version_info[0] > 2:
  13. def test_from_bytes_zero(self):
  14. assert 0 == integer.from_bytes(bytes([0]), signed=False)
  15. def test_from_bytes_unsigned(self):
  16. assert -66051 == integer.from_bytes(bytes([254, 253, 253]), signed=True)
  17. def test_from_bytes_signed(self):
  18. assert 66051 == integer.from_bytes(bytes([0, 1, 2, 3]), signed=False)
  19. def test_from_bytes_empty(self):
  20. assert 0 == integer.from_bytes(bytes([]))
  21. else:
  22. def test_from_bytes_zero(self):
  23. assert 0 == integer.from_bytes('\x00', signed=False)
  24. def test_from_bytes_unsigned(self):
  25. assert -66051 == integer.from_bytes('\xfe\xfd\xfd', signed=True)
  26. def test_from_bytes_signed(self):
  27. assert 66051 == integer.from_bytes('\x01\x02\x03', signed=False)
  28. def test_from_bytes_empty(self):
  29. assert 0 == integer.from_bytes('')
  30. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  31. if __name__ == '__main__':
  32. unittest.TextTestRunner(verbosity=2).run(suite)