Skip to content

Commit 10509e6

Browse files
committed
(fix) Fixed pre-commit errors
1 parent 251ae51 commit 10509e6

File tree

3 files changed

+133
-52
lines changed

3 files changed

+133
-52
lines changed

pyinjective/async_client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,9 @@ async def listen_derivative_market_updates(
16171617
async def fetch_derivative_orderbook_v2(self, market_id: str, depth: Optional[int] = None) -> Dict[str, Any]:
16181618
return await self.indexer_client.fetch_derivative_orderbook_v2(market_id=market_id, depth=depth or 0)
16191619

1620-
async def fetch_derivative_orderbooks_v2(self, market_ids: List[str], depth: Optional[int] = None) -> Dict[str, Any]:
1620+
async def fetch_derivative_orderbooks_v2(
1621+
self, market_ids: List[str], depth: Optional[int] = None
1622+
) -> Dict[str, Any]:
16211623
return await self.indexer_client.fetch_derivative_orderbooks_v2(market_ids=market_ids, depth=depth or 0)
16221624

16231625
async def fetch_derivative_orders(
Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,57 @@
11
import warnings
22
from unittest.mock import MagicMock, patch
33

4-
import pytest
5-
64
from pyinjective.core.network import Network
75

86

97
class TestAsyncClientDeprecationWarnings:
10-
def test_async_client_deprecation_warning(self):
8+
@patch("pyinjective.async_client.asyncio.get_event_loop")
9+
@patch("pyinjective.async_client.ChainGrpcChainStream")
10+
@patch("pyinjective.async_client.ChainGrpcExchangeApi")
11+
@patch("pyinjective.async_client.ChainGrpcDistributionApi")
12+
@patch("pyinjective.async_client.ChainGrpcAuthZApi")
13+
@patch("pyinjective.async_client.ChainGrpcAuthApi")
14+
@patch("pyinjective.async_client.ChainGrpcBankApi")
15+
@patch("pyinjective.async_client.IndexerClient")
16+
def test_async_client_deprecation_warning(self, *mocks):
1117
"""Test that creating an AsyncClient instance raises a deprecation warning with correct details."""
12-
with patch('pyinjective.async_client.IndexerClient'), \
13-
patch('pyinjective.async_client.ChainGrpcBankApi'), \
14-
patch('pyinjective.async_client.ChainGrpcAuthApi'), \
15-
patch('pyinjective.async_client.ChainGrpcAuthZApi'), \
16-
patch('pyinjective.async_client.ChainGrpcDistributionApi'), \
17-
patch('pyinjective.async_client.ChainGrpcExchangeApi'), \
18-
patch('pyinjective.async_client.ChainGrpcChainStream'), \
19-
patch('pyinjective.async_client.asyncio.get_event_loop'):
20-
21-
# Create a mock network to avoid actual network initialization
22-
mock_network = MagicMock(spec=Network)
23-
mock_network.chain_cookie_assistant = MagicMock()
24-
mock_network.create_chain_grpc_channel = MagicMock()
25-
mock_network.create_chain_stream_grpc_channel = MagicMock()
26-
mock_network.official_tokens_list_url = "https://example.com/tokens.json"
27-
28-
# Import here to avoid early import issues
29-
from pyinjective.async_client import AsyncClient
30-
31-
# Capture warnings
32-
with warnings.catch_warnings(record=True) as warning_list:
33-
warnings.simplefilter("always") # Ensure all warnings are captured
34-
35-
# Create AsyncClient instance - this should trigger the deprecation warning
36-
client = AsyncClient(network=mock_network)
37-
38-
# Find the AsyncClient deprecation warning
39-
async_client_warnings = [
40-
w for w in warning_list
41-
if issubclass(w.category, DeprecationWarning) and
42-
"AsyncClient from pyinjective.async_client is deprecated" in str(w.message)
43-
]
44-
45-
# Should have exactly one warning
46-
assert len(async_client_warnings) == 1
47-
48-
warning = async_client_warnings[0]
49-
# Check warning message contains migration advice
50-
assert "Please use AsyncClient from pyinjective.async_client_v2 instead" in str(warning.message)
51-
# Check warning category
52-
assert warning.category == DeprecationWarning
53-
# Check stacklevel is working correctly (should point to this test file)
54-
assert "test_async_client_deprecation_warnings.py" in warning.filename
55-
56-
# Verify the client was still created successfully
57-
assert client is not None
58-
assert hasattr(client, 'network')
59-
assert client.network == mock_network
18+
# Create a mock network to avoid actual network initialization
19+
mock_network = MagicMock(spec=Network)
20+
mock_network.chain_cookie_assistant = MagicMock()
21+
mock_network.create_chain_grpc_channel = MagicMock()
22+
mock_network.create_chain_stream_grpc_channel = MagicMock()
23+
mock_network.official_tokens_list_url = "https://example.com/tokens.json"
24+
25+
# Import here to avoid early import issues
26+
from pyinjective.async_client import AsyncClient
27+
28+
# Capture warnings
29+
with warnings.catch_warnings(record=True) as warning_list:
30+
warnings.simplefilter("always") # Ensure all warnings are captured
31+
32+
# Create AsyncClient instance - this should trigger the deprecation warning
33+
client = AsyncClient(network=mock_network)
34+
35+
# Find the AsyncClient deprecation warning
36+
async_client_warnings = [
37+
w
38+
for w in warning_list
39+
if issubclass(w.category, DeprecationWarning)
40+
and "AsyncClient from pyinjective.async_client is deprecated" in str(w.message)
41+
]
42+
43+
# Should have exactly one warning
44+
assert len(async_client_warnings) == 1
45+
46+
warning = async_client_warnings[0]
47+
# Check warning message contains migration advice
48+
assert "Please use AsyncClient from pyinjective.async_client_v2 instead" in str(warning.message)
49+
# Check warning category
50+
assert warning.category == DeprecationWarning
51+
# Check stacklevel is working correctly (should point to this test file)
52+
assert "test_async_client_deprecation_warnings.py" in warning.filename
53+
54+
# Verify the client was still created successfully
55+
assert client is not None
56+
assert hasattr(client, "network")
57+
assert client.network == mock_network
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import warnings
2+
from unittest.mock import MagicMock, patch
3+
4+
from pyinjective.core.network import Network
5+
6+
7+
class TestIndexerClientDeprecationWarnings:
8+
@patch("pyinjective.indexer_client.IndexerGrpcSpotStream")
9+
@patch("pyinjective.indexer_client.IndexerGrpcPortfolioStream")
10+
@patch("pyinjective.indexer_client.IndexerGrpcOracleStream")
11+
@patch("pyinjective.indexer_client.IndexerGrpcMetaStream")
12+
@patch("pyinjective.indexer_client.IndexerGrpcExplorerStream")
13+
@patch("pyinjective.indexer_client.IndexerGrpcDerivativeStream")
14+
@patch("pyinjective.indexer_client.IndexerGrpcAuctionStream")
15+
@patch("pyinjective.indexer_client.IndexerGrpcAccountStream")
16+
@patch("pyinjective.indexer_client.IndexerGrpcSpotApi")
17+
@patch("pyinjective.indexer_client.IndexerGrpcPortfolioApi")
18+
@patch("pyinjective.indexer_client.IndexerGrpcOracleApi")
19+
@patch("pyinjective.indexer_client.IndexerGrpcMetaApi")
20+
@patch("pyinjective.indexer_client.IndexerGrpcInsuranceApi")
21+
@patch("pyinjective.indexer_client.IndexerGrpcExplorerApi")
22+
@patch("pyinjective.indexer_client.IndexerGrpcDerivativeApi")
23+
@patch("pyinjective.indexer_client.IndexerGrpcAuctionApi")
24+
@patch("pyinjective.indexer_client.IndexerGrpcAccountApi")
25+
def test_listen_derivative_positions_updates_deprecation_warning(self, *mocks):
26+
"""Test that calling listen_derivative_positions_updates raises a deprecation warning."""
27+
# Create a mock network to avoid actual network initialization
28+
mock_network = MagicMock(spec=Network)
29+
mock_network.exchange_cookie_assistant = MagicMock()
30+
mock_network.explorer_cookie_assistant = MagicMock()
31+
mock_network.create_exchange_grpc_channel = MagicMock()
32+
mock_network.create_explorer_grpc_channel = MagicMock()
33+
34+
# Import here to avoid early import issues
35+
from pyinjective.indexer_client import IndexerClient
36+
37+
# Create IndexerClient instance
38+
client = IndexerClient(network=mock_network)
39+
40+
# Mock the derivative_stream_api.stream_positions method to avoid actual streaming
41+
client.derivative_stream_api.stream_positions = MagicMock()
42+
43+
# Capture warnings
44+
with warnings.catch_warnings(record=True) as warning_list:
45+
warnings.simplefilter("always") # Ensure all warnings are captured
46+
47+
# Mock callback function
48+
mock_callback = MagicMock()
49+
50+
# Call the deprecated method - this should trigger the deprecation warning
51+
client.listen_derivative_positions_updates(
52+
callback=mock_callback, market_ids=["market_1"], subaccount_ids=["subaccount_1"]
53+
)
54+
55+
# Find the deprecation warning
56+
deprecation_warnings = [
57+
w
58+
for w in warning_list
59+
if issubclass(w.category, DeprecationWarning)
60+
and "This method is deprecated. Use listen_derivative_positions_v2_updates instead" in str(w.message)
61+
]
62+
63+
# Should have exactly one warning
64+
assert len(deprecation_warnings) == 1
65+
66+
warning = deprecation_warnings[0]
67+
# Check warning message contains migration advice
68+
assert "Use listen_derivative_positions_v2_updates instead" in str(warning.message)
69+
# Check warning category
70+
assert warning.category == DeprecationWarning
71+
# Check stacklevel is working correctly (should point to this test file)
72+
assert "test_indexer_client_deprecation_warnings.py" in warning.filename
73+
74+
# Verify the underlying method was still called (functionality preserved)
75+
client.derivative_stream_api.stream_positions.assert_called_once_with(
76+
callback=mock_callback,
77+
on_end_callback=None,
78+
on_status_callback=None,
79+
market_ids=["market_1"],
80+
subaccount_ids=["subaccount_1"],
81+
)

0 commit comments

Comments
 (0)