Skip to content

Commit a91515b

Browse files
mattstaclaude
andcommitted
Switch test assertions to canonical commissionAndFees, drop deprecation warnings
The protobuf-side tests asserted on the legacy ``.commission`` attribute and ``commission=`` kwarg in ~15 places, each producing a ``DeprecationWarning`` on every test run. The legacy alias is documented behaviour through v4.0 — the warnings are noise, not signal — so the tests should use the canonical ``.commissionAndFees`` name everywhere except where the deprecation alias itself is the contract under test. Changes: * Switch all assertions / constructor kwargs / handler-captured reads from ``.commission`` / ``commission=`` to ``.commissionAndFees`` / ``commissionAndFees=`` across ``test_proto_audit_regressions.py``, ``test_proto_decoder_dispatch.py``, ``test_proto_orders.py``, ``test_round6_cross_handler_invariants.py``. * Two tests in ``test_proto_orders.py`` specifically exercise the rename / deprecation alias surface (``test_create_order_state_renames_commission_and_fees_to_commission``, ``test_create_commission_report_renames_fields``). Those keep the legacy ``.commission`` access and gain ``@pytest.mark.filterwarnings("ignore::DeprecationWarning")`` so the alias contract stays pinned without polluting the warning stream. Net: 1001 owned tests still pass; the DeprecationWarning chatter is gone from the test output. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 6951a8d commit a91515b

5 files changed

Lines changed: 26 additions & 15 deletions

tests/test_contract.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import pandas as pd
2+
import pytest
23

34
import ib_async
45
from ib_async import Stock, util
56

7+
# Live: requires a running TWS / IB Gateway on 127.0.0.1:4001.
8+
# Skipped by default. Opt in with ``pytest -m live``.
9+
pytestmark = pytest.mark.live
10+
611

712
def test_contract_format_data_pd():
813
"""Simple smoketest to verify everything still works minimally."""

tests/test_proto_audit_regressions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_commission_report_unset_realized_pnl_stays_none_not_nan():
8181
ib.client.decoder.processProtoBuf(59, proto.SerializeToString())
8282

8383
# commission did flow.
84-
assert fill.commissionReport.commission == Decimal("1.25")
84+
assert fill.commissionReport.commissionAndFees == Decimal("1.25")
8585
# realizedPNL / yield_ stay None — NOT Decimal('NaN'), NOT 0.
8686
assert fill.commissionReport.realizedPNL is None
8787
assert fill.commissionReport.yield_ is None
@@ -124,14 +124,14 @@ def test_commission_report_explicit_none_survives_wrapper_dispatch():
124124

125125
explicit = ibi.CommissionReport(
126126
execId="exec-explicit-none",
127-
commission=Decimal("0.50"),
127+
commissionAndFees=Decimal("0.50"),
128128
currency="USD",
129129
realizedPNL=None,
130130
yield_=None,
131131
)
132132
ib.wrapper.commissionReport(explicit)
133133

134-
assert fill.commissionReport.commission == Decimal("0.50")
134+
assert fill.commissionReport.commissionAndFees == Decimal("0.50")
135135
assert fill.commissionReport.realizedPNL is None
136136
assert fill.commissionReport.yield_ is None
137137
# Direct NaN guard: nothing morphed silently into a NaN sentinel.
@@ -2582,7 +2582,7 @@ def test_commission_report_arriving_before_fill_is_buffered_and_drained():
25822582

25832583
# 1) Commission report arrives FIRST. It must be parked, not dropped.
25842584
early_report = ibi.CommissionReport(
2585-
execId="exec-early", commission=2.5, currency="USD"
2585+
execId="exec-early", commissionAndFees=2.5, currency="USD"
25862586
)
25872587
ib.wrapper.commissionReport(early_report)
25882588
# Not yet emitted — fill doesn't exist.
@@ -2605,9 +2605,9 @@ def test_commission_report_arriving_before_fill_is_buffered_and_drained():
26052605

26062606
assert "exec-early" not in ib.wrapper._pendingCommissionReports
26072607
assert len(trade.fills) == 1
2608-
assert trade.fills[0].commissionReport.commission == 2.5
2608+
assert trade.fills[0].commissionReport.commissionAndFees == 2.5
26092609
assert len(seenCommission) == 1
2610-
assert seenCommission[0][2].commission == 2.5
2610+
assert seenCommission[0][2].commissionAndFees == 2.5
26112611

26122612

26132613
def test_completed_order_for_existing_trade_updates_status_to_terminal():

tests/test_proto_decoder_dispatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def test_commission_report_proto_attaches_to_existing_fill():
177177
ib.client.decoder.processProtoBuf(59, proto.SerializeToString())
178178

179179
assert fill.commissionReport.execId == "exec-7"
180-
assert fill.commissionReport.commission == Decimal("1.25")
180+
assert fill.commissionReport.commissionAndFees == Decimal("1.25")
181181
assert fill.commissionReport.realizedPNL == Decimal(10)
182182

183183

tests/test_proto_orders.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
from decimal import Decimal
2323

24+
import pytest
25+
2426
from ib_async._pb import (
2527
AttachedOrders_pb2,
2628
CommissionAndFeesReport_pb2,
@@ -421,6 +423,7 @@ def test_order_status_total_property_sums_when_both_set():
421423
# ---------------------------------------------------------------------------
422424

423425

426+
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
424427
def test_create_order_state_renames_commission_and_fees_to_commission():
425428
proto = OrderState_pb2.OrderState()
426429
proto.status = "PreSubmitted"
@@ -552,6 +555,7 @@ def test_create_execution_reads_submitter_and_opt_exercise_type():
552555
# ---------------------------------------------------------------------------
553556

554557

558+
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
555559
def test_create_commission_report_renames_fields():
556560
proto = CommissionAndFeesReport_pb2.CommissionAndFeesReport()
557561
proto.execId = "exec-1"
@@ -578,13 +582,13 @@ def test_create_commission_report_unparseable_redemption_date_safe():
578582
proto.yieldRedemptionDate = "garbage"
579583
report = createCommissionReport(proto)
580584
assert report.yieldRedemptionDate == 0
581-
assert report.commission == Decimal("1.25")
585+
assert report.commissionAndFees == Decimal("1.25")
582586

583587

584588
def test_create_commission_report_handles_empty_proto():
585589
proto = CommissionAndFeesReport_pb2.CommissionAndFeesReport()
586590
report = createCommissionReport(proto)
587-
assert report.commission is None
591+
assert report.commissionAndFees is None
588592
assert report.realizedPNL is None
589593
assert report.yield_ is None
590594

tests/test_round6_cross_handler_invariants.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,13 @@ def test_execDetails_then_commissionReport_pairs_on_fill():
444444
)
445445
ib.wrapper.execDetails(reqId=99, contract=contract, execution=execution)
446446
assert len(trade.fills) == 1
447-
assert trade.fills[0].commissionReport.commission is None
447+
assert trade.fills[0].commissionReport.commissionAndFees is None
448448

449449
report = ibi.CommissionReport(
450-
execId=execId, commission=Decimal("1.0"), currency="USD"
450+
execId=execId, commissionAndFees=Decimal("1.0"), currency="USD"
451451
)
452452
ib.wrapper.commissionReport(report)
453-
assert trade.fills[0].commissionReport.commission == Decimal("1.0")
453+
assert trade.fills[0].commissionReport.commissionAndFees == Decimal("1.0")
454454
assert len(seenComm) == 1
455455

456456

@@ -476,7 +476,7 @@ def test_execDetails_without_commissionReport_keeps_default_empty():
476476

477477
assert len(trade.fills) == 1
478478
cr = trade.fills[0].commissionReport
479-
assert cr.commission is None
479+
assert cr.commissionAndFees is None
480480
assert cr.realizedPNL is None
481481
assert cr.execId == ""
482482

@@ -637,7 +637,7 @@ def test_fills_aggregate_invariants_match_orderStatus_after_lifecycle():
637637
)
638638
ib.wrapper.commissionReport(
639639
ibi.CommissionReport(
640-
execId=execId, commission=Decimal("0.5"), currency="USD"
640+
execId=execId, commissionAndFees=Decimal("0.5"), currency="USD"
641641
)
642642
)
643643
cum += Decimal(sharesStr)
@@ -659,7 +659,9 @@ def test_fills_aggregate_invariants_match_orderStatus_after_lifecycle():
659659
assert trade.orderStatus.status == "Filled"
660660
assert trade.filled() == Decimal(50)
661661
assert trade.remaining() == Decimal(0)
662-
assert all(f.commissionReport.commission == Decimal("0.5") for f in trade.fills)
662+
assert all(
663+
f.commissionReport.commissionAndFees == Decimal("0.5") for f in trade.fills
664+
)
663665
# All fills carry the same permId — the wire's link from the
664666
# execution back to the order. Here we asserted on
665667
# ``trade.orderStatus.permId`` (set on the orderStatus callback)

0 commit comments

Comments
 (0)