diff --git a/tests/cbc/test_cbc.py b/tests/cbc/test_cbc.py index a3bd906..ea4294b 100644 --- a/tests/cbc/test_cbc.py +++ b/tests/cbc/test_cbc.py @@ -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): diff --git a/tests/ctr/test_ctr.py b/tests/ctr/test_ctr.py index 9fda80e..595a288 100644 --- a/tests/ctr/test_ctr.py +++ b/tests/ctr/test_ctr.py @@ -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): diff --git a/tests/ige/test_ige.py b/tests/ige/test_ige.py index bce6fad..1739741 100644 --- a/tests/ige/test_ige.py +++ b/tests/ige/test_ige.py @@ -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):