summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@stuvel.eu>2019-08-04 15:02:20 +0200
committerSybren A. Stüvel <sybren@stuvel.eu>2019-08-04 17:05:58 +0200
commitded036cf988b0cf4b20002d88434282f30762638 (patch)
treed927a9732226093ffcdf7400808ae45f5b9e6c37 /tests
parent65a81053d596c62ad2532c7e0e38e68ef61304bd (diff)
downloadrsa-git-ded036cf988b0cf4b20002d88434282f30762638.tar.gz
Removed compatibility code for Python 2.7 and 3.4
Diffstat (limited to 'tests')
-rw-r--r--tests/test_cli.py10
-rw-r--r--tests/test_compat.py4
-rw-r--r--tests/test_load_save_keys.py3
-rw-r--r--tests/test_pem.py17
-rw-r--r--tests/test_pkcs1.py6
-rw-r--r--tests/test_prime.py1
-rw-r--r--tests/test_transform.py23
7 files changed, 17 insertions, 47 deletions
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 7ce57eb..7cf7ed4 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -15,21 +15,15 @@ from io import StringIO, BytesIO
import rsa
import rsa.cli
import rsa.util
-from rsa._compat import PY2
-def make_buffer():
- if PY2:
- return BytesIO()
+def make_buffer() -> StringIO:
buf = StringIO()
buf.buffer = BytesIO()
return buf
-def get_bytes_out(out):
- if PY2:
- # Python 2.x writes 'str' to stdout
- return out.getvalue()
+def get_bytes_out(out: StringIO) -> bytes:
# Python 3.x writes 'bytes' to stdout.buffer
return out.buffer.getvalue()
diff --git a/tests/test_compat.py b/tests/test_compat.py
index 62e933f..a047402 100644
--- a/tests/test_compat.py
+++ b/tests/test_compat.py
@@ -17,7 +17,7 @@
import unittest
import struct
-from rsa._compat import byte, is_bytes, range, xor_bytes
+from rsa._compat import byte, xor_bytes
class TestByte(unittest.TestCase):
@@ -26,7 +26,7 @@ class TestByte(unittest.TestCase):
def test_byte(self):
for i in range(256):
byt = byte(i)
- self.assertTrue(is_bytes(byt))
+ self.assertIsInstance(byt, bytes)
self.assertEqual(ord(byt), i)
def test_raises_StructError_on_overflow(self):
diff --git a/tests/test_load_save_keys.py b/tests/test_load_save_keys.py
index 55bd5a4..c0ee06c 100644
--- a/tests/test_load_save_keys.py
+++ b/tests/test_load_save_keys.py
@@ -17,13 +17,12 @@
"""Unittest for saving and loading keys."""
import base64
-import mock
import os.path
import pickle
import unittest
import warnings
+from unittest import mock
-from rsa._compat import range
import rsa.key
B64PRIV_DER = b'MC4CAQACBQDeKYlRAgMBAAECBQDHn4npAgMA/icCAwDfxwIDANcXAgInbwIDAMZt'
diff --git a/tests/test_pem.py b/tests/test_pem.py
index 5fb9600..b9bd93c 100644
--- a/tests/test_pem.py
+++ b/tests/test_pem.py
@@ -17,7 +17,6 @@
import unittest
-from rsa._compat import is_bytes
from rsa.pem import _markers
import rsa.key
@@ -79,13 +78,13 @@ class TestByteOutput(unittest.TestCase):
def test_bytes_public(self):
key = rsa.key.PublicKey.load_pkcs1_openssl_pem(public_key_pem)
- self.assertTrue(is_bytes(key.save_pkcs1(format='DER')))
- self.assertTrue(is_bytes(key.save_pkcs1(format='PEM')))
+ self.assertIsInstance(key.save_pkcs1(format='DER'), bytes)
+ self.assertIsInstance(key.save_pkcs1(format='PEM'), bytes)
def test_bytes_private(self):
key = rsa.key.PrivateKey.load_pkcs1(private_key_pem)
- self.assertTrue(is_bytes(key.save_pkcs1(format='DER')))
- self.assertTrue(is_bytes(key.save_pkcs1(format='PEM')))
+ self.assertIsInstance(key.save_pkcs1(format='DER'), bytes)
+ self.assertIsInstance(key.save_pkcs1(format='PEM'), bytes)
class TestByteInput(unittest.TestCase):
@@ -93,10 +92,10 @@ class TestByteInput(unittest.TestCase):
def test_bytes_public(self):
key = rsa.key.PublicKey.load_pkcs1_openssl_pem(public_key_pem.encode('ascii'))
- self.assertTrue(is_bytes(key.save_pkcs1(format='DER')))
- self.assertTrue(is_bytes(key.save_pkcs1(format='PEM')))
+ self.assertIsInstance(key.save_pkcs1(format='DER'), bytes)
+ self.assertIsInstance(key.save_pkcs1(format='PEM'), bytes)
def test_bytes_private(self):
key = rsa.key.PrivateKey.load_pkcs1(private_key_pem.encode('ascii'))
- self.assertTrue(is_bytes(key.save_pkcs1(format='DER')))
- self.assertTrue(is_bytes(key.save_pkcs1(format='PEM')))
+ self.assertIsInstance(key.save_pkcs1(format='DER'), bytes)
+ self.assertIsInstance(key.save_pkcs1(format='PEM'), bytes)
diff --git a/tests/test_pkcs1.py b/tests/test_pkcs1.py
index 5377b30..1704ffd 100644
--- a/tests/test_pkcs1.py
+++ b/tests/test_pkcs1.py
@@ -21,7 +21,7 @@ import unittest
import rsa
from rsa import pkcs1
-from rsa._compat import byte, is_bytes
+from rsa._compat import byte
class BinaryTest(unittest.TestCase):
@@ -46,8 +46,8 @@ class BinaryTest(unittest.TestCase):
# Alter the encrypted stream
a = encrypted[5]
- if is_bytes(a):
- a = ord(a)
+ self.assertIsInstance(a, int)
+
altered_a = (a + 1) % 256
encrypted = encrypted[:5] + byte(altered_a) + encrypted[6:]
diff --git a/tests/test_prime.py b/tests/test_prime.py
index f3bda9b..75b80b3 100644
--- a/tests/test_prime.py
+++ b/tests/test_prime.py
@@ -18,7 +18,6 @@
import unittest
-from rsa._compat import range
import rsa.prime
import rsa.randnum
diff --git a/tests/test_transform.py b/tests/test_transform.py
index fe0970c..83c3934 100644
--- a/tests/test_transform.py
+++ b/tests/test_transform.py
@@ -15,37 +15,26 @@
# limitations under the License.
import unittest
-from rsa.transform import int2bytes, bytes2int, _int2bytes
+from rsa.transform import int2bytes, bytes2int
class Test_int2bytes(unittest.TestCase):
def test_accuracy(self):
self.assertEqual(int2bytes(123456789), b'\x07[\xcd\x15')
- self.assertEqual(_int2bytes(123456789), b'\x07[\xcd\x15')
def test_codec_identity(self):
self.assertEqual(bytes2int(int2bytes(123456789, 128)), 123456789)
- self.assertEqual(bytes2int(_int2bytes(123456789, 128)), 123456789)
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')
- 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_zero(self):
self.assertEqual(int2bytes(0, 4), b'\x00' * 4)
self.assertEqual(int2bytes(0, 7), b'\x00' * 7)
self.assertEqual(int2bytes(0), b'\x00')
- self.assertEqual(_int2bytes(0, 4), b'\x00' * 4)
- self.assertEqual(_int2bytes(0, 7), b'\x00' * 7)
- self.assertEqual(_int2bytes(0), b'\x00')
-
def test_correctness_against_base_implementation(self):
# Slow test.
values = [
@@ -54,26 +43,16 @@ class Test_int2bytes(unittest.TestCase):
1 << 77,
]
for value in values:
- self.assertEqual(int2bytes(value), _int2bytes(value),
- "Boom %d" % value)
self.assertEqual(bytes2int(int2bytes(value)),
value,
"Boom %d" % value)
- self.assertEqual(bytes2int(_int2bytes(value)),
- value,
- "Boom %d" % value)
def test_raises_OverflowError_when_chunk_size_is_insufficient(self):
self.assertRaises(OverflowError, int2bytes, 123456789, 3)
self.assertRaises(OverflowError, int2bytes, 299999999999, 4)
- 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)
- self.assertRaises(ValueError, _int2bytes, -1)
def test_raises_TypeError_when_not_integer(self):
self.assertRaises(TypeError, int2bytes, None)
- self.assertRaises(TypeError, _int2bytes, None)