Fix TypeError tests for Python 3.4

This commit is contained in:
Dan 2019-06-14 19:36:06 +02:00
parent aabb77de64
commit 0fe11896d9
3 changed files with 12 additions and 6 deletions

View File

@ -133,12 +133,14 @@ class TestCBC256Cryptography(unittest.TestCase):
class TestCBC256Input(unittest.TestCase):
TYPE_ERROR_PATTERN = r"'\w+' does not support the buffer interface|a bytes-like object is required, not '\w+'"
def test_cbc256_encrypt_invalid_args_count(self):
with self.assertRaisesRegex(TypeError, r"function takes exactly \d arguments \(\d given\)"):
tgcrypto.cbc256_encrypt(os.urandom(16), os.urandom(32))
def test_cbc256_encrypt_invalid_args_type(self):
with self.assertRaisesRegex(TypeError, r"a bytes-like object is required, not '\w+'"):
with self.assertRaisesRegex(TypeError, self.TYPE_ERROR_PATTERN):
tgcrypto.cbc256_encrypt(1, 2, 3)
def test_cbc256_encrypt_empty_data(self):
@ -158,7 +160,7 @@ class TestCBC256Input(unittest.TestCase):
tgcrypto.cbc256_decrypt(os.urandom(16), os.urandom(32))
def test_cbc256_decrypt_invalid_args_type(self):
with self.assertRaisesRegex(TypeError, r"a bytes-like object is required, not '\w+'"):
with self.assertRaisesRegex(TypeError, self.TYPE_ERROR_PATTERN):
tgcrypto.cbc256_decrypt(1, 2, 3)
def test_cbc256_decrypt_empty_data(self):

View File

@ -108,12 +108,14 @@ class TestCTR256Cryptography(unittest.TestCase):
class TestCTR256Input(unittest.TestCase):
TYPE_ERROR_PATTERN = r"'\w+' does not support the buffer interface|a bytes-like object is required, not '\w+'"
def test_ctr256_encrypt_invalid_args_count(self):
with self.assertRaisesRegex(TypeError, r"function takes exactly \d arguments \(\d given\)"):
tgcrypto.ctr256_encrypt(os.urandom(8), os.urandom(32), os.urandom(16))
def test_ctr256_encrypt_invalid_args_type(self):
with self.assertRaisesRegex(TypeError, r"a bytes-like object is required, not '\w+'"):
with self.assertRaisesRegex(TypeError, self.TYPE_ERROR_PATTERN):
tgcrypto.ctr256_encrypt(1, 2, 3, 4)
def test_ctr256_encrypt_empty_data(self):
@ -141,7 +143,7 @@ class TestCTR256Input(unittest.TestCase):
tgcrypto.ctr256_decrypt(os.urandom(8), os.urandom(32), os.urandom(16))
def test_ctr256_decrypt_invalid_args_type(self):
with self.assertRaisesRegex(TypeError, r"a bytes-like object is required, not '\w+'"):
with self.assertRaisesRegex(TypeError, self.TYPE_ERROR_PATTERN):
tgcrypto.ctr256_decrypt(1, 2, 3, 4)
def test_ctr256_decrypt_empty_data(self):

View File

@ -24,12 +24,14 @@ import tgcrypto
class TestIGE256Input(unittest.TestCase):
TYPE_ERROR_PATTERN = r"'\w+' does not support the buffer interface|a bytes-like object is required, not '\w+'"
def test_ige256_encrypt_invalid_args_count(self):
with self.assertRaisesRegex(TypeError, r"function takes exactly \d arguments \(\d given\)"):
tgcrypto.ige256_encrypt(os.urandom(16), os.urandom(32))
def test_ige256_encrypt_invalid_args_type(self):
with self.assertRaisesRegex(TypeError, r"a bytes-like object is required, not '\w+'"):
with self.assertRaisesRegex(TypeError, self.TYPE_ERROR_PATTERN):
tgcrypto.ige256_encrypt(1, 2, 3)
def test_ige256_encrypt_empty_data(self):
@ -49,7 +51,7 @@ class TestIGE256Input(unittest.TestCase):
tgcrypto.ige256_decrypt(os.urandom(16), os.urandom(32))
def test_ige256_decrypt_invalid_args_type(self):
with self.assertRaisesRegex(TypeError, r"a bytes-like object is required, not '\w+'"):
with self.assertRaisesRegex(TypeError, self.TYPE_ERROR_PATTERN):
tgcrypto.ige256_decrypt(1, 2, 3)
def test_ige256_decrypt_empty_data(self):