Skip to content

Commit 433adfd

Browse files
mattsb42-awslizroth
authored andcommitted
reorganize examples cross-imports to simplify tests (#157)
1 parent d6c39a7 commit 433adfd

7 files changed

+44
-42
lines changed

examples/__init__.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
"""Stub to allow relative imports of examples from tests."""

examples/test/examples_test_utils.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
"""Helper utilities for use while testing examples."""
14+
import os
15+
import sys
16+
17+
os.environ["AWS_ENCRYPTION_SDK_EXAMPLES_TESTING"] = "yes"
18+
sys.path.extend([os.sep.join([os.path.dirname(__file__), "..", "..", "test", "integration"])])
19+
20+
from integration_test_utils import get_cmk_arn # noqa pylint: disable=unused-import,import-error

examples/test/pylintrc

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ disable =
66
wrong-import-position, # similar to E0401, pylint does not appear to identify
77
# unknown modules as non-standard-library. flake8 tests for this as well
88
# and does treat them properly
9-
import-error, # because the examples are not actually in a module, sys.path
10-
# is patched to find tests and test utils. pylint does not recognize this
119
duplicate-code, # tests for similar things tend to be similar
1210

1311
[VARIABLES]

examples/test/test_i_basic_encryption.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+
# Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License"). You
44
# may not use this file except in compliance with the License. A copy of
@@ -12,20 +12,12 @@
1212
# language governing permissions and limitations under the License.
1313
"""Unit test suite for the Strings examples in the AWS-hosted documentation."""
1414
import os
15-
import sys
16-
17-
sys.path.extend(
18-
[ # noqa
19-
os.sep.join([os.path.dirname(__file__), "..", "..", "test", "integration"]),
20-
os.sep.join([os.path.dirname(__file__), "..", "src"]),
21-
]
22-
)
2315

2416
import botocore.session
2517
import pytest
2618

27-
from basic_encryption import cycle_string
28-
from integration_test_utils import get_cmk_arn
19+
from ..src.basic_encryption import cycle_string
20+
from .examples_test_utils import get_cmk_arn
2921

3022

3123
pytestmark = [pytest.mark.examples]

examples/test/test_i_basic_file_encryption_with_multiple_providers.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+
# Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License"). You
44
# may not use this file except in compliance with the License. A copy of
@@ -12,21 +12,13 @@
1212
# language governing permissions and limitations under the License.
1313
"""Unit test suite for the Bytes Streams Multiple Providers examples in the AWS-hosted documentation."""
1414
import os
15-
import sys
16-
17-
sys.path.extend(
18-
[ # noqa
19-
os.sep.join([os.path.dirname(__file__), "..", "..", "test", "integration"]),
20-
os.sep.join([os.path.dirname(__file__), "..", "src"]),
21-
]
22-
)
2315
import tempfile
2416

2517
import botocore.session
2618
import pytest
2719

28-
from basic_file_encryption_with_multiple_providers import cycle_file
29-
from integration_test_utils import get_cmk_arn
20+
from ..src.basic_file_encryption_with_multiple_providers import cycle_file
21+
from .examples_test_utils import get_cmk_arn
3022

3123

3224
pytestmark = [pytest.mark.examples]

examples/test/test_i_basic_file_encryption_with_raw_key_provider.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+
# Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License"). You
44
# may not use this file except in compliance with the License. A copy of
@@ -12,14 +12,11 @@
1212
# language governing permissions and limitations under the License.
1313
"""Unit test suite for the Bytes Streams examples in the AWS-hosted documentation."""
1414
import os
15-
import sys
16-
17-
sys.path.extend([os.sep.join([os.path.dirname(__file__), "..", "src"])]) # noqa
1815
import tempfile
1916

2017
import pytest
2118

22-
from basic_file_encryption_with_raw_key_provider import cycle_file
19+
from ..src.basic_file_encryption_with_raw_key_provider import cycle_file
2320

2421

2522
pytestmark = [pytest.mark.examples]

examples/test/test_i_data_key_caching_basic.py

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+
# Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License"). You
44
# may not use this file except in compliance with the License. A copy of
@@ -11,20 +11,10 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313
"""Unit test suite for the basic data key caching example in the AWS-hosted documentation."""
14-
import os
15-
import sys
16-
17-
sys.path.extend(
18-
[ # noqa
19-
os.sep.join([os.path.dirname(__file__), "..", "..", "test", "integration"]),
20-
os.sep.join([os.path.dirname(__file__), "..", "src"]),
21-
]
22-
)
23-
2414
import pytest
2515

26-
from data_key_caching_basic import encrypt_with_caching
27-
from integration_test_utils import get_cmk_arn
16+
from ..src.data_key_caching_basic import encrypt_with_caching
17+
from .examples_test_utils import get_cmk_arn
2818

2919

3020
pytestmark = [pytest.mark.examples]

0 commit comments

Comments
 (0)