summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorYesudeep Mangalapilly <yesudeep@gmail.com>2011-08-11 01:48:25 +0530
committerYesudeep Mangalapilly <yesudeep@gmail.com>2011-08-11 01:48:25 +0530
commit6ce8f458f51628df68a559784d42f4874b15e21c (patch)
tree9ac0fef8c58d8a5def3e967ff11c6d8925ec903a /tests
parenta20db8ff53e62c78f9e6b4077167ebb4a81cf94c (diff)
downloadrsa-6ce8f458f51628df68a559784d42f4874b15e21c.tar.gz
Tests are now functional (only running without syntax errors) on Python 3 too.
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py0
-rw-r--r--tests/constants.py9
-rw-r--r--tests/py2kconstants.py3
-rw-r--r--tests/py3kconstants.py3
-rw-r--r--tests/test_bigfile.py5
-rw-r--r--tests/test_integers.py10
-rw-r--r--tests/test_load_save_keys.py21
-rw-r--r--tests/test_pkcs1.py11
-rw-r--r--tests/test_strings.py12
-rw-r--r--tests/test_varblock.py5
10 files changed, 52 insertions, 27 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/__init__.py
diff --git a/tests/constants.py b/tests/constants.py
new file mode 100644
index 0000000..6a0d081
--- /dev/null
+++ b/tests/constants.py
@@ -0,0 +1,9 @@
+# -*- coding: utf-8 -*-
+
+from rsa._compat import have_python3
+
+if have_python3:
+ from py3kconstants import *
+else:
+ from py2kconstants import *
+
diff --git a/tests/py2kconstants.py b/tests/py2kconstants.py
new file mode 100644
index 0000000..5f695dd
--- /dev/null
+++ b/tests/py2kconstants.py
@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+
+unicode_string = u"Euro=\u20ac ABCDEFGHIJKLMNOPQRSTUVWXYZ"
diff --git a/tests/py3kconstants.py b/tests/py3kconstants.py
new file mode 100644
index 0000000..83b6712
--- /dev/null
+++ b/tests/py3kconstants.py
@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+
+unicode_string = "Euro=\u20ac ABCDEFGHIJKLMNOPQRSTUVWXYZ"
diff --git a/tests/test_bigfile.py b/tests/test_bigfile.py
index 30156a1..39bd095 100644
--- a/tests/test_bigfile.py
+++ b/tests/test_bigfile.py
@@ -1,6 +1,9 @@
'''Tests block operations.'''
-from StringIO import StringIO
+try:
+ from StringIO import StringIO
+except ImportError:
+ from io import StringIO
import unittest
import rsa
diff --git a/tests/test_integers.py b/tests/test_integers.py
index 111f8ab..d4fa087 100644
--- a/tests/test_integers.py
+++ b/tests/test_integers.py
@@ -12,13 +12,13 @@ class IntegerTest(unittest.TestCase):
def test_enc_dec(self):
message = 42
- print "\tMessage: %d" % message
+ print("\tMessage: %d" % message)
encrypted = rsa.core.encrypt_int(message, self.pub.e, self.pub.n)
- print "\tEncrypted: %d" % encrypted
+ print("\tEncrypted: %d" % encrypted)
decrypted = rsa.core.decrypt_int(encrypted, self.priv.d, self.pub.n)
- print "\tDecrypted: %d" % decrypted
+ print("\tDecrypted: %d" % decrypted)
self.assertEqual(message, decrypted)
@@ -27,10 +27,10 @@ class IntegerTest(unittest.TestCase):
message = 42
signed = rsa.core.encrypt_int(message,self.priv.d, self.pub.n)
- print "\tSigned: %d" % signed
+ print("\tSigned: %d" % signed)
verified = rsa.core.decrypt_int(signed, self.pub.e,self.pub.n)
- print "\tVerified: %d" % verified
+ print("\tVerified: %d" % verified)
self.assertEqual(message, verified)
diff --git a/tests/test_load_save_keys.py b/tests/test_load_save_keys.py
index 466a3f5..56d45c4 100644
--- a/tests/test_load_save_keys.py
+++ b/tests/test_load_save_keys.py
@@ -2,16 +2,17 @@
import base64
import unittest
+from rsa._compat import b
import rsa.key
-B64PRIV_DER = 'MC4CAQACBQDeKYlRAgMBAAECBQDHn4npAgMA/icCAwDfxwIDANcXAgInbwIDAMZt'
+B64PRIV_DER = b('MC4CAQACBQDeKYlRAgMBAAECBQDHn4npAgMA/icCAwDfxwIDANcXAgInbwIDAMZt')
PRIVATE_DER = base64.decodestring(B64PRIV_DER)
-B64PUB_DER = 'MAwCBQDeKYlRAgMBAAE='
+B64PUB_DER = b('MAwCBQDeKYlRAgMBAAE=')
PUBLIC_DER = base64.decodestring(B64PUB_DER)
-PRIVATE_PEM = '''
+PRIVATE_PEM = b('''
-----BEGIN CONFUSING STUFF-----
Cruft before the key
@@ -23,15 +24,15 @@ Comment: something blah
Stuff after the key
-----END CONFUSING STUFF-----
-''' % B64PRIV_DER
+''' % B64PRIV_DER)
-CLEAN_PRIVATE_PEM = '''\
+CLEAN_PRIVATE_PEM = b('''\
-----BEGIN RSA PRIVATE KEY-----
%s
-----END RSA PRIVATE KEY-----
-''' % B64PRIV_DER
+''' % B64PRIV_DER)
-PUBLIC_PEM = '''
+PUBLIC_PEM = b('''
-----BEGIN CONFUSING STUFF-----
Cruft before the key
@@ -43,13 +44,13 @@ Comment: something blah
Stuff after the key
-----END CONFUSING STUFF-----
-''' % B64PUB_DER
+''' % B64PUB_DER)
-CLEAN_PUBLIC_PEM = '''\
+CLEAN_PUBLIC_PEM = b('''\
-----BEGIN RSA PUBLIC KEY-----
%s
-----END RSA PUBLIC KEY-----
-''' % B64PUB_DER
+''' % B64PUB_DER)
class DerTest(unittest.TestCase):
diff --git a/tests/test_pkcs1.py b/tests/test_pkcs1.py
index 3392ed7..c841485 100644
--- a/tests/test_pkcs1.py
+++ b/tests/test_pkcs1.py
@@ -14,13 +14,13 @@ class BinaryTest(unittest.TestCase):
def test_enc_dec(self):
message = struct.pack('>IIII', 0, 0, 0, 1)
- print "\tMessage: %r" % message
+ print("\tMessage: %r" % message)
encrypted = pkcs1.encrypt(message, self.pub)
- print "\tEncrypted: %r" % encrypted
+ print("\tEncrypted: %r" % encrypted)
decrypted = pkcs1.decrypt(encrypted, self.priv)
- print "\tDecrypted: %r" % decrypted
+ print("\tDecrypted: %r" % decrypted)
self.assertEqual(message, decrypted)
@@ -55,10 +55,10 @@ class SignatureTest(unittest.TestCase):
'''Test happy flow of sign and verify'''
message = 'je moeder'
- print "\tMessage: %r" % message
+ print("\tMessage: %r" % message)
signature = pkcs1.sign(message, self.priv, 'SHA-256')
- print "\tSignature: %r" % signature
+ print("\tSignature: %r" % signature)
pkcs1.verify(message, signature, self.pub)
@@ -88,4 +88,3 @@ class SignatureTest(unittest.TestCase):
self.assertEqual(signature1, signature2)
- \ No newline at end of file
diff --git a/tests/test_strings.py b/tests/test_strings.py
index 38fae06..58d3833 100644
--- a/tests/test_strings.py
+++ b/tests/test_strings.py
@@ -1,9 +1,13 @@
'''Tests string operations.'''
+from __future__ import absolute_import
+
import unittest
import rsa
+from tests.constants import unicode_string
+
class StringTest(unittest.TestCase):
def setUp(self):
@@ -11,14 +15,14 @@ class StringTest(unittest.TestCase):
def test_enc_dec(self):
- message = u"Euro=\u20ac ABCDEFGHIJKLMNOPQRSTUVWXYZ".encode('utf-8')
- print "\tMessage: %s" % message
+ message = unicode_string.encode('utf-8')
+ print("\tMessage: %s" % message)
encrypted = rsa.encrypt(message, self.pub)
- print "\tEncrypted: %s" % encrypted
+ print("\tEncrypted: %s" % encrypted)
decrypted = rsa.decrypt(encrypted, self.priv)
- print "\tDecrypted: %s" % decrypted
+ print("\tDecrypted: %s" % decrypted)
self.assertEqual(message, decrypted)
diff --git a/tests/test_varblock.py b/tests/test_varblock.py
index d8addb4..6195258 100644
--- a/tests/test_varblock.py
+++ b/tests/test_varblock.py
@@ -1,6 +1,9 @@
'''Tests varblock operations.'''
-from StringIO import StringIO
+try:
+ from StringIO import StringIO
+except ImportError:
+ from io import StringIO
import unittest
import rsa