summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorYesudeep Mangalapilly <yesudeep@gmail.com>2011-08-11 04:48:11 +0530
committerYesudeep Mangalapilly <yesudeep@gmail.com>2011-08-11 04:48:11 +0530
commit7d73cf4398345824eaadf47e31f9c500c612a8b7 (patch)
tree141c0cf97d5cc7b05cf1909d786fa681c8e008cb /tests
parentd827dde263e1438682cef9df5e108ef3b993c0d4 (diff)
downloadrsa-7d73cf4398345824eaadf47e31f9c500c612a8b7.tar.gz
Adds tests for int2bytes.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_transform.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test_transform.py b/tests/test_transform.py
new file mode 100644
index 0000000..ecc1a30
--- /dev/null
+++ b/tests/test_transform.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+
+
+import unittest2
+from rsa._compat import b
+from rsa.transform import int2bytes
+
+
+class Test_integer_to_bytes(unittest2.TestCase):
+ def test_chunk_size(self):
+ self.assertEqual(int2bytes(123456789, 6),
+ b('\x00\x00\x07[\xcd\x15'))
+ self.assertEqual(int2bytes(123456789, 7),
+ b('\x00\x00\x00\x07[\xcd\x15'))
+
+ def test_raises_OverflowError_when_chunk_size_is_insufficient(self):
+ self.assertRaises(OverflowError, int2bytes, 123456789, 3)
+ self.assertRaises(OverflowError, int2bytes, 299999999999, 4)
+
+ def test_raises_ValueError_when_negative_integer(self):
+ self.assertRaises(ValueError, int2bytes, -1)
+
+ def test_raises_TypeError_when_not_integer(self):
+ self.assertRaises(TypeError, int2bytes, None)