summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@stuvel.eu>2016-03-29 19:45:47 +0200
committerSybren A. Stüvel <sybren@stuvel.eu>2016-03-29 19:46:15 +0200
commit5e08c91a122bac2e59e176928aa1b24f9aa7b0b2 (patch)
tree9f17a9cc17f3da59eef408895d7fba64e37ba61d /tests
parent9a9e08ce6559f888c345935bac7f85f747fc5f06 (diff)
downloadrsa-git-5e08c91a122bac2e59e176928aa1b24f9aa7b0b2.tar.gz
No longer require string operations to find bit lengths.
Now that we no longer support Python 2.6, we can use int.bit_length() instead. Co-authored by @adamantike.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_common.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/tests/test_common.py b/tests/test_common.py
index ef32f61..e26e004 100644
--- a/tests/test_common.py
+++ b/tests/test_common.py
@@ -18,7 +18,7 @@
import unittest
import struct
from rsa._compat import byte, b
-from rsa.common import byte_size, bit_size, _bit_size, inverse
+from rsa.common import byte_size, bit_size, inverse
class TestByte(unittest.TestCase):
@@ -69,12 +69,21 @@ class TestBitSize(unittest.TestCase):
self.assertEqual(bit_size((1 << 1024) + 1), 1025)
self.assertEqual(bit_size((1 << 1024) - 1), 1024)
- self.assertEqual(_bit_size(1023), 10)
- self.assertEqual(_bit_size(1024), 11)
- self.assertEqual(_bit_size(1025), 11)
- self.assertEqual(_bit_size(1 << 1024), 1025)
- self.assertEqual(_bit_size((1 << 1024) + 1), 1025)
- self.assertEqual(_bit_size((1 << 1024) - 1), 1024)
+ def test_negative_values(self):
+ self.assertEqual(bit_size(-1023), 10)
+ self.assertEqual(bit_size(-1024), 11)
+ self.assertEqual(bit_size(-1025), 11)
+ self.assertEqual(bit_size(-1 << 1024), 1025)
+ self.assertEqual(bit_size(-((1 << 1024) + 1)), 1025)
+ self.assertEqual(bit_size(-((1 << 1024) - 1)), 1024)
+
+ def test_bad_type(self):
+ self.assertRaises(TypeError, bit_size, [])
+ self.assertRaises(TypeError, bit_size, ())
+ self.assertRaises(TypeError, bit_size, dict())
+ self.assertRaises(TypeError, bit_size, "")
+ self.assertRaises(TypeError, bit_size, None)
+ self.assertRaises(TypeError, bit_size, 0.0)
class TestInverse(unittest.TestCase):