Skip to content

Commit

Permalink
chore: Fix pylint checks (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
farleyb-amazon committed Aug 25, 2021
1 parent 55309f3 commit 74af899
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 29 deletions.
4 changes: 3 additions & 1 deletion codebuild/py38/awses_local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ phases:
python: latest
build:
commands:
- pip install tox
- pyenv install 3.8.6
- pyenv local 3.8.6
- pip install tox tox-pyenv
- cd test_vector_handlers
- tox
4 changes: 3 additions & 1 deletion codebuild/py38/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ phases:
python: latest
build:
commands:
- pip install tox
- pyenv install 3.8.6
- pyenv local 3.8.6
- pip install tox tox-pyenv
- tox
4 changes: 3 additions & 1 deletion codebuild/py38/integ.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ phases:
python: latest
build:
commands:
- pip install tox
- pyenv install 3.8.6
- pyenv local 3.8.6
- pip install tox tox-pyenv
- tox
2 changes: 1 addition & 1 deletion decrypt_oracle/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def read(*args):
"""Read complete file contents."""
return open(os.path.join(HERE, *args)).read() # pylint: disable=consider-using-with
return open(os.path.join(HERE, *args), encoding="utf-8").read() # pylint: disable=consider-using-with


def get_version():
Expand Down
2 changes: 1 addition & 1 deletion decrypt_oracle/test/integration/integration_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_vectors_filename() -> Text:
def all_test_vectors() -> Iterable[Any]:
"""Collect and iterate through all test vectors."""

with open(test_vectors_filename(), "r") as vectors_file:
with open(test_vectors_filename(), "r", encoding="utf-8") as vectors_file:
raw_vectors = json.load(vectors_file)

for vector in raw_vectors:
Expand Down
2 changes: 1 addition & 1 deletion examples/src/one_kms_cmk_streaming_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def encrypt_decrypt_stream(key_arn, source_plaintext_filename, botocore_session=
:param botocore_session: existing botocore session instance
:type botocore_session: botocore.session.Session
"""
kwargs = dict()
kwargs = {}

kwargs["key_ids"] = [key_arn]

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def read(*args):
"""Reads complete file contents."""
return open(os.path.join(HERE, *args)).read() # pylint: disable=consider-using-with
return open(os.path.join(HERE, *args), encoding="utf-8").read() # pylint: disable=consider-using-with


def get_version():
Expand Down
2 changes: 1 addition & 1 deletion src/aws_encryption_sdk/internal/formatting/deserialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def deserialize_header(stream, max_encrypted_data_keys=None):
tee_stream = TeeStream(stream, tee)
(version_id,) = unpack_values(">B", tee_stream)
version = _verified_version_from_id(version_id)
header = dict()
header = {}
header["version"] = version

if version == SerializationVersion.V1:
Expand Down
2 changes: 1 addition & 1 deletion test/functional/test_f_xcompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def _generate_test_cases(): # noqa=C901
# Make no test cases if the ciphertext file is not found
return []

with open(ciphertext_manifest_path) as f:
with open(ciphertext_manifest_path, encoding="utf-8") as f:
ciphertext_manifest = json.load(f)
_test_cases = []

Expand Down
6 changes: 3 additions & 3 deletions test/integration/test_i_xcompat_kms.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _generate_test_cases():
# Make no test cases if the ciphertext file is not found
return []

with open(ciphertext_manifest_path) as f:
with open(ciphertext_manifest_path, encoding="utf-8") as f:
ciphertext_manifest = json.load(f)
_test_cases = []

Expand All @@ -69,9 +69,9 @@ def _generate_test_cases():
@pytest.mark.parametrize("plaintext_filename, ciphertext_filename", _generate_test_cases())
def test_decrypt_from_file(plaintext_filename, ciphertext_filename):
"""Tests decrypt from known good files."""
with open(ciphertext_filename, "rb") as infile:
with open(ciphertext_filename, "rb", encoding="utf-8") as infile:
ciphertext = infile.read()
with open(plaintext_filename, "rb") as infile:
with open(plaintext_filename, "rb", encoding="utf-8") as infile:
plaintext = infile.read()
decrypted_ciphertext, _header = aws_encryption_sdk.decrypt(
source=ciphertext, key_provider=setup_kms_master_key_provider()
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_kat_commitment.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _file_root():
base_dir = os.path.join(root_dir, "test", "resources")
file_path = os.path.join(base_dir, FILE_NAME)

test_str = open(file_path, "r").read() # pylint: disable=consider-using-with
test_str = open(file_path, "r", encoding="utf-8").read() # pylint: disable=consider-using-with
test_json = json.loads(test_str)
kat_tests = test_json["tests"]

Expand Down
10 changes: 5 additions & 5 deletions test/unit/test_encryption_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_client_encrypt(mocker):
commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT, max_encrypted_data_keys=3
)

kwargs = dict()
kwargs = {}
kwargs["source"] = b"plaintext"
kwargs["materials_manager"] = cmm
client.encrypt(**kwargs)
Expand All @@ -77,7 +77,7 @@ def test_client_decrypt(mocker):
commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT, max_encrypted_data_keys=3
)

kwargs = dict()
kwargs = {}
kwargs["source"] = b"ciphertext"
kwargs["materials_manager"] = cmm
client.decrypt(**kwargs)
Expand All @@ -94,7 +94,7 @@ def test_client_stream_encrypt(mocker, mode_string):
cmm = MagicMock(__class__=CryptoMaterialsManager)
client = aws_encryption_sdk.EncryptionSDKClient(commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT)

kwargs = dict()
kwargs = {}
kwargs["mode"] = mode_string
kwargs["source"] = b"plaintext"
kwargs["materials_manager"] = cmm
Expand All @@ -113,7 +113,7 @@ def test_client_stream_decrypt(mocker, mode_string):
cmm = MagicMock(__class__=CryptoMaterialsManager)
client = aws_encryption_sdk.EncryptionSDKClient(commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT)

kwargs = dict()
kwargs = {}
kwargs["mode"] = mode_string
kwargs["source"] = b"ciphertext"
kwargs["materials_manager"] = cmm
Expand All @@ -132,7 +132,7 @@ def test_client_bad_kwargs(mocker, method, key):
mocker.patch.object(aws_encryption_sdk, "StreamEncryptor")

cmm = MagicMock(__class__=CryptoMaterialsManager)
kwargs = dict()
kwargs = {}
kwargs[key] = "foobar"
kwargs["source"] = b"ciphertext"
kwargs["materials_manager"] = cmm
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_material_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
(EncryptionMaterials, dict(data_encryption_key=None)),
(EncryptionMaterials, dict(encrypted_data_keys=None)),
(EncryptionMaterials, dict(encryption_context=None)),
(EncryptionMaterials, dict(signing_key=u"not bytes or None")),
(EncryptionMaterials, dict(signing_key="not bytes or None")),
(DecryptionMaterialsRequest, dict(algorithm=None)),
(DecryptionMaterialsRequest, dict(encrypted_data_keys=None)),
(DecryptionMaterialsRequest, dict(encryption_context=None)),
Expand Down
16 changes: 8 additions & 8 deletions test/unit/test_util_str_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ def test_to_bytes_bytes2bytes(self):
assert test == b"\x3a\x00\x99"

def test_to_str_bytes2unicode(self):
test = aws_encryption_sdk.internal.str_ops.to_str(codecs.encode(u"Предисловие", "utf-8"))
assert test == u"Предисловие"
test = aws_encryption_sdk.internal.str_ops.to_str(codecs.encode("Предисловие", "utf-8"))
assert test == "Предисловие"

def test_to_str_unicode2unicode(self):
test = aws_encryption_sdk.internal.str_ops.to_str(u"Предисловие")
assert test == u"Предисловие"
test = aws_encryption_sdk.internal.str_ops.to_str("Предисловие")
assert test == "Предисловие"

def test_to_str_unicode2bytes(self):
test = aws_encryption_sdk.internal.str_ops.to_bytes(u"Предисловие")
assert test == codecs.encode(u"Предисловие", "utf-8")
test = aws_encryption_sdk.internal.str_ops.to_bytes("Предисловие")
assert test == codecs.encode("Предисловие", "utf-8")

def test_to_bytes_utf82utf8(self):
test = aws_encryption_sdk.internal.str_ops.to_bytes(codecs.encode(u"Предисловие", "utf-8"))
assert test == codecs.encode(u"Предисловие", "utf-8")
test = aws_encryption_sdk.internal.str_ops.to_bytes(codecs.encode("Предисловие", "utf-8"))
assert test == codecs.encode("Предисловие", "utf-8")
2 changes: 1 addition & 1 deletion test/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_prep_stream_data_passthrough():
assert_prepped_stream_identity(test, io.BytesIO)


@pytest.mark.parametrize("source", (u"some unicode data ловие", b"\x00\x01\x02"))
@pytest.mark.parametrize("source", ("some unicode data ловие", b"\x00\x01\x02"))
def test_prep_stream_data_wrap(source):
test = aws_encryption_sdk.internal.utils.prep_stream_data(source)

Expand Down
2 changes: 1 addition & 1 deletion test_vector_handlers/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def read(*args):
"""Read complete file contents."""
return open(os.path.join(HERE, *args)).read() # pylint: disable=consider-using-with
return open(os.path.join(HERE, *args), encoding="utf-8").read() # pylint: disable=consider-using-with


def get_version():
Expand Down

0 comments on commit 74af899

Please sign in to comment.