Skip to content

reorganize examples cross-imports to simplify tests #157

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 1 commit into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/__init__.py
Original file line number Diff line number Diff line change
@@ -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."""
20 changes: 20 additions & 0 deletions examples/test/examples_test_utils.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions examples/test/pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 3 additions & 11 deletions examples/test/test_i_basic_encryption.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]
Expand Down
16 changes: 3 additions & 13 deletions examples/test/test_i_data_key_caching_basic.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]
Expand Down