From 7c4580d1f430fd66fed02947feca8d38e117392c Mon Sep 17 00:00:00 2001 From: mattsb42-aws Date: Wed, 29 May 2019 12:14:48 -0700 Subject: [PATCH] reorganize examples cross-imports to simplify tests --- examples/__init__.py | 13 ++++++++++++ examples/test/examples_test_utils.py | 20 +++++++++++++++++++ examples/test/pylintrc | 2 -- examples/test/test_i_basic_encryption.py | 14 +++---------- ...file_encryption_with_multiple_providers.py | 14 +++---------- ...c_file_encryption_with_raw_key_provider.py | 7 ++----- .../test/test_i_data_key_caching_basic.py | 16 +++------------ 7 files changed, 44 insertions(+), 42 deletions(-) create mode 100644 examples/__init__.py create mode 100644 examples/test/examples_test_utils.py diff --git a/examples/__init__.py b/examples/__init__.py new file mode 100644 index 000000000..9cef784c2 --- /dev/null +++ b/examples/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). You +# may not use this file except in compliance with the License. A copy of +# the License is located at +# +# http://aws.amazon.com/apache2.0/ +# +# or in the "license" file accompanying this file. This file is +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF +# ANY KIND, either express or implied. See the License for the specific +# language governing permissions and limitations under the License. +"""Stub to allow relative imports of examples from tests.""" diff --git a/examples/test/examples_test_utils.py b/examples/test/examples_test_utils.py new file mode 100644 index 000000000..669d8e823 --- /dev/null +++ b/examples/test/examples_test_utils.py @@ -0,0 +1,20 @@ +# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). You +# may not use this file except in compliance with the License. A copy of +# the License is located at +# +# http://aws.amazon.com/apache2.0/ +# +# or in the "license" file accompanying this file. This file is +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF +# ANY KIND, either express or implied. See the License for the specific +# language governing permissions and limitations under the License. +"""Helper utilities for use while testing examples.""" +import os +import sys + +os.environ["AWS_ENCRYPTION_SDK_EXAMPLES_TESTING"] = "yes" +sys.path.extend([os.sep.join([os.path.dirname(__file__), "..", "..", "test", "integration"])]) + +from integration_test_utils import get_cmk_arn # noqa pylint: disable=unused-import,import-error diff --git a/examples/test/pylintrc b/examples/test/pylintrc index 64147acf2..b30a3e202 100644 --- a/examples/test/pylintrc +++ b/examples/test/pylintrc @@ -6,8 +6,6 @@ disable = wrong-import-position, # similar to E0401, pylint does not appear to identify # unknown modules as non-standard-library. flake8 tests for this as well # and does treat them properly - import-error, # because the examples are not actually in a module, sys.path - # is patched to find tests and test utils. pylint does not recognize this duplicate-code, # tests for similar things tend to be similar [VARIABLES] diff --git a/examples/test/test_i_basic_encryption.py b/examples/test/test_i_basic_encryption.py index d1e336945..db1e9292a 100644 --- a/examples/test/test_i_basic_encryption.py +++ b/examples/test/test_i_basic_encryption.py @@ -1,4 +1,4 @@ -# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"). You # may not use this file except in compliance with the License. A copy of @@ -12,20 +12,12 @@ # language governing permissions and limitations under the License. """Unit test suite for the Strings examples in the AWS-hosted documentation.""" import os -import sys - -sys.path.extend( - [ # noqa - os.sep.join([os.path.dirname(__file__), "..", "..", "test", "integration"]), - os.sep.join([os.path.dirname(__file__), "..", "src"]), - ] -) import botocore.session import pytest -from basic_encryption import cycle_string -from integration_test_utils import get_cmk_arn +from ..src.basic_encryption import cycle_string +from .examples_test_utils import get_cmk_arn pytestmark = [pytest.mark.examples] diff --git a/examples/test/test_i_basic_file_encryption_with_multiple_providers.py b/examples/test/test_i_basic_file_encryption_with_multiple_providers.py index cc724e11e..0f91c2017 100644 --- a/examples/test/test_i_basic_file_encryption_with_multiple_providers.py +++ b/examples/test/test_i_basic_file_encryption_with_multiple_providers.py @@ -1,4 +1,4 @@ -# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"). You # may not use this file except in compliance with the License. A copy of @@ -12,21 +12,13 @@ # language governing permissions and limitations under the License. """Unit test suite for the Bytes Streams Multiple Providers examples in the AWS-hosted documentation.""" import os -import sys - -sys.path.extend( - [ # noqa - os.sep.join([os.path.dirname(__file__), "..", "..", "test", "integration"]), - os.sep.join([os.path.dirname(__file__), "..", "src"]), - ] -) import tempfile import botocore.session import pytest -from basic_file_encryption_with_multiple_providers import cycle_file -from integration_test_utils import get_cmk_arn +from ..src.basic_file_encryption_with_multiple_providers import cycle_file +from .examples_test_utils import get_cmk_arn pytestmark = [pytest.mark.examples] diff --git a/examples/test/test_i_basic_file_encryption_with_raw_key_provider.py b/examples/test/test_i_basic_file_encryption_with_raw_key_provider.py index a812a92db..6b744353e 100644 --- a/examples/test/test_i_basic_file_encryption_with_raw_key_provider.py +++ b/examples/test/test_i_basic_file_encryption_with_raw_key_provider.py @@ -1,4 +1,4 @@ -# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"). You # may not use this file except in compliance with the License. A copy of @@ -12,14 +12,11 @@ # language governing permissions and limitations under the License. """Unit test suite for the Bytes Streams examples in the AWS-hosted documentation.""" import os -import sys - -sys.path.extend([os.sep.join([os.path.dirname(__file__), "..", "src"])]) # noqa import tempfile import pytest -from basic_file_encryption_with_raw_key_provider import cycle_file +from ..src.basic_file_encryption_with_raw_key_provider import cycle_file pytestmark = [pytest.mark.examples] diff --git a/examples/test/test_i_data_key_caching_basic.py b/examples/test/test_i_data_key_caching_basic.py index 5147db652..734c35692 100644 --- a/examples/test/test_i_data_key_caching_basic.py +++ b/examples/test/test_i_data_key_caching_basic.py @@ -1,4 +1,4 @@ -# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"). You # may not use this file except in compliance with the License. A copy of @@ -11,20 +11,10 @@ # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. """Unit test suite for the basic data key caching example in the AWS-hosted documentation.""" -import os -import sys - -sys.path.extend( - [ # noqa - os.sep.join([os.path.dirname(__file__), "..", "..", "test", "integration"]), - os.sep.join([os.path.dirname(__file__), "..", "src"]), - ] -) - import pytest -from data_key_caching_basic import encrypt_with_caching -from integration_test_utils import get_cmk_arn +from ..src.data_key_caching_basic import encrypt_with_caching +from .examples_test_utils import get_cmk_arn pytestmark = [pytest.mark.examples]