From 1f48bd20dd83e9924f9c72606263bd123e1e5e39 Mon Sep 17 00:00:00 2001 From: mattsb42-aws Date: Thu, 29 Mar 2018 13:41:32 -0700 Subject: [PATCH 1/2] flake8-tests fixes --- test/acceptance/__init__.py | 1 + test/acceptance/acceptance_test_utils.py | 23 +++++------ test/acceptance/encrypted/__init__.py | 1 + test/acceptance/encrypted/test_item.py | 2 +- test/functional/__init__.py | 1 + test/functional/encrypted/__init__.py | 1 + test/functional/encrypted/test_client.py | 13 ++++--- test/functional/encrypted/test_item.py | 9 +++-- test/functional/encrypted/test_resource.py | 9 ++--- test/functional/encrypted/test_table.py | 9 +++-- test/functional/functional_test_utils.py | 30 ++++++++------- .../functional_test_vector_generators.py | 7 ++-- test/functional/hypothesis_strategies.py | 38 +++++++++---------- test/functional/internal/__init__.py | 1 + test/functional/internal/crypto/__init__.py | 1 + .../internal/crypto/test_authentication.py | 2 +- .../internal/formatting/__init__.py | 1 + .../formatting/test_material_description.py | 4 +- .../{test_f_str_ops.py => test_str_ops.py} | 2 +- test/functional/test_identifiers.py | 1 + test/functional/test_structures.py | 2 +- test/integration/__init__.py | 1 + test/integration/integration_test_utils.py | 16 +++++--- .../material_providers/__init__.py | 1 + .../material_providers/test_aws_kms.py | 4 +- test/pylintrc | 2 +- test/unit/__init__.py | 1 + test/unit/material_providers/__init__.py | 1 + test/unit/material_providers/test_aws_kms.py | 1 + 29 files changed, 105 insertions(+), 80 deletions(-) rename test/functional/internal/{test_f_str_ops.py => test_str_ops.py} (95%) diff --git a/test/acceptance/__init__.py b/test/acceptance/__init__.py index 1ccc7fa1..2add15ef 100644 --- a/test/acceptance/__init__.py +++ b/test/acceptance/__init__.py @@ -10,3 +10,4 @@ # 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. +"""Dummy stub to make linters work better.""" diff --git a/test/acceptance/acceptance_test_utils.py b/test/acceptance/acceptance_test_utils.py index dae4cd9c..7595bebe 100644 --- a/test/acceptance/acceptance_test_utils.py +++ b/test/acceptance/acceptance_test_utils.py @@ -10,29 +10,31 @@ # 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 tools for use with acceptance tests.""" import base64 from collections import defaultdict import json import os import sys -sys.path.append(os.path.join( - os.path.abspath(os.path.dirname(__file__)), - '..', - 'functional' -)) import pytest from six.moves.urllib.parse import urlparse - +from dynamodb_encryption_sdk.delegated_keys.jce import JceNameLocalDelegatedKey +from dynamodb_encryption_sdk.identifiers import EncryptionKeyTypes, KeyEncodingType from dynamodb_encryption_sdk.material_providers.static import StaticCryptographicMaterialsProvider from dynamodb_encryption_sdk.material_providers.wrapped import WrappedCryptographicMaterialsProvider -from dynamodb_encryption_sdk.materials.raw import RawDecryptionMaterials, RawEncryptionMaterials -from dynamodb_encryption_sdk.delegated_keys.jce import JceNameLocalDelegatedKey -from dynamodb_encryption_sdk.identifiers import EncryptionKeyTypes, ItemAction, KeyEncodingType +from dynamodb_encryption_sdk.materials.raw import RawDecryptionMaterials from dynamodb_encryption_sdk.structures import AttributeActions -import functional_test_vector_generators +sys.path.append(os.path.join( + os.path.abspath(os.path.dirname(__file__)), + '..', + 'functional' +)) + +# Convenience imports +import functional_test_vector_generators # noqa: E402,I100 _ENCRYPTED_ITEM_VECTORS_DIR = os.path.join( os.path.abspath(os.path.dirname(__file__)), @@ -64,7 +66,6 @@ def _decode_item(item): def _build_plaintext_items(plaintext_file, version): - """""" with open(plaintext_file) as f: plaintext_data = json.load(f) diff --git a/test/acceptance/encrypted/__init__.py b/test/acceptance/encrypted/__init__.py index 1ccc7fa1..2add15ef 100644 --- a/test/acceptance/encrypted/__init__.py +++ b/test/acceptance/encrypted/__init__.py @@ -10,3 +10,4 @@ # 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. +"""Dummy stub to make linters work better.""" diff --git a/test/acceptance/encrypted/test_item.py b/test/acceptance/encrypted/test_item.py index c9123f68..073a069d 100644 --- a/test/acceptance/encrypted/test_item.py +++ b/test/acceptance/encrypted/test_item.py @@ -10,12 +10,12 @@ # 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. +"""Acceptance tests for ``dynamodb_encryption_sdk.encrypted.item``.""" import pytest from dynamodb_encryption_sdk.encrypted import CryptoConfig from dynamodb_encryption_sdk.encrypted.item import decrypt_dynamodb_item from dynamodb_encryption_sdk.structures import EncryptionContext - from ..acceptance_test_utils import load_scenarios pytestmark = [pytest.mark.acceptance, pytest.mark.local] diff --git a/test/functional/__init__.py b/test/functional/__init__.py index 1ccc7fa1..2add15ef 100644 --- a/test/functional/__init__.py +++ b/test/functional/__init__.py @@ -10,3 +10,4 @@ # 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. +"""Dummy stub to make linters work better.""" diff --git a/test/functional/encrypted/__init__.py b/test/functional/encrypted/__init__.py index 1ccc7fa1..2add15ef 100644 --- a/test/functional/encrypted/__init__.py +++ b/test/functional/encrypted/__init__.py @@ -10,3 +10,4 @@ # 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. +"""Dummy stub to make linters work better.""" diff --git a/test/functional/encrypted/test_client.py b/test/functional/encrypted/test_client.py index 4d690754..93e82ab2 100644 --- a/test/functional/encrypted/test_client.py +++ b/test/functional/encrypted/test_client.py @@ -10,18 +10,19 @@ # 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. -"""""" +"""Functional tests for ``dynamodb_encryption_sdk.encrypted.client``.""" import boto3 import hypothesis import pytest +from dynamodb_encryption_sdk.encrypted.client import EncryptedClient +from dynamodb_encryption_sdk.internal.formatting.transform import ddb_to_dict, dict_to_ddb from ..functional_test_utils import ( - check_encrypted_item, example_table, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item, - cycle_batch_item_check, TEST_KEY, TEST_TABLE_NAME + check_encrypted_item, cycle_batch_item_check, set_parametrized_actions, set_parametrized_cmp, + set_parametrized_item, TEST_KEY, TEST_TABLE_NAME ) +from ..functional_test_utils import example_table # noqa from ..hypothesis_strategies import ddb_items, SLOW_SETTINGS, VERY_SLOW_SETTINGS -from dynamodb_encryption_sdk.encrypted.client import EncryptedClient -from dynamodb_encryption_sdk.internal.formatting.transform import ddb_to_dict, dict_to_ddb pytestmark = [pytest.mark.functional, pytest.mark.local] @@ -47,7 +48,7 @@ def _client_cycle_single_item_check(materials_provider, initial_actions, initial attribute_actions=initial_actions ) - _put_result = e_client.put_item( + _put_result = e_client.put_item( # noqa TableName=TEST_TABLE_NAME, Item=ddb_item ) diff --git a/test/functional/encrypted/test_item.py b/test/functional/encrypted/test_item.py index c8ec1ef3..856dc764 100644 --- a/test/functional/encrypted/test_item.py +++ b/test/functional/encrypted/test_item.py @@ -10,18 +10,19 @@ # 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. +"""Functional tests for ``dynamodb_encryption_sdk.encrypted.item``.""" import hypothesis import pytest -from ..functional_test_utils import ( - build_static_jce_cmp, cycle_item_check, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item -) -from ..hypothesis_strategies import ddb_items, SLOW_SETTINGS, VERY_SLOW_SETTINGS from dynamodb_encryption_sdk.encrypted import CryptoConfig from dynamodb_encryption_sdk.encrypted.item import decrypt_python_item, encrypt_python_item from dynamodb_encryption_sdk.exceptions import DecryptionError, EncryptionError from dynamodb_encryption_sdk.internal.identifiers import ReservedAttributes from dynamodb_encryption_sdk.structures import AttributeActions, EncryptionContext +from ..functional_test_utils import ( + build_static_jce_cmp, cycle_item_check, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item +) +from ..hypothesis_strategies import ddb_items, SLOW_SETTINGS, VERY_SLOW_SETTINGS pytestmark = [pytest.mark.functional, pytest.mark.local] diff --git a/test/functional/encrypted/test_resource.py b/test/functional/encrypted/test_resource.py index dabbe8bf..aa62b606 100644 --- a/test/functional/encrypted/test_resource.py +++ b/test/functional/encrypted/test_resource.py @@ -10,16 +10,15 @@ # 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. -"""""" +"""Functional tests for ``dynamodb_encryption_sdk.encrypted.resource``.""" import boto3 import pytest +from dynamodb_encryption_sdk.encrypted.resource import EncryptedResource from ..functional_test_utils import ( - example_table, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item, - cycle_batch_item_check, TEST_TABLE_NAME + cycle_batch_item_check, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item, TEST_TABLE_NAME ) -from ..hypothesis_strategies import ddb_items, SLOW_SETTINGS, VERY_SLOW_SETTINGS -from dynamodb_encryption_sdk.encrypted.resource import EncryptedResource +from ..functional_test_utils import example_table # noqa pytestmark = [pytest.mark.functional, pytest.mark.local] diff --git a/test/functional/encrypted/test_table.py b/test/functional/encrypted/test_table.py index 03cbcaf4..b9b73dd3 100644 --- a/test/functional/encrypted/test_table.py +++ b/test/functional/encrypted/test_table.py @@ -10,17 +10,18 @@ # 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. -"""""" +"""Functional tests for ``dynamodb_encryption_sdk.encrypted.table``.""" import boto3 import hypothesis import pytest +from dynamodb_encryption_sdk.encrypted.table import EncryptedTable from ..functional_test_utils import ( - check_encrypted_item, example_table, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item, + check_encrypted_item, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item, TEST_KEY, TEST_TABLE_NAME ) +from ..functional_test_utils import example_table # noqa from ..hypothesis_strategies import ddb_items, SLOW_SETTINGS, VERY_SLOW_SETTINGS -from dynamodb_encryption_sdk.encrypted.table import EncryptedTable pytestmark = [pytest.mark.functional, pytest.mark.local] @@ -44,7 +45,7 @@ def _table_cycle_check(materials_provider, initial_actions, initial_item): attribute_actions=initial_actions, ) - _put_result = e_table.put_item(Item=item) + _put_result = e_table.put_item(Item=item) # noqa encrypted_result = table.get_item(Key=TEST_KEY) check_encrypted_item(item, encrypted_result['Item'], check_attribute_actions) diff --git a/test/functional/functional_test_utils.py b/test/functional/functional_test_utils.py index cd0422be..a7043f17 100644 --- a/test/functional/functional_test_utils.py +++ b/test/functional/functional_test_utils.py @@ -10,9 +10,11 @@ # 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 tools for use in tests.""" from __future__ import division -import copy + from collections import defaultdict +import copy from decimal import Decimal import itertools @@ -28,7 +30,7 @@ from dynamodb_encryption_sdk.material_providers.static import StaticCryptographicMaterialsProvider from dynamodb_encryption_sdk.material_providers.wrapped import WrappedCryptographicMaterialsProvider from dynamodb_encryption_sdk.materials.raw import RawDecryptionMaterials, RawEncryptionMaterials -from dynamodb_encryption_sdk.structures import AttributeActions, EncryptionContext +from dynamodb_encryption_sdk.structures import AttributeActions _DELEGATED_KEY_CACHE = defaultdict(lambda: defaultdict(dict)) TEST_TABLE_NAME = 'my_table' @@ -39,7 +41,7 @@ }, 'sort_attribute': { 'type': 'N', - 'value': Decimal('99.233') + 'value': Decimal('99.233') } } TEST_KEY = {name: value['value'] for name, value in TEST_INDEX.items()} @@ -51,7 +53,7 @@ }, 'sort_attribute': { 'type': 'N', - 'value': Decimal('99.233') + 'value': Decimal('99.233') } }, { @@ -61,7 +63,7 @@ }, 'sort_attribute': { 'type': 'N', - 'value': Decimal('92986745') + 'value': Decimal('92986745') } }, { @@ -71,7 +73,7 @@ }, 'sort_attribute': { 'type': 'N', - 'value': Decimal('2231.0001') + 'value': Decimal('2231.0001') } }, { @@ -81,7 +83,7 @@ }, 'sort_attribute': { 'type': 'N', - 'value': Decimal('732342') + 'value': Decimal('732342') } } ] @@ -301,7 +303,7 @@ def set_parametrized_cmp(metafunc): def set_parametrized_actions(metafunc): - """Set parametrized values for attribute actions""" + """Set parametrized values for attribute actions.""" for name, actions in _ACTIONS.items(): if name in metafunc.fixturenames: metafunc.parametrize(name, actions) @@ -362,8 +364,8 @@ def check_encrypted_item(plaintext_item, ciphertext_item, attribute_actions): def _matching_key(actual_item, expected): expected_item = [ i for i in expected - if i['partition_attribute'] == actual_item['partition_attribute'] - and i['sort_attribute'] == actual_item['sort_attribute'] + if i['partition_attribute'] == actual_item['partition_attribute'] and + i['sort_attribute'] == actual_item['sort_attribute'] ] assert len(expected_item) == 1 return expected_item[0] @@ -401,7 +403,7 @@ def cycle_batch_item_check( write_transformer=_nop_transformer, read_transformer=_nop_transformer ): - """Common logic for cycling batch items.""" + """Check that cycling (plaintext->encrypted->decrypted) item batch has the expected results.""" check_attribute_actions = initial_actions.copy() check_attribute_actions.set_index_keys(*list(TEST_KEY.keys())) items = [] @@ -410,7 +412,7 @@ def cycle_batch_item_check( _item.update(key) items.append(write_transformer(_item)) - _put_result = encrypted.batch_write_item( + _put_result = encrypted.batch_write_item( # noqa RequestItems={ TEST_TABLE_NAME: [ {'PutRequest': {'Item': _item}} @@ -447,7 +449,7 @@ def cycle_batch_item_check( transformer=read_transformer ) - _delete_result = encrypted.batch_write_item( + _delete_result = encrypted.batch_write_item( # noqa RequestItems={ TEST_TABLE_NAME: [ {'DeleteRequest': {'Key': _key}} @@ -461,7 +463,7 @@ def cycle_batch_item_check( def cycle_item_check(plaintext_item, crypto_config): - """Common logic for cycled item (plaintext->encrypted->decrypted) tests: used by many test suites.""" + """Check that cycling (plaintext->encrypted->decrypted) an item has the expected results.""" ciphertext_item = encrypt_python_item(plaintext_item, crypto_config) check_encrypted_item(plaintext_item, ciphertext_item, crypto_config.attribute_actions) diff --git a/test/functional/functional_test_vector_generators.py b/test/functional/functional_test_vector_generators.py index a425d2b2..3b3b60c9 100644 --- a/test/functional/functional_test_vector_generators.py +++ b/test/functional/functional_test_vector_generators.py @@ -10,14 +10,15 @@ # 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 tools for attribute de/serialization functional tests.""" +"""Helper tools for collecting test vectors for use in functional tests.""" import base64 -from decimal import Decimal import codecs +from decimal import Decimal import json import os from boto3.dynamodb.types import Binary + from dynamodb_encryption_sdk.identifiers import ItemAction from dynamodb_encryption_sdk.structures import AttributeActions @@ -41,7 +42,7 @@ ) -def decode_value(value, transform_binary=False): +def decode_value(value, transform_binary=False): # noqa: C901 def _decode_string(_value): return _value diff --git a/test/functional/hypothesis_strategies.py b/test/functional/hypothesis_strategies.py index aa0fb8e5..fa7f316c 100644 --- a/test/functional/hypothesis_strategies.py +++ b/test/functional/hypothesis_strategies.py @@ -11,14 +11,14 @@ # 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 resources for functional tests.""" +"""Hypothesis strategies for use in tests.""" from collections import namedtuple from decimal import Decimal from boto3.dynamodb.types import Binary, DYNAMODB_CONTEXT import hypothesis from hypothesis.strategies import ( - binary, booleans, characters, dictionaries, deferred, fractions, just, lists, none, sets, text + binary, booleans, characters, deferred, dictionaries, fractions, just, lists, none, sets, text ) SLOW_SETTINGS = hypothesis.settings( @@ -59,7 +59,7 @@ def _ddb_fraction_to_decimal(val): - """hypothesis does not support providing a custom Context, so working around that""" + """Hypothesis does not support providing a custom Context, so working around that.""" return DYNAMODB_CONTEXT.create_decimal(Decimal(val.numerator) / Decimal(val.denominator)) @@ -82,17 +82,17 @@ def _ddb_fraction_to_decimal(val): ddb_null = none() ddb_scalar_types = ( - ddb_string - | ddb_number - | ddb_binary - | ddb_boolean - | ddb_null + ddb_string | + ddb_number | + ddb_binary | + ddb_boolean | + ddb_null ) ddb_set_types = ( - ddb_string_set - | ddb_number_set - | ddb_binary_set + ddb_string_set | + ddb_number_set | + ddb_binary_set ) ddb_attribute_names = text( min_size=1, @@ -102,18 +102,18 @@ def _ddb_fraction_to_decimal(val): ddb_map_type = deferred(lambda: dictionaries( keys=ddb_attribute_names, values=( - ddb_scalar_types - | ddb_set_types - | ddb_list_type - | ddb_map_type + ddb_scalar_types | + ddb_set_types | + ddb_list_type | + ddb_map_type ), min_size=1 )) ddb_list_type = deferred(lambda: lists( - ddb_scalar_types - | ddb_set_types - | ddb_list_type - | ddb_map_type, + ddb_scalar_types | + ddb_set_types | + ddb_list_type | + ddb_map_type, min_size=1 )) ddb_document_types = ddb_map_type | ddb_list_type diff --git a/test/functional/internal/__init__.py b/test/functional/internal/__init__.py index 1ccc7fa1..2add15ef 100644 --- a/test/functional/internal/__init__.py +++ b/test/functional/internal/__init__.py @@ -10,3 +10,4 @@ # 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. +"""Dummy stub to make linters work better.""" diff --git a/test/functional/internal/crypto/__init__.py b/test/functional/internal/crypto/__init__.py index 1ccc7fa1..2add15ef 100644 --- a/test/functional/internal/crypto/__init__.py +++ b/test/functional/internal/crypto/__init__.py @@ -10,3 +10,4 @@ # 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. +"""Dummy stub to make linters work better.""" diff --git a/test/functional/internal/crypto/test_authentication.py b/test/functional/internal/crypto/test_authentication.py index 1d7635aa..c17a078c 100644 --- a/test/functional/internal/crypto/test_authentication.py +++ b/test/functional/internal/crypto/test_authentication.py @@ -13,8 +13,8 @@ """Functional tests for material description de/serialization.""" import pytest -from ...functional_test_vector_generators import string_to_sign_test_vectors from dynamodb_encryption_sdk.internal.crypto.authentication import _string_to_sign +from ...functional_test_vector_generators import string_to_sign_test_vectors pytestmark = [pytest.mark.functional, pytest.mark.local] diff --git a/test/functional/internal/formatting/__init__.py b/test/functional/internal/formatting/__init__.py index 1ccc7fa1..2add15ef 100644 --- a/test/functional/internal/formatting/__init__.py +++ b/test/functional/internal/formatting/__init__.py @@ -10,3 +10,4 @@ # 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. +"""Dummy stub to make linters work better.""" diff --git a/test/functional/internal/formatting/test_material_description.py b/test/functional/internal/formatting/test_material_description.py index 372f00a0..1fbf219d 100644 --- a/test/functional/internal/formatting/test_material_description.py +++ b/test/functional/internal/formatting/test_material_description.py @@ -14,12 +14,12 @@ import hypothesis import pytest -from ...functional_test_vector_generators import material_description_test_vectors -from ...hypothesis_strategies import material_descriptions, SLOW_SETTINGS, VERY_SLOW_SETTINGS from dynamodb_encryption_sdk.exceptions import InvalidMaterialDescriptionError, InvalidMaterialDescriptionVersionError from dynamodb_encryption_sdk.internal.formatting.material_description import ( deserialize as deserialize_material_description, serialize as serialize_material_description ) +from ...functional_test_vector_generators import material_description_test_vectors +from ...hypothesis_strategies import material_descriptions, SLOW_SETTINGS, VERY_SLOW_SETTINGS pytestmark = [pytest.mark.functional, pytest.mark.local] diff --git a/test/functional/internal/test_f_str_ops.py b/test/functional/internal/test_str_ops.py similarity index 95% rename from test/functional/internal/test_f_str_ops.py rename to test/functional/internal/test_str_ops.py index 08782367..785c5b93 100644 --- a/test/functional/internal/test_f_str_ops.py +++ b/test/functional/internal/test_str_ops.py @@ -11,7 +11,7 @@ # 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. -"""Test suite for dynamodb_encryption_sdk.internal.str_ops""" +"""Test suite for ``dynamodb_encryption_sdk.internal.str_ops``.""" import codecs import pytest diff --git a/test/functional/test_identifiers.py b/test/functional/test_identifiers.py index 61986780..b1ee2e9d 100644 --- a/test/functional/test_identifiers.py +++ b/test/functional/test_identifiers.py @@ -10,6 +10,7 @@ # 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. +"""Functional tests for ``dynamodb_encryption_sdk.identifiers``.""" import operator import pytest diff --git a/test/functional/test_structures.py b/test/functional/test_structures.py index e3428a40..3435b645 100644 --- a/test/functional/test_structures.py +++ b/test/functional/test_structures.py @@ -10,7 +10,7 @@ # 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. -"""""" +"""Functional tests for ``dynamodb_encryption_sdk.structures``.""" import pytest from dynamodb_encryption_sdk.exceptions import InvalidArgumentError diff --git a/test/integration/__init__.py b/test/integration/__init__.py index 1ccc7fa1..2add15ef 100644 --- a/test/integration/__init__.py +++ b/test/integration/__init__.py @@ -10,3 +10,4 @@ # 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. +"""Dummy stub to make linters work better.""" diff --git a/test/integration/integration_test_utils.py b/test/integration/integration_test_utils.py index f2673cd0..75f42554 100644 --- a/test/integration/integration_test_utils.py +++ b/test/integration/integration_test_utils.py @@ -10,26 +10,30 @@ # 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 integration tests.""" import os import sys + +import pytest + +from dynamodb_encryption_sdk.material_providers.aws_kms import AwsKmsCryptographicMaterialsProvider + sys.path.append(os.path.join( os.path.abspath(os.path.dirname(__file__)), '..', 'functional' )) -import pytest - -from dynamodb_encryption_sdk.material_providers.aws_kms import AwsKmsCryptographicMaterialsProvider - -import functional_test_utils, hypothesis_strategies +# Convenience imports +import functional_test_utils # noqa: E402,F401,I100 +import hypothesis_strategies # noqa: E402,F401,I100 AWS_KMS_KEY_ID = 'AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID' @pytest.fixture def cmk_arn(): - """Retrieves the target CMK ARN from environment variable.""" + """Retrieve the target CMK ARN from environment variable.""" arn = os.environ.get(AWS_KMS_KEY_ID, None) if arn is None: raise ValueError( diff --git a/test/integration/material_providers/__init__.py b/test/integration/material_providers/__init__.py index 1ccc7fa1..2add15ef 100644 --- a/test/integration/material_providers/__init__.py +++ b/test/integration/material_providers/__init__.py @@ -10,3 +10,4 @@ # 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. +"""Dummy stub to make linters work better.""" diff --git a/test/integration/material_providers/test_aws_kms.py b/test/integration/material_providers/test_aws_kms.py index 17258090..a268f5e9 100644 --- a/test/integration/material_providers/test_aws_kms.py +++ b/test/integration/material_providers/test_aws_kms.py @@ -10,12 +10,14 @@ # 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. +"""Integration tests for ``dynamodb_encryption_sdk.material_providers.aws_kms``.""" import hypothesis import pytest -from ..integration_test_utils import aws_kms_cmp, functional_test_utils, hypothesis_strategies from dynamodb_encryption_sdk.encrypted import CryptoConfig from dynamodb_encryption_sdk.structures import EncryptionContext +from ..integration_test_utils import aws_kms_cmp # noqa +from ..integration_test_utils import functional_test_utils, hypothesis_strategies pytestmark = pytest.mark.integ diff --git a/test/pylintrc b/test/pylintrc index bc06e8de..27d82a9c 100644 --- a/test/pylintrc +++ b/test/pylintrc @@ -8,7 +8,7 @@ # R0801 : duplicate-code (unit tests for similar things tend to be similar) # W0212 : protected-access (raised when calling _ methods) # W0621 : redefined-outer-name (raised when using pytest-mock) -# W0613 : unused-argument (raised when patches are needed but not called) +# W0613 : unused-argument (raised when patches and fixtures are needed but not called) disable = C0103, C0111, E1101, R0801, W0212, W0621, W0613 [DESIGN] diff --git a/test/unit/__init__.py b/test/unit/__init__.py index 1ccc7fa1..2add15ef 100644 --- a/test/unit/__init__.py +++ b/test/unit/__init__.py @@ -10,3 +10,4 @@ # 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. +"""Dummy stub to make linters work better.""" diff --git a/test/unit/material_providers/__init__.py b/test/unit/material_providers/__init__.py index 1ccc7fa1..2add15ef 100644 --- a/test/unit/material_providers/__init__.py +++ b/test/unit/material_providers/__init__.py @@ -10,3 +10,4 @@ # 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. +"""Dummy stub to make linters work better.""" diff --git a/test/unit/material_providers/test_aws_kms.py b/test/unit/material_providers/test_aws_kms.py index 701143ce..2a1c9668 100644 --- a/test/unit/material_providers/test_aws_kms.py +++ b/test/unit/material_providers/test_aws_kms.py @@ -10,6 +10,7 @@ # 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. +"""Unit tests for ``dynamodb_encryption_sdk.material_providers.aws_kms``.""" import boto3 import botocore.session from moto import mock_kms From 8c3bab03e97d4e3806b06d234ed3e08105c5ed99 Mon Sep 17 00:00:00 2001 From: mattsb42-aws Date: Thu, 29 Mar 2018 15:57:59 -0700 Subject: [PATCH 2/2] pylint-tests update and fixes --- test/acceptance/acceptance_test_utils.py | 6 ++++-- test/functional/encrypted/test_client.py | 2 +- test/functional/encrypted/test_resource.py | 2 +- test/functional/encrypted/test_table.py | 2 +- test/functional/functional_test_utils.py | 14 +++++++------- test/integration/integration_test_utils.py | 4 ++-- .../integration/material_providers/test_aws_kms.py | 2 +- tox.ini | 5 ++++- 8 files changed, 21 insertions(+), 16 deletions(-) diff --git a/test/acceptance/acceptance_test_utils.py b/test/acceptance/acceptance_test_utils.py index 7595bebe..80a9302e 100644 --- a/test/acceptance/acceptance_test_utils.py +++ b/test/acceptance/acceptance_test_utils.py @@ -18,7 +18,7 @@ import sys import pytest -from six.moves.urllib.parse import urlparse +from six.moves.urllib.parse import urlparse # moves confuse pylint: disable=wrong-import-order from dynamodb_encryption_sdk.delegated_keys.jce import JceNameLocalDelegatedKey from dynamodb_encryption_sdk.identifiers import EncryptionKeyTypes, KeyEncodingType @@ -34,7 +34,7 @@ )) # Convenience imports -import functional_test_vector_generators # noqa: E402,I100 +import functional_test_vector_generators # noqa: E402,I100 pylint: disable=import-error,wrong-import-position _ENCRYPTED_ITEM_VECTORS_DIR = os.path.join( os.path.abspath(os.path.dirname(__file__)), @@ -66,6 +66,7 @@ def _decode_item(item): def _build_plaintext_items(plaintext_file, version): + # pylint: disable=too-many-locals with open(plaintext_file) as f: plaintext_data = json.load(f) @@ -209,6 +210,7 @@ def _expand_items(ciphertext_items, plaintext_items): def load_scenarios(): + # pylint: disable=too-many-locals with open(_SCENARIO_FILE) as f: scenarios = json.load(f) keys_file = _filename_from_uri(scenarios['keys']) diff --git a/test/functional/encrypted/test_client.py b/test/functional/encrypted/test_client.py index 93e82ab2..e816da5d 100644 --- a/test/functional/encrypted/test_client.py +++ b/test/functional/encrypted/test_client.py @@ -21,7 +21,7 @@ check_encrypted_item, cycle_batch_item_check, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item, TEST_KEY, TEST_TABLE_NAME ) -from ..functional_test_utils import example_table # noqa +from ..functional_test_utils import example_table # noqa pylint: disable=unused-import from ..hypothesis_strategies import ddb_items, SLOW_SETTINGS, VERY_SLOW_SETTINGS pytestmark = [pytest.mark.functional, pytest.mark.local] diff --git a/test/functional/encrypted/test_resource.py b/test/functional/encrypted/test_resource.py index aa62b606..6c8188c1 100644 --- a/test/functional/encrypted/test_resource.py +++ b/test/functional/encrypted/test_resource.py @@ -18,7 +18,7 @@ from ..functional_test_utils import ( cycle_batch_item_check, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item, TEST_TABLE_NAME ) -from ..functional_test_utils import example_table # noqa +from ..functional_test_utils import example_table # noqa pylint: disable=unused-import pytestmark = [pytest.mark.functional, pytest.mark.local] diff --git a/test/functional/encrypted/test_table.py b/test/functional/encrypted/test_table.py index b9b73dd3..c0eda6e7 100644 --- a/test/functional/encrypted/test_table.py +++ b/test/functional/encrypted/test_table.py @@ -20,7 +20,7 @@ check_encrypted_item, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item, TEST_KEY, TEST_TABLE_NAME ) -from ..functional_test_utils import example_table # noqa +from ..functional_test_utils import example_table # noqa pylint: disable=unused-import from ..hypothesis_strategies import ddb_items, SLOW_SETTINGS, VERY_SLOW_SETTINGS pytestmark = [pytest.mark.functional, pytest.mark.local] diff --git a/test/functional/functional_test_utils.py b/test/functional/functional_test_utils.py index a7043f17..a1042f44 100644 --- a/test/functional/functional_test_utils.py +++ b/test/functional/functional_test_utils.py @@ -362,13 +362,13 @@ def check_encrypted_item(plaintext_item, ciphertext_item, attribute_actions): def _matching_key(actual_item, expected): - expected_item = [ - i for i in expected - if i['partition_attribute'] == actual_item['partition_attribute'] and - i['sort_attribute'] == actual_item['sort_attribute'] - ] - assert len(expected_item) == 1 - return expected_item[0] + expected_item = [ + i for i in expected + if i['partition_attribute'] == actual_item['partition_attribute'] and + i['sort_attribute'] == actual_item['sort_attribute'] + ] + assert len(expected_item) == 1 + return expected_item[0] def _nop_transformer(item): diff --git a/test/integration/integration_test_utils.py b/test/integration/integration_test_utils.py index 75f42554..39c0206d 100644 --- a/test/integration/integration_test_utils.py +++ b/test/integration/integration_test_utils.py @@ -25,8 +25,8 @@ )) # Convenience imports -import functional_test_utils # noqa: E402,F401,I100 -import hypothesis_strategies # noqa: E402,F401,I100 +import functional_test_utils # noqa: E402,F401,I100 pylint: disable=import-error,unused-import,wrong-import-position +import hypothesis_strategies # noqa: E402,F401,I100 pylint: disable=import-error,unused-import,wrong-import-position AWS_KMS_KEY_ID = 'AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID' diff --git a/test/integration/material_providers/test_aws_kms.py b/test/integration/material_providers/test_aws_kms.py index a268f5e9..3f239ede 100644 --- a/test/integration/material_providers/test_aws_kms.py +++ b/test/integration/material_providers/test_aws_kms.py @@ -16,7 +16,7 @@ from dynamodb_encryption_sdk.encrypted import CryptoConfig from dynamodb_encryption_sdk.structures import EncryptionContext -from ..integration_test_utils import aws_kms_cmp # noqa +from ..integration_test_utils import aws_kms_cmp # noqa pylint: disable=unused-import from ..integration_test_utils import functional_test_utils, hypothesis_strategies pytestmark = pytest.mark.integ diff --git a/tox.ini b/tox.ini index 8b4db3f0..2ea787d0 100644 --- a/tox.ini +++ b/tox.ini @@ -134,7 +134,10 @@ deps = {[testenv:pylint]deps} commands = pylint \ --rcfile=test/pylintrc \ - test/unit/ + test/unit/ \ + test/acceptance/ \ + test/functional/ \ + test/integration/ [testenv:doc8] basepython = python3