From 0da93e8d3f2fa88401acfb92f4370fd0fc2089e6 Mon Sep 17 00:00:00 2001 From: Yesudeep Mangalapilly Date: Tue, 16 Aug 2011 14:58:32 +0530 Subject: Moves incompatible doctests to unit test modules. --- rsa/_version200.py | 8 ++------ rsa/common.py | 17 ++--------------- rsa/pem.py | 7 ++----- tests/test__version200.py | 12 ++++++++++++ tests/test_pem.py | 14 ++++++++++++++ tox.ini | 2 +- 6 files changed, 33 insertions(+), 27 deletions(-) create mode 100644 tests/test__version200.py create mode 100644 tests/test_pem.py diff --git a/rsa/_version200.py b/rsa/_version200.py index 8e3f452..a49f635 100644 --- a/rsa/_version200.py +++ b/rsa/_version200.py @@ -65,12 +65,8 @@ def bytes2int(bytes): return integer def int2bytes(number): - """Converts a number to a string of bytes - - >>>int2bytes(123456789) - '\x07[\xcd\x15' - >>> bytes2int(int2bytes(123456789)) - 123456789 + """ + Converts a number to a string of bytes """ if not (type(number) is types.LongType or type(number) is types.IntType): diff --git a/rsa/common.py b/rsa/common.py index 5730ac3..7801b59 100644 --- a/rsa/common.py +++ b/rsa/common.py @@ -22,20 +22,6 @@ def bit_size(num): Number of bits needed to represent a integer excluding any prefix 0 bits. - >>> bit_size(1023) - 10 - >>> bit_size(1024) - 11 - >>> bit_size(1025) - 11 - - >>> bit_size(1 << 1024) - 1025 - >>> bit_size((1 << 1024) + 1) - 1025 - >>> bit_size((1 << 1024) - 1) - 1024 - :param num: Integer value. If num is 0, returns 0. Only the absolute value of the number is considered. Therefore, signed integers will be abs(num) @@ -118,9 +104,10 @@ def extended_gcd(a, b): if (ly < 0): ly += oa #If neg wrap modulo orignal a return (a, lx, ly) #Return only positive values + def inverse(x, n): """Returns x^-1 (mod n) - + >>> inverse(7, 4) 3 >>> (inverse(143, 4) * 143) % 4 diff --git a/rsa/pem.py b/rsa/pem.py index b632ceb..5a37f6d 100644 --- a/rsa/pem.py +++ b/rsa/pem.py @@ -20,11 +20,8 @@ import base64 from rsa._compat import b, is_bytes def _markers(pem_marker): - """Returns the start and end PEM markers - - >>> _markers('RSA PRIVATE KEY') - ('-----BEGIN RSA PRIVATE KEY-----', '-----END RSA PRIVATE KEY-----') - + """ + Returns the start and end PEM markers """ if is_bytes(pem_marker): diff --git a/tests/test__version200.py b/tests/test__version200.py new file mode 100644 index 0000000..2a179a8 --- /dev/null +++ b/tests/test__version200.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import unittest2 +from rsa._compat import b + +from rsa._version200 import int2bytes, bytes2int + +class Test_int2bytes(unittest2.TestCase): + def test_values(self): + self.assertEqual(int2bytes(123456789), b('\x07[\xcd\x15')) + self.assertEqual(bytes2int(int2bytes(123456789)), 123456789) diff --git a/tests/test_pem.py b/tests/test_pem.py new file mode 100644 index 0000000..867f678 --- /dev/null +++ b/tests/test_pem.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + + +import unittest2 +from rsa._compat import b +from rsa.pem import _markers + + +class Test__markers(unittest2.TestCase): + def test_values(self): + self.assertEqual(_markers('RSA PRIVATE KEY'), + (b('-----BEGIN RSA PRIVATE KEY-----'), + b('-----END RSA PRIVATE KEY-----'))) diff --git a/tox.ini b/tox.ini index 949bade..7bc952c 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,7 @@ envlist = py25,py26,py27,py32 #,pypy [pytest] -addopts = -n4 --cov rsa --cov-report term-missing +addopts = -n4 --cov rsa --cov-report term-missing --doctest-modules [testenv] commands=py.test [] -- cgit v1.2.1