Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 137 additions & 63 deletions binance/ws/streams.py

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
[tool.ruff]
preview = true
lint.ignore = ["F722","F841","F821","E402","E501","E902","E713","E741","E714", "E275","E721","E266", "E261"]
lint.ignore = [
"F722","F841","F821","E402","E501","E902","E713","E741","E714",
"E275","E721","E266","E261",
# Type annotation modernization (fix gradually)
"FA100","FA102","UP004","UP006","UP008","UP009","UP028","UP031","UP032","UP035",
# Import sorting (fix gradually)
"I001",
# Code style (fix gradually)
"B006","B017","BLE001","C402","DTZ004","DTZ005","EXE001","EXE002",
"FURB167","N999","PIE790","PIE808","PLC0414","PLR1711","PLR2044",
"RUF010","RUF100","S102","S110",
"SIM102","SIM117","SIM118","SIM401",
"TRY002","TRY004","TRY201",
]

[tool.pytest.ini_options]
timeout = 90
timeout_method = "thread"
asyncio_default_fixture_loop_scope = "function"

42 changes: 24 additions & 18 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
testnet = os.getenv("TEST_TESTNET", "true").lower() == "true"
api_key = "u4L8MG2DbshTfTzkx2Xm7NfsHHigvafxeC29HrExEmah1P8JhxXkoOu6KntLICUc"
api_secret = "hBZEqhZUUS6YZkk7AIckjJ3iLjrgEFr5CRtFPp5gjzkrHKKC9DAv4OH25PlT6yq5"
testnet = True # only for spot now
demo = True # spot and swap
testnet = True # only for spot now
demo = True # spot and swap
futures_api_key = "HjhMFvuF1veWQVdUbLIy7TiCYe9fj4W6sEukmddD8TM9kPVRHMK6nS2SdV5mwE5u"
futures_api_secret = "Suu9pWcO9zbvVuc6cSQsVuiiw2DmmA8DgHrUfePF9s2RtaHa0zxK3eAF4MfIk7Pd"

Expand Down Expand Up @@ -58,9 +58,7 @@ def liveClient():

@pytest.fixture(scope="function")
def futuresClient():
return Client(
futures_api_key, futures_api_secret, {"proxies": proxies}, demo=demo
)
return Client(futures_api_key, futures_api_secret, {"proxies": proxies}, demo=demo)


@pytest_asyncio.fixture(scope="function")
Expand Down Expand Up @@ -91,12 +89,14 @@ async def liveClientAsync():
finally:
await client.close_connection()


@pytest.fixture(scope="function")
def manager():
return ThreadedWebsocketManager(
api_key="test_key", api_secret="test_secret", https_proxy=proxy, testnet=True
)


@pytest.fixture(autouse=True, scope="function")
def event_loop():
"""Create new event loop for each test"""
Expand All @@ -111,7 +111,9 @@ def event_loop():
for task in pending:
task.cancel()
if pending:
loop.run_until_complete(asyncio.gather(*pending, return_exceptions=True))
loop.run_until_complete(
asyncio.gather(*pending, return_exceptions=True)
)
except Exception:
pass # Ignore cleanup errors
finally:
Expand Down Expand Up @@ -178,36 +180,40 @@ def pytest_collection_modifyitems(config, items):
item.add_marker(skip_gift_card)


def call_method_and_assert_uri_contains(client, method_name, expected_string, *args, **kwargs):
def call_method_and_assert_uri_contains(
client, method_name, expected_string, *args, **kwargs
):
"""
Helper function to test that a client method calls the expected URI.

Args:
client: The client instance to test
method_name: Name of the method to call (as string)
expected_string: String that should be present in the URI
*args, **kwargs: Arguments to pass to the client method

Returns:
The result of the method call
"""
from unittest.mock import patch
with patch.object(client, '_request', wraps=client._request) as mock_request:

with patch.object(client, "_request", wraps=client._request) as mock_request:
# Get the method from the client and call it
method = getattr(client, method_name)
result = method(*args, **kwargs)

# Assert that _request was called
mock_request.assert_called_once()

# Get the arguments passed to _request
args_passed, kwargs_passed = mock_request.call_args
args_passed, _kwargs_passed = mock_request.call_args

# The second argument is the URI
uri = args_passed[1]

# Assert that the URL contains the expected string
assert expected_string in uri, f"Expected '{expected_string}' in URL, but got: {uri}"

assert expected_string in uri, (
f"Expected '{expected_string}' in URL, but got: {uri}"
)

return result
Loading
Loading