summaryrefslogtreecommitdiffstats
path: root/contrib/python/pyasn1/py2/tests/compat/test_integer.py
diff options
context:
space:
mode:
authoralexv-smirnov <[email protected]>2023-12-01 12:02:50 +0300
committeralexv-smirnov <[email protected]>2023-12-01 13:28:10 +0300
commit0e578a4c44d4abd539d9838347b9ebafaca41dfb (patch)
treea0c1969c37f818c830ebeff9c077eacf30be6ef8 /contrib/python/pyasn1/py2/tests/compat/test_integer.py
parent84f2d3d4cc985e63217cff149bd2e6d67ae6fe22 (diff)
Change "ya.make"
Diffstat (limited to 'contrib/python/pyasn1/py2/tests/compat/test_integer.py')
-rw-r--r--contrib/python/pyasn1/py2/tests/compat/test_integer.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/contrib/python/pyasn1/py2/tests/compat/test_integer.py b/contrib/python/pyasn1/py2/tests/compat/test_integer.py
new file mode 100644
index 00000000000..4026b75402d
--- /dev/null
+++ b/contrib/python/pyasn1/py2/tests/compat/test_integer.py
@@ -0,0 +1,49 @@
+#
+# This file is part of pyasn1 software.
+#
+# Copyright (c) 2005-2020, Ilya Etingof <[email protected]>
+# License: https://pyasn1.readthedocs.io/en/latest/license.html
+#
+import sys
+import unittest
+
+from __tests__.base import BaseTestCase
+
+from pyasn1.compat import integer
+
+
+class IntegerTestCase(BaseTestCase):
+
+ if sys.version_info[0] > 2:
+
+ def test_from_bytes_zero(self):
+ assert 0 == integer.from_bytes(bytes([0]), signed=False)
+
+ def test_from_bytes_unsigned(self):
+ assert -66051 == integer.from_bytes(bytes([254, 253, 253]), signed=True)
+
+ def test_from_bytes_signed(self):
+ assert 66051 == integer.from_bytes(bytes([0, 1, 2, 3]), signed=False)
+
+ def test_from_bytes_empty(self):
+ assert 0 == integer.from_bytes(bytes([]))
+
+ else:
+
+ def test_from_bytes_zero(self):
+ assert 0 == integer.from_bytes('\x00', signed=False)
+
+ def test_from_bytes_unsigned(self):
+ assert -66051 == integer.from_bytes('\xfe\xfd\xfd', signed=True)
+
+ def test_from_bytes_signed(self):
+ assert 66051 == integer.from_bytes('\x01\x02\x03', signed=False)
+
+ def test_from_bytes_empty(self):
+ assert 0 == integer.from_bytes('')
+
+
+suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
+
+if __name__ == '__main__':
+ unittest.TextTestRunner(verbosity=2).run(suite)