Skip to content

Commit aed6e86

Browse files
committed
Update tests to use unittest2.
1 parent 5802431 commit aed6e86

6 files changed

Lines changed: 30 additions & 28 deletions

File tree

tests/test_bigfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
from StringIO import StringIO
55
except ImportError:
66
from io import StringIO
7-
import unittest
7+
import unittest2
88

99
import rsa
1010
from rsa import bigfile, varblock, pkcs1
1111

12-
class BigfileTest(unittest.TestCase):
12+
class BigfileTest(unittest2.TestCase):
1313

1414
def test_encrypt_decrypt_bigfile(self):
1515

tests/test_integers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'''Tests integer operations.'''
22

3-
import unittest
3+
import unittest2
44

55
import rsa.core
66

7-
class IntegerTest(unittest.TestCase):
7+
class IntegerTest(unittest2.TestCase):
88

99
def setUp(self):
1010
(self.pub, self.priv) = rsa.newkeys(64)

tests/test_load_save_keys.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'''Unittest for saving and loading keys.'''
22

33
import base64
4-
import unittest
4+
import unittest2
55
from rsa._compat import b
66

77
import rsa.key
@@ -53,7 +53,7 @@
5353
''' % B64PUB_DER)
5454

5555

56-
class DerTest(unittest.TestCase):
56+
class DerTest(unittest2.TestCase):
5757
'''Test saving and loading DER keys.'''
5858

5959
def test_load_private_key(self):
@@ -88,7 +88,7 @@ def test_save_public_key(self):
8888

8989
self.assertEqual(PUBLIC_DER, der)
9090

91-
class PemTest(unittest.TestCase):
91+
class PemTest(unittest2.TestCase):
9292
'''Test saving and loading PEM keys.'''
9393

9494

tests/test_pkcs1.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'''Tests string operations.'''
22

33
import struct
4-
import unittest
4+
import unittest2
55

66
import rsa
77
from rsa import pkcs1
88

9-
class BinaryTest(unittest.TestCase):
9+
class BinaryTest(unittest2.TestCase):
1010

1111
def setUp(self):
1212
(self.pub, self.priv) = rsa.newkeys(256)
@@ -46,7 +46,7 @@ def test_randomness(self):
4646

4747
self.assertNotEqual(encrypted1, encrypted2)
4848

49-
class SignatureTest(unittest.TestCase):
49+
class SignatureTest(unittest2.TestCase):
5050

5151
def setUp(self):
5252
(self.pub, self.priv) = rsa.newkeys(512)

tests/test_strings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
from __future__ import absolute_import
44

5-
import unittest
5+
import unittest2
66

77
import rsa
88

99
from tests.constants import unicode_string
1010

11-
class StringTest(unittest.TestCase):
11+
class StringTest(unittest2.TestCase):
1212

1313
def setUp(self):
1414
(self.pub, self.priv) = rsa.newkeys(384)

tests/test_varblock.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
'''Tests varblock operations.'''
22

3+
34
try:
4-
from StringIO import StringIO
5+
from StringIO import StringIO as BytesIO
56
except ImportError:
6-
from io import StringIO
7+
from io import BytesIO
78
import unittest
89

910
import rsa
11+
from rsa._compat import b
1012
from rsa import varblock
1113

1214
class VarintTest(unittest.TestCase):
1315

1416
def test_read_varint(self):
1517

16-
encoded = '\xac\x02crummy'
17-
infile = StringIO(encoded)
18+
encoded = b('\xac\x02crummy')
19+
infile = BytesIO(encoded)
1820

1921
(decoded, read) = varblock.read_varint(infile)
2022

@@ -23,12 +25,12 @@ def test_read_varint(self):
2325
self.assertEqual(2, read)
2426

2527
# The rest of the file should be untouched
26-
self.assertEqual('crummy', infile.read())
28+
self.assertEqual(b('crummy'), infile.read())
2729

2830
def test_read_zero(self):
2931

30-
encoded = '\x00crummy'
31-
infile = StringIO(encoded)
32+
encoded = b('\x00crummy')
33+
infile = BytesIO(encoded)
3234

3335
(decoded, read) = varblock.read_varint(infile)
3436

@@ -37,12 +39,12 @@ def test_read_zero(self):
3739
self.assertEqual(1, read)
3840

3941
# The rest of the file should be untouched
40-
self.assertEqual('crummy', infile.read())
42+
self.assertEqual(b('crummy'), infile.read())
4143

4244
def test_write_varint(self):
4345

44-
expected = '\xac\x02'
45-
outfile = StringIO()
46+
expected = b('\xac\x02')
47+
outfile = BytesIO()
4648

4749
written = varblock.write_varint(outfile, 300)
4850

@@ -53,28 +55,28 @@ def test_write_varint(self):
5355

5456
def test_write_zero(self):
5557

56-
outfile = StringIO()
58+
outfile = BytesIO()
5759
written = varblock.write_varint(outfile, 0)
5860

5961
# Test the returned values
60-
self.assertEqual('\x00', outfile.getvalue())
62+
self.assertEqual(b('\x00'), outfile.getvalue())
6163
self.assertEqual(1, written)
6264

6365

6466
class VarblockTest(unittest.TestCase):
6567

6668
def test_yield_varblock(self):
67-
infile = StringIO('\x01\x0512345\x06Sybren')
69+
infile = BytesIO(b('\x01\x0512345\x06Sybren'))
6870

6971
varblocks = list(varblock.yield_varblocks(infile))
70-
self.assertEqual(['12345', 'Sybren'], varblocks)
72+
self.assertEqual([b('12345'), b('Sybren')], varblocks)
7173

7274
class FixedblockTest(unittest.TestCase):
7375

7476
def test_yield_fixedblock(self):
7577

76-
infile = StringIO('123456Sybren')
78+
infile = BytesIO(b('123456Sybren'))
7779

7880
fixedblocks = list(varblock.yield_fixedblocks(infile, 6))
79-
self.assertEqual(['123456', 'Sybren'], fixedblocks)
81+
self.assertEqual([b('123456'), b('Sybren')], fixedblocks)
8082

0 commit comments

Comments
 (0)