From 7d73cf4398345824eaadf47e31f9c500c612a8b7 Mon Sep 17 00:00:00 2001 From: Yesudeep Mangalapilly Date: Thu, 11 Aug 2011 04:48:11 +0530 Subject: Adds tests for int2bytes. --- tests/test_transform.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/test_transform.py (limited to 'tests') 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) -- cgit v1.2.1