Add test for stream
This commit is contained in:
parent
d8dfc7119e
commit
ecdbc2fa45
|
@ -1,5 +1,6 @@
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from unittest.mock import Mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from pytest_mock import MockerFixture
|
from pytest_mock import MockerFixture
|
||||||
|
@ -11,7 +12,9 @@ sys.path.insert(0, SRC_PATH)
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def bot(mocker: MockerFixture):
|
def bot(mocker: MockerFixture):
|
||||||
yield mocker.patch('discord.ext.commands.Bot', autospec=True)
|
bot_mock = mocker.patch('discord.ext.commands.Bot', autospec=True)
|
||||||
|
bot_mock.loop = Mock()
|
||||||
|
yield bot_mock
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from unittest.mock import AsyncMock
|
from unittest.mock import Mock, AsyncMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
@ -36,3 +36,19 @@ async def test_bot_ensure_voice(bot, ctx):
|
||||||
ctx.author.voice = None
|
ctx.author.voice = None
|
||||||
with pytest.raises(commands.CommandError):
|
with pytest.raises(commands.CommandError):
|
||||||
await mbot.ensure_voice(ctx)
|
await mbot.ensure_voice(ctx)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_bot_stream(bot, ctx):
|
||||||
|
mbot = Music(bot)
|
||||||
|
|
||||||
|
with patch('bot.YTDLSource', new_callable=AsyncMock) as ytdl_source:
|
||||||
|
player = Mock()
|
||||||
|
ytdl_source.from_url.return_value = player
|
||||||
|
url = 'A Day To Remember - All I Want'
|
||||||
|
# pylint: disable=too-many-function-args
|
||||||
|
await mbot.stream(mbot, ctx, url=url)
|
||||||
|
assert ytdl_source.from_url.await_args.args == (url,)
|
||||||
|
assert ytdl_source.from_url.await_args.kwargs == {"loop": bot.loop, "stream": True}
|
||||||
|
assert ctx.voice_client.play.call_args.args == (player,)
|
||||||
|
assert ctx.send.call_count == 1
|
||||||
|
|
Loading…
Reference in New Issue