diff --git a/test/unit/test_encryption_context.py b/test/unit/test_encryption_context.py index 764901b1f..187365783 100644 --- a/test/unit/test_encryption_context.py +++ b/test/unit/test_encryption_context.py @@ -11,10 +11,7 @@ # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. """Unit test suite for aws_encryption_sdk.internal.formatting.encryption_context""" -import unittest - import pytest -import six import aws_encryption_sdk.internal.defaults import aws_encryption_sdk.internal.formatting.encryption_context @@ -26,7 +23,7 @@ pytestmark = [pytest.mark.unit, pytest.mark.local] -class TestEncryptionContext(unittest.TestCase): +class TestEncryptionContext(object): def test_assemble_content_aad(self): """Validate that the assemble_content_aad function behaves as expected. @@ -40,10 +37,11 @@ def test_assemble_content_aad(self): assert test == VALUES["non_framed_aac"] def test_assemble_content_aad_unknown_type(self): - with six.assertRaisesRegex(self, SerializationError, "Unknown aad_content_string"): + with pytest.raises(SerializationError) as excinfo: aws_encryption_sdk.internal.formatting.encryption_context.assemble_content_aad( message_id=VALUES["message_id"], aad_content_string=None, seq_num=1, length=VALUES["content_len"] ) + excinfo.match("Unknown aad_content_string") def test_serialize_encryption_context_no_encryption_context(self): """Validate that the serialize_encryption_context @@ -59,20 +57,22 @@ def test_serialize_encryption_context_too_many_elements(self): with an encryption context with too many elements. """ - with six.assertRaisesRegex(self, SerializationError, "The encryption context contains too many elements."): + with pytest.raises(SerializationError) as excinfo: aws_encryption_sdk.internal.formatting.encryption_context.serialize_encryption_context( VALUES["encryption_context_too_many_elements"] ) + excinfo.match("The encryption context contains too many elements.") def test_serialize_encryption_context_too_large(self): """Validate that the serialize_encryption_context function behaves as expected when presented with an encryption context which is too large. """ - with six.assertRaisesRegex(self, SerializationError, "The serialized context is too large"): + with pytest.raises(SerializationError) as excinfo: aws_encryption_sdk.internal.formatting.encryption_context.serialize_encryption_context( VALUES["encryption_context_too_large"] ) + excinfo.match("The serialized context is too large") def test_serialize_encryption_context_unencodable(self): """Validate that the serialize_encryption_context @@ -81,10 +81,11 @@ def test_serialize_encryption_context_unencodable(self): unencodable elements. """ for encryption_context in [{"a": b"\xc4"}, {b"\xc4": "a"}, {b"\xc4": b"\xc4"}]: - with six.assertRaisesRegex(self, SerializationError, "Cannot encode dictionary key or value using *"): + with pytest.raises(SerializationError) as excinfo: aws_encryption_sdk.internal.formatting.encryption_context.serialize_encryption_context( encryption_context ) + excinfo.match("Cannot encode dictionary key or value using *") def test_serialize_encryption_context_valid(self): """Validate that the serialize_encryption_context @@ -100,8 +101,9 @@ def test_read_short_too_short(self): """Validate that the read_short function behaves as expected when it encounters a struct error. """ - with six.assertRaisesRegex(self, SerializationError, "Bad format of serialized context."): + with pytest.raises(SerializationError) as excinfo: aws_encryption_sdk.internal.formatting.encryption_context.read_short(b"d", 0) + excinfo.match("Bad format of serialized context.") def test_read_short_valid(self): """Validate that the read_short function behaves @@ -116,8 +118,9 @@ def test_read_string_encoding_error(self): as expected when it encounters an encoding error. """ - with six.assertRaisesRegex(self, SerializationError, "Bad format of serialized context."): + with pytest.raises(SerializationError) as excinfo: aws_encryption_sdk.internal.formatting.encryption_context.read_string(b"\xc4", 0, 1) + excinfo.match("Bad format of serialized context.") def test_read_string_valid(self): """Validate that the read_string function behaves @@ -136,10 +139,11 @@ def test_deserialize_encryption_context_too_large(self): data = "" for i in range(aws_encryption_sdk.internal.defaults.MAX_BYTE_ARRAY_SIZE + 1): data += str(i) - with six.assertRaisesRegex(self, SerializationError, "Serialized context is too long."): + with pytest.raises(SerializationError) as excinfo: aws_encryption_sdk.internal.formatting.encryption_context.deserialize_encryption_context( serialized_encryption_context=data ) + excinfo.match("Serialized context is too long.") def test_deserialize_encryption_context_duplicate_key(self): """Validate that the deserialize_encryption_context @@ -147,10 +151,11 @@ def test_deserialize_encryption_context_duplicate_key(self): a serialized encryption context which contains duplicate keys. """ - with six.assertRaisesRegex(self, SerializationError, "Duplicate key in serialized context."): + with pytest.raises(SerializationError) as excinfo: aws_encryption_sdk.internal.formatting.encryption_context.deserialize_encryption_context( serialized_encryption_context=VALUES["serialized_encryption_context_duplicate_key"] ) + excinfo.match("Duplicate key in serialized context.") def test_deserialize_encryption_context_extra_data(self): """Validate that the deserialize_encryption_context @@ -160,10 +165,11 @@ def test_deserialize_encryption_context_extra_data(self): of pairs (formatting error). """ data = VALUES["serialized_encryption_context"] + b"jhofguijhsuskldfh" - with six.assertRaisesRegex(self, SerializationError, "Formatting error: Extra data in serialized context."): + with pytest.raises(SerializationError) as excinfo: aws_encryption_sdk.internal.formatting.encryption_context.deserialize_encryption_context( serialized_encryption_context=data ) + excinfo.match("Formatting error: Extra data in serialized context.") def test_deserialize_encryption_context_valid(self): """Validate that the deserialize_encryption_context