aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--slack/util.py5
-rw-r--r--tests/test_hook_process_hashtable.py5
-rw-r--r--tests/test_http_request.py7
-rw-r--r--tests/test_sleep.py3
4 files changed, 13 insertions, 7 deletions
diff --git a/slack/util.py b/slack/util.py
index b5b5bb2..8738748 100644
--- a/slack/util.py
+++ b/slack/util.py
@@ -10,8 +10,9 @@ weechat_callback_return_type = Union[int, str, Dict[str, str], None]
def get_callback_name(callback: Callable[..., weechat_callback_return_type]) -> str:
- shared.weechat_callbacks[callback.__name__] = callback
- return callback.__name__
+ callback_id = f"{callback.__name__}-{id(callback)}"
+ shared.weechat_callbacks[callback_id] = callback
+ return callback_id
def with_color(color: str, string: str):
diff --git a/tests/test_hook_process_hashtable.py b/tests/test_hook_process_hashtable.py
index e8a1f64..9d0db36 100644
--- a/tests/test_hook_process_hashtable.py
+++ b/tests/test_hook_process_hashtable.py
@@ -6,6 +6,7 @@ import weechat
import slack.http
from slack.http import hook_process_hashtable
from slack.task import FutureProcess, FutureTimer, weechat_task_cb
+from slack.util import get_callback_name
@patch.object(weechat, "hook_process_hashtable")
@@ -18,7 +19,7 @@ def test_hook_process_hashtable(mock_method: MagicMock):
assert isinstance(future, FutureProcess)
mock_method.assert_called_once_with(
- command, options, timeout, weechat_task_cb.__name__, future.id
+ command, options, timeout, get_callback_name(weechat_task_cb), future.id
)
with pytest.raises(StopIteration) as excinfo:
@@ -36,7 +37,7 @@ def test_hook_process_hashtable_chunked(mock_method: MagicMock):
assert isinstance(future, FutureProcess)
mock_method.assert_called_once_with(
- command, options, timeout, weechat_task_cb.__name__, future.id
+ command, options, timeout, get_callback_name(weechat_task_cb), future.id
)
assert isinstance(coroutine.send((command, -1, "o1", "e1")), FutureProcess)
diff --git a/tests/test_http_request.py b/tests/test_http_request.py
index 57b0c91..300882d 100644
--- a/tests/test_http_request.py
+++ b/tests/test_http_request.py
@@ -6,6 +6,7 @@ import weechat
from slack.http import HttpError, http_request
from slack.task import FutureProcess, FutureTimer, weechat_task_cb
+from slack.util import get_callback_name
@patch.object(weechat, "hook_process_hashtable")
@@ -21,7 +22,7 @@ def test_http_request_success(mock_method: MagicMock):
f"url:{url}",
{**options, "header": "1"},
timeout,
- weechat_task_cb.__name__,
+ get_callback_name(weechat_task_cb),
future.id,
)
@@ -151,7 +152,9 @@ def test_http_request_ratelimit(mock_method: MagicMock):
timer = coroutine.send(("", 0, body, ""))
assert isinstance(timer, FutureTimer)
- mock_method.assert_called_once_with(12000, 0, 1, weechat_task_cb.__name__, timer.id)
+ mock_method.assert_called_once_with(
+ 12000, 0, 1, get_callback_name(weechat_task_cb), timer.id
+ )
assert isinstance(coroutine.send((0,)), FutureProcess)
diff --git a/tests/test_sleep.py b/tests/test_sleep.py
index 4598778..893c108 100644
--- a/tests/test_sleep.py
+++ b/tests/test_sleep.py
@@ -4,6 +4,7 @@ import pytest
import weechat
from slack.task import FutureTimer, sleep, weechat_task_cb
+from slack.util import get_callback_name
@patch.object(weechat, "hook_timer")
@@ -14,7 +15,7 @@ def test_sleep(mock_method: MagicMock):
assert isinstance(future, FutureTimer)
mock_method.assert_called_once_with(
- milliseconds, 0, 1, weechat_task_cb.__name__, future.id
+ milliseconds, 0, 1, get_callback_name(weechat_task_cb), future.id
)
with pytest.raises(StopIteration) as excinfo: