Skip to content

Commit 21fcbcf

Browse files
authored
style: format tests/unit/custom_fee_test.py (hiero-ledger#1703)
Signed-off-by: Dominiq Barbero <mr.dom.barbero@gmail.com>
1 parent 29de6d9 commit 21fcbcf

File tree

2 files changed

+56
-33
lines changed

2 files changed

+56
-33
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
2828
- Formatted `ethereum_transaction_test.py` using Black.
2929
- Formatted client_test.py using Black.
3030
- Format tests/unit/query*.py using black (#1547)
31+
- Format `tests/unit/custom_fee_test.py` with black for code style consistency. (#1525)
3132

3233
### Added
3334
- Add `__repr__()` method to `TopicId` class for improved debugging with constructor-style representation (#1629)

tests/unit/custom_fee_test.py

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from hiero_sdk_python.account.account_id import AccountId
1111
from hiero_sdk_python.tokens.token_id import TokenId
1212

13-
1413
pytestmark = pytest.mark.unit
1514

15+
1616
def test_custom_fixed_fee_proto_round_trip():
1717
"""Ensure CustomFixedFee protobuf serialization and deserialization behave correctly."""
1818
fee = CustomFixedFee(
@@ -31,6 +31,7 @@ def test_custom_fixed_fee_proto_round_trip():
3131
assert new_fee.fee_collector_account_id == AccountId(0, 0, 456)
3232
assert new_fee.all_collectors_are_exempt is True
3333

34+
3435
def test_custom_fixed_fee_str():
3536
"""Test the string representation of CustomFixedFee."""
3637
fee = CustomFixedFee(
@@ -108,6 +109,7 @@ def test_custom_fractional_fee_str():
108109
assert "0.0.789" in kv["Fee Collector Account Id"]
109110
assert kv["All Collectors Are Exempt"] in ("False", "false")
110111

112+
111113
def test_custom_fractional_fee():
112114
fee = CustomFractionalFee(
113115
numerator=1,
@@ -120,7 +122,9 @@ def test_custom_fractional_fee():
120122
)
121123

122124
proto = fee._to_proto() # Changed from _to_protobuf
123-
new_fee = CustomFractionalFee._from_proto(proto) # Changed from CustomFee._from_protobuf
125+
new_fee = CustomFractionalFee._from_proto(
126+
proto
127+
) # Changed from CustomFee._from_protobuf
124128

125129
assert isinstance(new_fee, CustomFractionalFee)
126130
assert new_fee.numerator == 1
@@ -131,6 +135,7 @@ def test_custom_fractional_fee():
131135
assert new_fee.fee_collector_account_id == AccountId(0, 0, 456)
132136
assert new_fee.all_collectors_are_exempt is False
133137

138+
134139
def test_custom_royalty_fee():
135140
fallback_fee = CustomFixedFee(
136141
amount=50,
@@ -145,7 +150,9 @@ def test_custom_royalty_fee():
145150
)
146151

147152
proto = fee._to_proto() # Changed from _to_protobuf
148-
new_fee = CustomRoyaltyFee._from_proto(proto) # Changed from CustomFee._from_protobuf
153+
new_fee = CustomRoyaltyFee._from_proto(
154+
proto
155+
) # Changed from CustomFee._from_protobuf
149156

150157
assert isinstance(new_fee, CustomRoyaltyFee)
151158
assert new_fee.numerator == 5
@@ -156,59 +163,68 @@ def test_custom_royalty_fee():
156163
assert new_fee.fallback_fee.amount == 50
157164
assert new_fee.fallback_fee.denominating_token_id == TokenId(0, 0, 789)
158165

166+
159167
@pytest.mark.parametrize(
160-
"custom_royalty_fee, expected_str",
161-
[
162-
(
163-
CustomRoyaltyFee(
164-
numerator=3,
165-
denominator=20,
166-
fallback_fee=None,
167-
fee_collector_account_id=None,
168-
all_collectors_are_exempt=True,
169-
),
170-
"\n".join([
168+
"custom_royalty_fee, expected_str",
169+
[
170+
(
171+
CustomRoyaltyFee(
172+
numerator=3,
173+
denominator=20,
174+
fallback_fee=None,
175+
fee_collector_account_id=None,
176+
all_collectors_are_exempt=True,
177+
),
178+
"\n".join(
179+
[
171180
"CustomRoyaltyFee:",
172181
" Numerator = 3",
173182
" Denominator = 20",
174183
" Fallback Fee Amount = None",
175184
" Fallback Fee Denominating Token ID = None",
176185
" Fee Collector Account ID = None",
177186
" All Collectors Are Exempt = True",
178-
])
187+
]
179188
),
180-
(
181-
CustomRoyaltyFee(
182-
numerator=7,
183-
denominator=100,
184-
fallback_fee=CustomFixedFee(
185-
amount=30,
186-
denominating_token_id=TokenId(0, 0, 123),
187-
),
188-
fee_collector_account_id=AccountId(0, 0, 456),
189-
all_collectors_are_exempt=False,
189+
),
190+
(
191+
CustomRoyaltyFee(
192+
numerator=7,
193+
denominator=100,
194+
fallback_fee=CustomFixedFee(
195+
amount=30,
196+
denominating_token_id=TokenId(0, 0, 123),
190197
),
191-
"\n".join([
198+
fee_collector_account_id=AccountId(0, 0, 456),
199+
all_collectors_are_exempt=False,
200+
),
201+
"\n".join(
202+
[
192203
"CustomRoyaltyFee:",
193204
" Numerator = 7",
194205
" Denominator = 100",
195206
" Fallback Fee Amount = 30",
196207
" Fallback Fee Denominating Token ID = 0.0.123",
197208
" Fee Collector Account ID = 0.0.456",
198209
" All Collectors Are Exempt = False",
199-
])
200-
)
201-
]
210+
]
211+
),
212+
),
213+
],
202214
)
203-
def test_custom_royalty_fee_str(custom_royalty_fee: CustomRoyaltyFee, expected_str: str):
215+
def test_custom_royalty_fee_str(
216+
custom_royalty_fee: CustomRoyaltyFee, expected_str: str
217+
):
204218
"""Test the string representation of CustomRoyaltyFee."""
205219
fee_str = str(custom_royalty_fee)
206220
assert fee_str == expected_str
207221

222+
208223
class DummyCustomFee(CustomFee):
209224
def _to_proto(self):
210225
return "dummy-proto"
211226

227+
212228
def test_custom_fee_init_and_setters():
213229
fee = DummyCustomFee()
214230
assert fee.fee_collector_account_id is None
@@ -221,6 +237,7 @@ def test_custom_fee_init_and_setters():
221237
fee.set_all_collectors_are_exempt(True)
222238
assert fee.all_collectors_are_exempt is True
223239

240+
224241
def test_custom_fee_equality():
225242
fee1 = DummyCustomFee()
226243
fee2 = DummyCustomFee()
@@ -229,6 +246,7 @@ def test_custom_fee_equality():
229246
fee1.set_all_collectors_are_exempt(True)
230247
assert fee1 != fee2
231248

249+
232250
def test_custom_fee_get_fee_collector_account_id_protobuf():
233251
fee = DummyCustomFee()
234252
assert fee._get_fee_collector_account_id_protobuf() is None
@@ -238,6 +256,7 @@ def test_custom_fee_get_fee_collector_account_id_protobuf():
238256
fee.set_fee_collector_account_id(mock_account)
239257
assert fee._get_fee_collector_account_id_protobuf() == "proto-account"
240258

259+
241260
def test_custom_fee_validate_checksums():
242261
fee = DummyCustomFee()
243262
# No account, should not call validate_checksum
@@ -249,26 +268,29 @@ def test_custom_fee_validate_checksums():
249268
fee._validate_checksums(client)
250269
mock_account.validate_checksum.assert_called_once_with(client)
251270

271+
252272
def test_custom_fee_from_proto_unrecognized():
253273
class FakeProto:
254274
def WhichOneof(self, name):
255275
return "unknown_fee"
276+
256277
with pytest.raises(ValueError):
257278
CustomFee._from_proto(FakeProto())
258279

280+
259281
def test_set_amount_in_tinybars_deprecation():
260282
"""Test that set_amount_in_tinybars shows deprecation warning."""
261283
fee = CustomFixedFee()
262-
284+
263285
# Test that deprecation warning is raised
264286
with warnings.catch_warnings(record=True) as w:
265287
warnings.simplefilter("always")
266288
fee.set_amount_in_tinybars(100)
267-
289+
268290
assert len(w) == 1
269291
assert issubclass(w[0].category, DeprecationWarning)
270292
assert "set_amount_in_tinybars() is deprecated" in str(w[0].message)
271-
293+
272294
# Verify the method still works correctly
273295
assert fee.amount == 100
274296
assert fee.denominating_token_id is None

0 commit comments

Comments
 (0)