Skip to content

Commit 579524f

Browse files
committed
fix: cross-platform test compatibility and add error framework tests
- Fix test_logging_factory.py: Use Path() for cross-platform path comparison - Fix test_log_message.py: Use Path.parts for platform-agnostic path checking - Fix test_gateway/test_config.py: Handle Windows forcing tcp transport - Add test_error.py: Comprehensive tests for unified error framework - Fix lint issues: contextlib.suppress, unused variables, specific exception types - Format all files with ruff
1 parent 94b3e32 commit 579524f

404 files changed

Lines changed: 3280 additions & 1329 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bt_api_py/containers/bars/kucoin_bar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import time
77

88
from bt_api_py.containers.bars.bar import BarData
9-
from bt_api_py.functions.utils import from_dict_get_float, from_dict_get_string
9+
from bt_api_py.functions.utils import from_dict_get_string
1010

1111

1212
class KuCoinBarData(BarData):

coverage_analysis.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@
22
==================================================
33

44
## Exchange Coverage
5-
Total exchanges: 72
6-
Tested exchanges: 69 (95.8%)
7-
Untested exchanges: 3
8-
9-
**Untested exchanges:**
10-
- aivora
11-
- allinx
12-
- ascendex
5+
Total exchanges: 68
6+
Tested exchanges: 68 (100.0%)
7+
Untested exchanges: 0
138

149
## Module Test Distribution
1510
feeds: 34 test files
16-
containers: 282 test files
11+
containers: 285 test files
1712
registry: 2 test files
1813
event_bus: 1 test files
1914
exceptions: 1 test files

tests/containers/accounts/test_bitfinex_account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Tests for Bitfinex account container."""
22

3-
import pytest
43

54
from bt_api_py.containers.accounts.bitfinex_account import (
65
BitfinexSpotRequestAccountData,
@@ -42,6 +41,7 @@ def test_init_data(self):
4241
def test_init_data_with_json_string(self):
4342
"""Test init_data with JSON string."""
4443
import json
44+
4545
data = json.dumps({"id": "12345", "currency": "USD"})
4646
account = BitfinexSpotRequestAccountData(data, asset_type="SPOT")
4747
account.init_data()

tests/containers/accounts/test_bitget_account.py

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Tests for Bitget account container."""
22

3-
import pytest
43

54
from bt_api_py.containers.accounts.bitget_account import (
65
BitgetAccountData,
@@ -34,7 +33,9 @@ def test_init_data(self):
3433
"marginAvailable": 8000.0,
3534
"marginForced": 0.0,
3635
}
37-
account = BitgetAccountData(data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True)
36+
account = BitgetAccountData(
37+
data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True
38+
)
3839
account.init_data()
3940

4041
assert account.uid == "12345"
@@ -50,7 +51,9 @@ def test_init_data(self):
5051
def test_init_data_idempotent(self):
5152
"""Test init_data is idempotent."""
5253
data = {"uid": "12345"}
53-
account = BitgetAccountData(data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True)
54+
account = BitgetAccountData(
55+
data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True
56+
)
5457
account.init_data()
5558
first_uid = account.uid
5659

@@ -59,63 +62,81 @@ def test_init_data_idempotent(self):
5962

6063
def test_get_exchange_name(self):
6164
"""Test get_exchange_name."""
62-
account = BitgetAccountData({}, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True)
65+
account = BitgetAccountData(
66+
{}, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True
67+
)
6368
assert account.get_exchange_name() == "BITGET"
6469

6570
def test_get_symbol_name(self):
6671
"""Test get_symbol_name."""
67-
account = BitgetAccountData({}, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True)
72+
account = BitgetAccountData(
73+
{}, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True
74+
)
6875
assert account.get_symbol_name() == "BTCUSDT"
6976

7077
def test_get_asset_type(self):
7178
"""Test get_asset_type."""
72-
account = BitgetAccountData({}, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True)
79+
account = BitgetAccountData(
80+
{}, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True
81+
)
7382
assert account.get_asset_type() == "SPOT"
7483

7584
def test_get_uid(self):
7685
"""Test get_uid."""
7786
data = {"uid": "12345"}
78-
account = BitgetAccountData(data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True)
87+
account = BitgetAccountData(
88+
data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True
89+
)
7990
account.init_data()
8091

8192
assert account.get_uid() == "12345"
8293

8394
def test_get_account_type(self):
8495
"""Test get_account_type."""
8596
data = {"accountType": "spot"}
86-
account = BitgetAccountData(data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True)
97+
account = BitgetAccountData(
98+
data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True
99+
)
87100
account.init_data()
88101

89102
assert account.get_account_type() == "spot"
90103

91104
def test_get_equity(self):
92105
"""Test get_equity."""
93106
data = {"equity": 10000.0}
94-
account = BitgetAccountData(data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True)
107+
account = BitgetAccountData(
108+
data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True
109+
)
95110
account.init_data()
96111

97112
assert account.get_equity() == 10000.0
98113

99114
def test_get_unrealized_pnl(self):
100115
"""Test get_unrealized_pnl."""
101116
data = {"unrealizedPnl": 500.0}
102-
account = BitgetAccountData(data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True)
117+
account = BitgetAccountData(
118+
data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True
119+
)
103120
account.init_data()
104121

105122
assert account.get_unrealized_pnl() == 500.0
106123

107124
def test_get_realized_pnl(self):
108125
"""Test get_realized_pnl."""
109126
data = {"realizedPnl": 1000.0}
110-
account = BitgetAccountData(data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True)
127+
account = BitgetAccountData(
128+
data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True
129+
)
111130
account.init_data()
112131

113132
assert account.get_realized_pnl() == 1000.0
114133

115134
def test_get_margin_available(self):
116135
"""Test get_margin_available."""
117136
data = {"marginAvailable": 8000.0}
118-
account = BitgetAccountData(data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True)
137+
account = BitgetAccountData(
138+
data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True
139+
)
119140
account.init_data()
120141

121142
assert account.get_margin_available() == 8000.0
@@ -126,7 +147,9 @@ def test_get_all_data(self):
126147
"uid": "12345",
127148
"equity": 10000.0,
128149
}
129-
account = BitgetAccountData(data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True)
150+
account = BitgetAccountData(
151+
data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True
152+
)
130153
result = account.get_all_data()
131154

132155
assert result["exchange_name"] == "BITGET"
@@ -136,7 +159,9 @@ def test_get_all_data(self):
136159
def test_str_representation(self):
137160
"""Test __str__ method."""
138161
data = {"uid": "12345"}
139-
account = BitgetAccountData(data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True)
162+
account = BitgetAccountData(
163+
data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True
164+
)
140165
result = str(account)
141166

142167
assert "BITGET" in result
@@ -172,7 +197,9 @@ def test_init_data(self):
172197
]
173198
}
174199
}
175-
account = BitgetSpotWssAccountData(data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True)
200+
account = BitgetSpotWssAccountData(
201+
data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True
202+
)
176203
# Work around bug by setting the attribute manually
177204
account.has_been_json_encoded = True
178205
account.init_data()
@@ -188,7 +215,9 @@ def test_get_balances(self):
188215
]
189216
}
190217
}
191-
account = BitgetSpotWssAccountData(data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True)
218+
account = BitgetSpotWssAccountData(
219+
data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True
220+
)
192221
account.has_been_json_encoded = True
193222
balances = account.get_balances()
194223

@@ -204,7 +233,9 @@ def test_get_balance(self):
204233
]
205234
}
206235
}
207-
account = BitgetSpotWssAccountData(data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True)
236+
account = BitgetSpotWssAccountData(
237+
data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True
238+
)
208239
account.has_been_json_encoded = True
209240
balance = account.get_balance("USDT")
210241

@@ -219,7 +250,9 @@ def test_get_balance_not_found(self):
219250
]
220251
}
221252
}
222-
account = BitgetSpotWssAccountData(data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True)
253+
account = BitgetSpotWssAccountData(
254+
data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True
255+
)
223256
account.has_been_json_encoded = True
224257
balance = account.get_balance("ETH")
225258

@@ -238,7 +271,9 @@ def test_get_total_equity(self):
238271
]
239272
}
240273
}
241-
account = BitgetSpotWssAccountData(data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True)
274+
account = BitgetSpotWssAccountData(
275+
data, symbol_name="BTCUSDT", asset_type="SPOT", has_been_json_encoded=True
276+
)
242277
account.has_been_json_encoded = True
243278
account.init_data()
244279
total = account.get_total_equity()

tests/containers/accounts/test_coinbase_account.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Tests for CoinbaseAccountData container."""
22

3-
import pytest
43

54
from bt_api_py.containers.accounts.coinbase_account import (
65
CoinbaseAccountData,
@@ -30,7 +29,9 @@ def test_init_data(self):
3029
"hold": {"value": "0.5"},
3130
"updated_at": "2024-01-01T00:00:00Z",
3231
}
33-
account = CoinbaseAccountData(data, symbol_name="BTC-USD", asset_type="SPOT", has_been_json_encoded=True)
32+
account = CoinbaseAccountData(
33+
data, symbol_name="BTC-USD", asset_type="SPOT", has_been_json_encoded=True
34+
)
3435
account.init_data()
3536

3637
assert account.has_been_init_data is True

tests/containers/accounts/test_htx_account.py

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Tests for HTX account container."""
22

3-
import pytest
43

54
from bt_api_py.containers.accounts.htx_account import HtxSpotRequestAccountData
65

@@ -29,22 +28,22 @@ def test_init_data(self):
2928
"subtype": "",
3029
"state": "working",
3130
}
32-
]
31+
],
3332
}
34-
account = HtxSpotRequestAccountData(data, symbol_name="btcusdt", asset_type="SPOT", has_been_json_encoded=True)
33+
account = HtxSpotRequestAccountData(
34+
data, symbol_name="btcusdt", asset_type="SPOT", has_been_json_encoded=True
35+
)
3536
account.init_data()
3637

3738
# Note: from_dict_get_float returns float, so id becomes "123456.0"
3839
assert account.account_id == "123456.0"
3940

4041
def test_init_data_idempotent(self):
4142
"""Test init_data is idempotent."""
42-
data = {
43-
"data": [
44-
{"id": 123456}
45-
]
46-
}
47-
account = HtxSpotRequestAccountData(data, symbol_name="btcusdt", asset_type="SPOT", has_been_json_encoded=True)
43+
data = {"data": [{"id": 123456}]}
44+
account = HtxSpotRequestAccountData(
45+
data, symbol_name="btcusdt", asset_type="SPOT", has_been_json_encoded=True
46+
)
4847
account.init_data()
4948
first_id = account.account_id
5049

@@ -68,12 +67,10 @@ def test_get_asset_type(self):
6867

6968
def test_get_account_id(self):
7069
"""Test get_account_id."""
71-
data = {
72-
"data": [
73-
{"id": 123456}
74-
]
75-
}
76-
account = HtxSpotRequestAccountData(data, symbol_name="btcusdt", asset_type="SPOT", has_been_json_encoded=True)
70+
data = {"data": [{"id": 123456}]}
71+
account = HtxSpotRequestAccountData(
72+
data, symbol_name="btcusdt", asset_type="SPOT", has_been_json_encoded=True
73+
)
7774
result = account.get_account_id()
7875

7976
assert result == "123456.0"
@@ -99,12 +96,10 @@ def test_get_used_margin(self):
9996

10097
def test_get_all_data(self):
10198
"""Test get_all_data."""
102-
data = {
103-
"data": [
104-
{"id": 123456}
105-
]
106-
}
107-
account = HtxSpotRequestAccountData(data, symbol_name="btcusdt", asset_type="SPOT", has_been_json_encoded=True)
99+
data = {"data": [{"id": 123456}]}
100+
account = HtxSpotRequestAccountData(
101+
data, symbol_name="btcusdt", asset_type="SPOT", has_been_json_encoded=True
102+
)
108103
account.init_data()
109104
result = account.get_all_data()
110105

@@ -113,12 +108,10 @@ def test_get_all_data(self):
113108

114109
def test_str_representation(self):
115110
"""Test __str__ method."""
116-
data = {
117-
"data": [
118-
{"id": 123456}
119-
]
120-
}
121-
account = HtxSpotRequestAccountData(data, symbol_name="btcusdt", asset_type="SPOT", has_been_json_encoded=True)
111+
data = {"data": [{"id": 123456}]}
112+
account = HtxSpotRequestAccountData(
113+
data, symbol_name="btcusdt", asset_type="SPOT", has_been_json_encoded=True
114+
)
122115
result = str(account)
123116

124117
assert "HTX" in result

0 commit comments

Comments
 (0)