Skip to content

Commit

Permalink
Re-format tests/hazmat/primitives/ (#9770)
Browse files Browse the repository at this point in the history
this matches both ruff and black style
  • Loading branch information
alex authored Oct 25, 2023
1 parent 7a066bf commit c687e5c
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 22 deletions.
4 changes: 3 additions & 1 deletion tests/hazmat/primitives/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def test_instantiate_with_non_algorithm(self, backend):
algorithm = object()
with pytest.raises(TypeError):
Cipher(
algorithm, mode=None, backend=backend # type: ignore[arg-type]
algorithm, # type: ignore[arg-type]
mode=None,
backend=backend,
)


Expand Down
8 changes: 6 additions & 2 deletions tests/hazmat/primitives/test_ciphers.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ def test_update_into_auto_chunking(self, backend, monkeypatch):
encryptor = c.encryptor()
# Lower max chunk size so we can test chunking
monkeypatch.setattr(
encryptor._ctx, "_MAX_CHUNK_SIZE", 40 # type: ignore[attr-defined]
encryptor._ctx, # type: ignore[attr-defined]
"_MAX_CHUNK_SIZE",
40,
)
buf = bytearray(527)
pt = b"abcdefghijklmnopqrstuvwxyz012345" * 16 # 512 bytes
Expand All @@ -355,7 +357,9 @@ def test_update_into_auto_chunking(self, backend, monkeypatch):
decryptor = c.decryptor()
# Change max chunk size to verify alternate boundaries don't matter
monkeypatch.setattr(
decryptor._ctx, "_MAX_CHUNK_SIZE", 73 # type: ignore[attr-defined]
decryptor._ctx, # type: ignore[attr-defined]
"_MAX_CHUNK_SIZE",
73,
)
decbuf = bytearray(527)
decprocessed = decryptor.update_into(buf[:processed], decbuf)
Expand Down
6 changes: 4 additions & 2 deletions tests/hazmat/primitives/test_dsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,8 @@ def test_dsa_public_numbers(self):
def test_dsa_public_numbers_invalid_types(self):
with pytest.raises(TypeError):
dsa.DSAPublicNumbers(
y=4, parameter_numbers=None # type: ignore[arg-type]
y=4,
parameter_numbers=None, # type: ignore[arg-type]
)

with pytest.raises(TypeError):
Expand Down Expand Up @@ -606,7 +607,8 @@ def test_dsa_private_numbers_invalid_types(self):

with pytest.raises(TypeError):
dsa.DSAPrivateNumbers(
x=None, public_numbers=public_numbers # type: ignore[arg-type]
x=None, # type: ignore[arg-type]
public_numbers=public_numbers,
)

def test_repr(self):
Expand Down
3 changes: 2 additions & 1 deletion tests/hazmat/primitives/test_ec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,8 @@ def test_from_encoded_point_empty_byte_string(self):
def test_from_encoded_point_not_a_curve(self):
with pytest.raises(TypeError):
ec.EllipticCurvePublicKey.from_encoded_point(
"notacurve", b"\x04data" # type: ignore[arg-type]
"notacurve", # type: ignore[arg-type]
b"\x04data",
)

def test_from_encoded_point_unsupported_encoding(self):
Expand Down
4 changes: 3 additions & 1 deletion tests/hazmat/primitives/test_hmac.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def test_hmac_reject_unicode(self, backend):
def test_hmac_algorithm_instance(self, backend):
with pytest.raises(TypeError):
hmac.HMAC(
b"key", hashes.SHA1, backend=backend # type: ignore[arg-type]
b"key",
hashes.SHA1, # type: ignore[arg-type]
backend=backend,
)

def test_raises_after_finalize(self, backend):
Expand Down
16 changes: 12 additions & 4 deletions tests/hazmat/primitives/test_pkcs12.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ def test_load_pkcs12_key_only(self, backend):
def test_non_bytes(self, backend):
with pytest.raises(TypeError):
load_key_and_certificates(
b"irrelevant", object(), backend # type: ignore[arg-type]
b"irrelevant",
object(), # type: ignore[arg-type]
backend,
)

def test_not_a_pkcs12(self, backend):
Expand Down Expand Up @@ -804,15 +806,21 @@ def test_certificate_repr(self, backend):
def test_key_and_certificates_constructor(self, backend):
with pytest.raises(TypeError):
PKCS12KeyAndCertificates(
"hello", None, [] # type:ignore[arg-type]
"hello", # type:ignore[arg-type]
None,
[],
)
with pytest.raises(TypeError):
PKCS12KeyAndCertificates(
None, "hello", [] # type:ignore[arg-type]
None,
"hello", # type:ignore[arg-type]
[],
)
with pytest.raises(TypeError):
PKCS12KeyAndCertificates(
None, None, ["hello"] # type:ignore[list-item]
None,
None,
["hello"], # type:ignore[list-item]
)

def test_key_and_certificates_equality(self, backend):
Expand Down
15 changes: 11 additions & 4 deletions tests/hazmat/primitives/test_pkcs7.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,18 @@ def test_unsupported_hash_alg(self, backend):
cert, key = _load_cert_key()
with pytest.raises(TypeError):
pkcs7.PKCS7SignatureBuilder().add_signer(
cert, key, hashes.SHA512_256() # type: ignore[arg-type]
cert,
key,
hashes.SHA512_256(), # type: ignore[arg-type]
)

def test_not_a_cert(self, backend):
cert, key = _load_cert_key()
with pytest.raises(TypeError):
pkcs7.PKCS7SignatureBuilder().add_signer(
b"notacert", key, hashes.SHA256() # type: ignore[arg-type]
b"notacert", # type: ignore[arg-type]
key,
hashes.SHA256(),
)

@pytest.mark.supported(
Expand All @@ -213,7 +217,9 @@ def test_unsupported_key_type(self, backend):
key = ed25519.Ed25519PrivateKey.generate()
with pytest.raises(TypeError):
pkcs7.PKCS7SignatureBuilder().add_signer(
cert, key, hashes.SHA256() # type: ignore[arg-type]
cert,
key, # type: ignore[arg-type]
hashes.SHA256(),
)

def test_sign_invalid_options(self, backend):
Expand Down Expand Up @@ -816,5 +822,6 @@ def test_invalid_types(self):

with pytest.raises(TypeError):
pkcs7.serialize_certificates(
certs, "not an encoding" # type: ignore[arg-type]
certs,
"not an encoding", # type: ignore[arg-type]
)
10 changes: 7 additions & 3 deletions tests/hazmat/primitives/test_rsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,8 @@ class TestPSS:
def test_calculate_max_pss_salt_length(self):
with pytest.raises(TypeError):
padding.calculate_max_pss_salt_length(
object(), hashes.SHA256() # type:ignore[arg-type]
object(), # type:ignore[arg-type]
hashes.SHA256(),
)

def test_invalid_salt_length_not_integer(self):
Expand Down Expand Up @@ -1711,7 +1712,9 @@ def test_invalid_algorithm(self):
mgf = padding.MGF1(hashes.SHA1())
with pytest.raises(TypeError):
padding.OAEP(
mgf=mgf, algorithm=b"", label=None # type:ignore[arg-type]
mgf=mgf,
algorithm=b"", # type:ignore[arg-type]
label=None,
)

def test_algorithm_property(self):
Expand Down Expand Up @@ -2180,7 +2183,8 @@ def test_unsupported_padding(
public_key.encrypt(b"somedata", DummyAsymmetricPadding())
with pytest.raises(TypeError):
public_key.encrypt(
b"somedata", padding=object() # type: ignore[arg-type]
b"somedata",
padding=object(), # type: ignore[arg-type]
)

def test_unsupported_oaep_mgf(
Expand Down
9 changes: 6 additions & 3 deletions tests/hazmat/primitives/test_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1501,11 +1501,13 @@ def test_add_critical_option_errors(self):
builder = SSHCertificateBuilder()
with pytest.raises(TypeError):
builder.add_critical_option(
"not bytes", b"test" # type: ignore[arg-type]
"not bytes", # type: ignore[arg-type]
b"test",
)
with pytest.raises(TypeError):
builder.add_critical_option(
b"test", object() # type: ignore[arg-type]
b"test",
object(), # type: ignore[arg-type]
)
builder = builder.add_critical_option(b"test", b"test")
with pytest.raises(ValueError):
Expand All @@ -1515,7 +1517,8 @@ def test_add_extension_errors(self):
builder = SSHCertificateBuilder()
with pytest.raises(TypeError):
builder.add_extension(
"not bytes", b"test" # type: ignore[arg-type]
"not bytes", # type: ignore[arg-type]
b"test",
)
with pytest.raises(TypeError):
builder.add_extension(b"test", object()) # type: ignore[arg-type]
Expand Down
3 changes: 2 additions & 1 deletion tests/hazmat/primitives/test_x25519.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def test_public_bytes_bad_args(self, backend):
key = X25519PrivateKey.generate().public_key()
with pytest.raises(TypeError):
key.public_bytes(
None, serialization.PublicFormat.Raw # type: ignore[arg-type]
None, # type: ignore[arg-type]
serialization.PublicFormat.Raw,
)
with pytest.raises(ValueError):
key.public_bytes(
Expand Down

0 comments on commit c687e5c

Please sign in to comment.