backwards-compatible renaming
This commit is contained in:
parent
0aa76cd98c
commit
8c414fd87d
@ -40,9 +40,9 @@ pytest
|
||||
## Usage
|
||||
|
||||
```python
|
||||
from announce_server.announce import announce_server
|
||||
from announce_server import register_service
|
||||
|
||||
@announce_server(name="server_name", ip="server_ip", port=8000, host_ip="host_server_ip", host_port=5000, retry_interval=5)
|
||||
@register_service(name="server_name", ip="server_ip", port=8000, host_ip="host_server_ip", host_port=5000, retry_interval=5)
|
||||
def your_function():
|
||||
pass
|
||||
|
||||
|
@ -1,2 +1,8 @@
|
||||
from .decorator import _announce_server, announce_server
|
||||
from .decorator import (
|
||||
_announce_server,
|
||||
announce_server,
|
||||
register_block,
|
||||
register_server,
|
||||
register_service,
|
||||
)
|
||||
from .get_ip import get_ip_address
|
||||
|
@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
import warnings
|
||||
from functools import wraps
|
||||
|
||||
import socketio
|
||||
@ -45,9 +46,9 @@ async def _announce_server(**kwargs):
|
||||
await main()
|
||||
|
||||
|
||||
def announce_server(task=None, **outer_kwargs):
|
||||
def register_service(task=None, **outer_kwargs):
|
||||
if task is None:
|
||||
return lambda f: announce_server(f, **outer_kwargs)
|
||||
return lambda f: register_service(f, **outer_kwargs)
|
||||
|
||||
@wraps(task)
|
||||
def wrapper(*args, **kwargs):
|
||||
@ -64,3 +65,23 @@ def announce_server(task=None, **outer_kwargs):
|
||||
return asyncio.run(main())
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
def announce_server(*args, **kwargs):
|
||||
"""Wrapper for register_service"""
|
||||
warnings.warn(
|
||||
"announce_server is deprecated, use register_service instead",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return register_service(*args, **kwargs)
|
||||
|
||||
|
||||
def register_block(*args, **kwargs):
|
||||
"""Wrapper for register_service"""
|
||||
return register_service(*args, **kwargs)
|
||||
|
||||
|
||||
def register_server(*args, **kwargs):
|
||||
"""Wrapper for register_service"""
|
||||
return register_service(*args, **kwargs)
|
||||
|
37
tests/test_aliases.py
Normal file
37
tests/test_aliases.py
Normal file
@ -0,0 +1,37 @@
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from announce_server.decorator import (
|
||||
announce_server,
|
||||
register_block,
|
||||
register_server,
|
||||
register_service,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"decorator_alias",
|
||||
[
|
||||
announce_server,
|
||||
register_block,
|
||||
register_server,
|
||||
],
|
||||
)
|
||||
def test_alias_calls_register_service(decorator_alias):
|
||||
test_args = (None, None)
|
||||
test_kwargs = {
|
||||
"name": "test_server",
|
||||
"ip": "127.0.0.1",
|
||||
"port": 8000,
|
||||
"host_ip": "127.0.0.1",
|
||||
"host_port": 5000,
|
||||
}
|
||||
|
||||
with patch("announce_server.decorator.register_service") as mock_register_service:
|
||||
mock_register_service.return_value = MagicMock()
|
||||
|
||||
decorator = decorator_alias(*test_args, **test_kwargs)
|
||||
decorator(MagicMock())
|
||||
|
||||
mock_register_service.assert_called_once_with(*test_args, **test_kwargs)
|
@ -4,7 +4,7 @@ from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from announce_server.decorator import _announce_server, announce_server
|
||||
from announce_server.decorator import _announce_server, register_service
|
||||
|
||||
|
||||
@patch("announce_server.decorator._announce_server")
|
||||
@ -13,7 +13,7 @@ def test_announce_server_decorator(mock_announce_server):
|
||||
mock_announce_server.return_value = MagicMock()
|
||||
|
||||
# Decorate the sample function with announce_server
|
||||
@announce_server(
|
||||
@register_service(
|
||||
name="test_server",
|
||||
ip="127.0.0.1",
|
||||
port=8000,
|
||||
|
Loading…
Reference in New Issue
Block a user