Skip to content

Migrated "test/unit/test_aws_encryption_sdk.py" from unittest to pytest #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 17, 2018
15 changes: 7 additions & 8 deletions test/unit/test_aws_encryption_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 high-level functions in aws_encryption_sdk module"""
import unittest

import pytest
import six
from mock import MagicMock, patch, sentinel

import aws_encryption_sdk
Expand All @@ -23,8 +20,9 @@
pytestmark = [pytest.mark.unit, pytest.mark.local]


class TestAwsEncryptionSdk(unittest.TestCase):
def setUp(self):
class TestAwsEncryptionSdk(object):
@pytest.fixture(autouse=True)
def apply_fixtures(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as #127 : need to run teardown actions.

# Set up StreamEncryptor patch
self.mock_stream_encryptor_patcher = patch("aws_encryption_sdk.StreamEncryptor")
self.mock_stream_encryptor = self.mock_stream_encryptor_patcher.start()
Expand All @@ -41,8 +39,8 @@ def setUp(self):
self.mock_stream_decryptor_instance.header = sentinel.header
self.mock_stream_decryptor.return_value = self.mock_stream_decryptor_instance
self.mock_stream_decryptor_instance.__enter__.return_value = self.mock_stream_decryptor_instance

def tearDown(self):
yield
# Run tearDown
self.mock_stream_encryptor_patcher.stop()
self.mock_stream_decryptor_patcher.stop()

Expand Down Expand Up @@ -77,5 +75,6 @@ def test_stream_decryptor_decrypt(self):
assert test is self.mock_stream_decryptor_instance

def test_stream_unknown(self):
with six.assertRaisesRegex(self, ValueError, "Unsupported mode: *"):
with pytest.raises(ValueError) as excinfo:
aws_encryption_sdk.stream(mode="ERROR", a=sentinel.a, b=sentinel.b, c=sentinel.b)
excinfo.match("Unsupported mode: *")