Skip to content

Commit 82e2156

Browse files
authored
chore: clean up and fix test vector handler static analysis checks (#263)
* chore: fix pylint-test configuration * chore: clean up linting issues in test vector handler
1 parent 351f71d commit 82e2156

File tree

16 files changed

+42
-27
lines changed

16 files changed

+42
-27
lines changed

test_vector_handlers/src/awses_test_vectors/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13+
"""Static test vector handling logic for the AWS Encyrption SDK."""
1314
__version__ = "1.0.0"

test_vector_handlers/src/awses_test_vectors/commands/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13+
"""CLI commands."""

test_vector_handlers/src/awses_test_vectors/commands/full_message_decrypt.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
"""
14-
AWS Encryption SDK full message decrypt command.
15-
"""
13+
"""AWS Encryption SDK full message decrypt command."""
1614
import argparse
1715

1816
from awses_test_vectors.manifests.full_message.decrypt import MessageDecryptionManifest

test_vector_handlers/src/awses_test_vectors/commands/full_message_encrypt.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
"""
14-
AWS Encryption SDK full message encrypt command.
15-
"""
13+
"""AWS Encryption SDK full message encrypt command."""
1614
import argparse
1715

1816
from awses_test_vectors.manifests.full_message.encrypt import MessageEncryptionManifest

test_vector_handlers/src/awses_test_vectors/internal/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13+
"""Internal implementation details.
14+
15+
.. warning::
16+
No guarantee is provided on the modules and APIs within this
17+
namespace staying consistent. Directly reference at your own risk.
18+
"""

test_vector_handlers/src/awses_test_vectors/internal/aws_kms.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
"""
14-
Helper utilities for interacting with AWS KMS.
15-
"""
13+
"""Helper utilities for interacting with AWS KMS."""
1614
try:
1715
from aws_encryption_sdk.identifiers import AlgorithmSuite
1816
except ImportError:

test_vector_handlers/src/awses_test_vectors/internal/defaults.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
"""
14-
Default values for use in AWS Encryption SDK test vector handlers.
15-
"""
13+
"""Default values for use in AWS Encryption SDK test vector handlers."""
1614

1715
ENCODING = "utf-8"

test_vector_handlers/src/awses_test_vectors/internal/mypy_types.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
"""
14-
MyPy types for use in AWS Encryption SDK test vector handlers.
15-
"""
13+
"""MyPy types for use in AWS Encryption SDK test vector handlers."""
1614
# mypy types confuse pylint: disable=invalid-name
1715

1816
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules

test_vector_handlers/src/awses_test_vectors/internal/util.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
"""
14-
Utility functions for use in AWS Encryption SDK test vector handlers.
15-
"""
13+
"""Utility functions for use in AWS Encryption SDK test vector handlers."""
1614
import os
1715
import struct
1816
from binascii import unhexlify
@@ -100,7 +98,7 @@ def membership_validator(allowed):
10098
def _validate_membership(instance, attribute, value):
10199
# type: (object, Attribute, Any) -> None
102100
# pylint: disable=unused-argument
103-
""""""
101+
"""Perform membership check."""
104102
if value not in allowed:
105103
raise ValueError(
106104
'Unknown "{name}" value "{actual}" not in {expected}'.format(
@@ -178,9 +176,9 @@ def algorithm_suite_from_string_id(string_id):
178176
return AlgorithmSuite.get_by_id(numeric_id)
179177

180178

181-
# TODO: I want to replace these functions with an extensible "URI Handler" class
182-
# that will abstract away any file handling. This will vastly simply extending
183-
# these handlers to work with files in some non-local location, such as S3.
179+
# I want to replace these functions with an extensible "URI Handler" class
180+
# that will abstract away any file handling. This will vastly simply extending
181+
# these handlers to work with files in some non-local location, such as S3.
184182
def file_writer(parent_dir):
185183
# type: (str) -> Callable[[str, bytes], str]
186184
"""Return a caller that will write the requested named data to a file and return
@@ -214,7 +212,7 @@ def _write_file(name, data):
214212

215213
def file_reader(parent_dir):
216214
# type: (str) -> Callable[[str], bytes]
217-
"""Returns a callable that accepts a URI identifying a file relative to ``parent_dir``
215+
"""Return a callable that accepts a URI identifying a file relative to ``parent_dir``
218216
and returns the binary contents of that file.
219217
220218
:param str parent_dir: Parent directory to use as the relative root for all URIs

test_vector_handlers/src/awses_test_vectors/manifests/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13+
"""Test vector manifest handlers."""

test_vector_handlers/src/awses_test_vectors/manifests/full_message/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13+
"""Full-message test vector manifest handlers."""

test_vector_handlers/src/awses_test_vectors/manifests/full_message/decrypt.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252
@attr.s(init=False)
5353
class MessageDecryptionTestScenario(object):
54+
# pylint: disable=too-many-arguments
5455
"""Data class for a single full message decrypt test scenario.
5556
5657
Handles serialization and deserialization to and from manifest specs.
@@ -156,12 +157,12 @@ def run(self, name):
156157
"""
157158
plaintext, _header = aws_encryption_sdk.decrypt(source=self.ciphertext, key_provider=self.master_key_provider)
158159
if plaintext != self.plaintext:
159-
# TODO: Actually do something here
160-
raise Exception("TODO: ERROR MESSAGE")
160+
raise ValueError("Decrypted plaintext does not match expected value.")
161161

162162

163163
@attr.s(init=False)
164164
class MessageDecryptionManifest(object):
165+
# pylint: disable=too-many-arguments
165166
"""AWS Encryption SDK Decrypt Message manifest handler.
166167
167168
Described in AWS Crypto Tools Test Vector Framework feature #0003 AWS Encryption SDK Decrypt Message.

test_vector_handlers/src/awses_test_vectors/manifests/keys.py

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def manifest_spec(self):
108108

109109
@attr.s(init=False)
110110
class ManualKeySpec(KeySpec):
111+
# pylint: disable=too-many-arguments
111112
"""Manual key specification.
112113
113114
Allowed values described in AWS Crypto Tools Test Vector Framework feature #0002 Keys Manifest.

test_vector_handlers/src/pylintrc

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ disable =
44
bad-continuation, # we let black handle this
55
ungrouped-imports, # we let isort handle this
66
useless-object-inheritance, # we need to support Python 2, so no, not useless
7+
duplicate-code, # the manifest handlers have a lot of similar code
78

89
[FORMAT]
910
max-line-length = 120

test_vector_handlers/test/pylintrc

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[MESSAGES CONTROL]
2+
# Disabling messages that we either don't care about for tests or are necessary to break for tests.
3+
disable =
4+
invalid-name, # we prefer long, descriptive, names for tests
5+
missing-docstring, # we don't write docstrings for tests
6+
bad-continuation, # we let black handle this
7+
ungrouped-imports, # we let isort handle this
8+
useless-object-inheritance, # we need to support Python 2, so no, not useless
9+
duplicate-code, # unit tests for similar things tend to be similar
10+
redefined-outer-name, # raised when using decorators
11+
12+
[FORMAT]
13+
max-line-length = 120
14+
15+
[REPORTS]
16+
msg-template = {path}:{line}: [{msg_id}({symbol}), {obj}] {msg}

test_vector_handlers/tox.ini

-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ deps = {[testenv:pylint]deps}
145145
commands =
146146
pylint \
147147
--rcfile=test/pylintrc \
148-
test/unit/ \
149-
test/functional/ \
150148
test/integration/ \
151149
{posargs}
152150

0 commit comments

Comments
 (0)