Skip to content

Commit d8f5826

Browse files
chore: format key unit tests using black (#1562)
Signed-off-by: E.D.I.T.H <[email protected]>
1 parent c0d8015 commit d8f5826

File tree

4 files changed

+64
-44
lines changed

4 files changed

+64
-44
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
66

77
## [Unreleased]
88

9+
10+
911
### Tests
1012
- Format `tests/unit/hedera_trust_manager_test.py` with Black for consistent code style (#1539)
1113
- Format tests/unit/logger_test.py with black for code style consistency (#1541)
@@ -207,6 +209,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
207209
- Refactored `examples/account/account_create_transaction_create_with_alias.py` and `examples/account/account_create_transaction_evm_alias.py` to use the native `AccountInfo.__str__` method for printing account details, replacing manual JSON serialization. ([#1263](https://github.com/hiero-ledger/hiero-sdk-python/issues/1263))
208210
- Enhance TopicInfo `__str__` method and tests with additional coverage, and update the format_key function in `key_format.py` to handle objects with a \_to_proto method.
209211
- Update changelog workflow to trigger automatically on pull requests instead of manual dispatch (#1567)
212+
- Formatted key-related unit test files (`key_utils_test.py`, `test_key_format.py`, `test_key_list.py`) using the black formatter
210213

211214
### Fixed
212215
- Reduced notification spam by skipping the entire advanced qualification job for non-advanced issues and irrelevant events (#1517)

tests/unit/key_utils_test.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ def test_key_to_proto_with_ed25519_public_key():
1414
"""Tests key_to_proto with an Ed25519 PublicKey."""
1515
private_key = PrivateKey.generate_ed25519()
1616
public_key = private_key.public_key()
17-
17+
1818
expected_proto = public_key._to_proto()
1919
result_proto = key_to_proto(public_key)
20-
20+
2121
assert result_proto == expected_proto
2222
assert isinstance(result_proto, basic_types_pb2.Key)
2323

@@ -26,10 +26,10 @@ def test_key_to_proto_with_ecdsa_public_key():
2626
"""Tests key_to_proto with an ECDSA PublicKey."""
2727
private_key = PrivateKey.generate_ecdsa()
2828
public_key = private_key.public_key()
29-
29+
3030
expected_proto = public_key._to_proto()
3131
result_proto = key_to_proto(public_key)
32-
32+
3333
assert result_proto == expected_proto
3434
assert isinstance(result_proto, basic_types_pb2.Key)
3535

@@ -38,13 +38,13 @@ def test_key_to_proto_with_ed25519_private_key():
3838
"""Tests key_to_proto with an Ed25519 PrivateKey (extracts public key)."""
3939
private_key = PrivateKey.generate_ed25519()
4040
public_key = private_key.public_key()
41-
41+
4242
# We expect the *public key's* proto, even though we passed a private key
4343
expected_proto = public_key._to_proto()
44-
44+
4545
# Call the function with the PrivateKey
4646
result_proto = key_to_proto(private_key)
47-
47+
4848
# Assert it correctly converted it to the public key proto
4949
assert result_proto == expected_proto
5050
assert isinstance(result_proto, basic_types_pb2.Key)
@@ -54,10 +54,10 @@ def test_key_to_proto_with_ecdsa_private_key():
5454
"""Tests key_to_proto with an ECDSA PrivateKey (extracts public key)."""
5555
private_key = PrivateKey.generate_ecdsa()
5656
public_key = private_key.public_key()
57-
57+
5858
expected_proto = public_key._to_proto()
5959
result_proto = key_to_proto(private_key)
60-
60+
6161
assert result_proto == expected_proto
6262
assert isinstance(result_proto, basic_types_pb2.Key)
6363

@@ -72,20 +72,19 @@ def test_key_to_proto_with_invalid_string_raises_error():
7272
"""Tests key_to_proto raises TypeError with invalid input."""
7373
with pytest.raises(TypeError) as e:
7474
key_to_proto("this is not a key")
75-
75+
7676
assert "Key must be of type PrivateKey or PublicKey" in str(e.value)
7777

7878

7979
def test_key_type_alias():
8080
"""Tests that the Key type alias works correctly."""
8181
private_key = PrivateKey.generate_ed25519()
8282
public_key = private_key.public_key()
83-
83+
8484
# Test that both PrivateKey and PublicKey can be assigned to Key type
8585
key1: Key = private_key
8686
key2: Key = public_key
87-
87+
8888
# Both should work with key_to_proto
8989
assert key_to_proto(key1) is not None
9090
assert key_to_proto(key2) is not None
91-

tests/unit/keys_private_test.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
pytestmark = pytest.mark.unit
1212

13+
1314
def test_generate_ed25519():
1415
"""
1516
Test generating an Ed25519 key, then:
@@ -136,7 +137,7 @@ def test_from_string_der_ed25519():
136137
"""
137138
Test from_string_der with a known valid DER encoding for Ed25519.
138139
Then confirm sign/verify works.
139-
140+
140141
This example DER was built using a known Ed25519 seed (all '01').
141142
"""
142143
der_hex = (
@@ -319,11 +320,7 @@ def test_from_bytes_ambiguity_prefers_ecdsa_when_ed25519_fails(monkeypatch):
319320
ecdsa_scalar_one = (1).to_bytes(32, "big")
320321

321322
# 2) Force the Ed25519 loader to always return None
322-
monkeypatch.setattr(
323-
PrivateKey,
324-
"_try_load_ed25519",
325-
staticmethod(lambda b: None)
326-
)
323+
monkeypatch.setattr(PrivateKey, "_try_load_ed25519", staticmethod(lambda b: None))
327324

328325
# 3) Now from_bytes should skip Ed25519 and succeed with ECDSA
329326
with warnings.catch_warnings(record=True) as w:
@@ -387,12 +384,15 @@ def test_from_string_ecdsa_strips_0x():
387384
assert priv.is_ecdsa()
388385

389386

390-
@pytest.mark.parametrize("fn, length", [
391-
(PrivateKey.from_bytes_ed25519, 31),
392-
(PrivateKey.from_bytes_ed25519, 33),
393-
(PrivateKey.from_bytes_ecdsa, 31),
394-
(PrivateKey.from_bytes_ecdsa, 33),
395-
])
387+
@pytest.mark.parametrize(
388+
"fn, length",
389+
[
390+
(PrivateKey.from_bytes_ed25519, 31),
391+
(PrivateKey.from_bytes_ed25519, 33),
392+
(PrivateKey.from_bytes_ecdsa, 31),
393+
(PrivateKey.from_bytes_ecdsa, 33),
394+
],
395+
)
396396
def test_from_bytes_wrong_length(fn, length):
397397
bad = b"\x00" * length
398398
with pytest.raises(ValueError):
@@ -434,7 +434,7 @@ def test_repr_contains_full_hex(key_type):
434434
def test_der_roundtrip(key_type):
435435
"""
436436
Make sure that if we serialize a key to DER and then load it back,
437-
we get the same raw seed/scalar.
437+
we get the same raw seed/scalar.
438438
"""
439439
priv1 = PrivateKey.generate(key_type)
440440
der_hex = priv1.to_string_der()

0 commit comments

Comments
 (0)