Add comments
This commit is contained in:
parent
645e6556a4
commit
a2a84d5e33
|
@ -7,14 +7,14 @@ from discord.ext import commands
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_bot_ensure_voice(mbot, ctx):
|
async def test_bot_ensure_voice(mbot, ctx):
|
||||||
# Connects to voice channel of author if possible
|
# TEST: Connects to voice channel of author if possible
|
||||||
ctx.voice_client = None
|
ctx.voice_client = None
|
||||||
ctx.author.voice = AsyncMock()
|
ctx.author.voice = AsyncMock()
|
||||||
await mbot.ensure_voice(ctx)
|
await mbot.ensure_voice(ctx)
|
||||||
assert ctx.author.voice.channel.connect.call_count == 1, "Did not connect to voice channel of author"
|
assert ctx.author.voice.channel.connect.call_count == 1, "Did not connect to voice channel of author"
|
||||||
ctx.reset_mock(return_value=True)
|
ctx.reset_mock(return_value=True)
|
||||||
|
|
||||||
# Error if author not inside a channel
|
# TEST: Error if author not inside a channel
|
||||||
ctx.voice_client = None
|
ctx.voice_client = None
|
||||||
ctx.author.voice = None
|
ctx.author.voice = None
|
||||||
with pytest.raises(commands.CommandError):
|
with pytest.raises(commands.CommandError):
|
||||||
|
@ -35,6 +35,8 @@ def mock_ffmpeg_pcm_audio(ffmpeg_pcm_audio):
|
||||||
async def test_bot_playback(mbot, ctx):
|
async def test_bot_playback(mbot, ctx):
|
||||||
with patch.object(mbot, '_ytdl') as ytdl:
|
with patch.object(mbot, '_ytdl') as ytdl:
|
||||||
with patch('discord.FFmpegPCMAudio') as ffmpeg_pcm_audio:
|
with patch('discord.FFmpegPCMAudio') as ffmpeg_pcm_audio:
|
||||||
|
|
||||||
|
# TEST: First song queued is immediately played
|
||||||
ctx.voice_client.is_playing.return_value = False
|
ctx.voice_client.is_playing.return_value = False
|
||||||
url = "https://www.youtube.com/watch?v=Wr9LZ1hAFpQ"
|
url = "https://www.youtube.com/watch?v=Wr9LZ1hAFpQ"
|
||||||
title = "In Flames - Deliver Us (Official Video)"
|
title = "In Flames - Deliver Us (Official Video)"
|
||||||
|
@ -66,6 +68,7 @@ async def test_bot_playback(mbot, ctx):
|
||||||
ctx.send.call_args.args == (f"Now playing: {title}",), \
|
ctx.send.call_args.args == (f"Now playing: {title}",), \
|
||||||
"Did not send 'Now playing:' message"
|
"Did not send 'Now playing:' message"
|
||||||
|
|
||||||
|
# TEST: Following songs are put inside a queue
|
||||||
ctx.voice_client.is_playing.return_value = True
|
ctx.voice_client.is_playing.return_value = True
|
||||||
url = "https://www.youtube.com/watch?v=pMDcYX2wRSg"
|
url = "https://www.youtube.com/watch?v=pMDcYX2wRSg"
|
||||||
title = "Three Days Grace - Time of Dying (lyrics)"
|
title = "Three Days Grace - Time of Dying (lyrics)"
|
||||||
|
@ -87,11 +90,12 @@ async def test_bot_playback(mbot, ctx):
|
||||||
ctx.send.call_args.args == (f"Queued: {title}",), \
|
ctx.send.call_args.args == (f"Queued: {title}",), \
|
||||||
"Did not send 'Queued:' message"
|
"Did not send 'Queued:' message"
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
# Still no playback because previous song not finished
|
# Assert that there is still no playback because previous song is not finished yet
|
||||||
assert \
|
assert \
|
||||||
not ffmpeg_pcm_audio.call_args.args == (url,), \
|
not ffmpeg_pcm_audio.call_args.args == (url,), \
|
||||||
f"FFmpegPCMAudio was called with {url} before previous song finished"
|
f"FFmpegPCMAudio was called with {url} before previous song finished"
|
||||||
ctx.voice_client.play.call_args.kwargs["after"](None) # Execute callback for song finish event
|
# Execute callback for song finish event
|
||||||
|
ctx.voice_client.play.call_args.kwargs["after"](None)
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
assert \
|
assert \
|
||||||
ctx.voice_client.play.call_args.args == (time_of_dying_audio,), \
|
ctx.voice_client.play.call_args.args == (time_of_dying_audio,), \
|
||||||
|
@ -103,6 +107,9 @@ async def test_bot_skip(mbot, ctx):
|
||||||
with patch.object(mbot, '_ytdl') as ytdl:
|
with patch.object(mbot, '_ytdl') as ytdl:
|
||||||
with patch('discord.FFmpegPCMAudio') as ffmpeg_pcm_audio:
|
with patch('discord.FFmpegPCMAudio') as ffmpeg_pcm_audio:
|
||||||
|
|
||||||
|
# TEST: One can skip songs to immediately play the next song in queue
|
||||||
|
|
||||||
|
# Queue first song
|
||||||
ctx.voice_client.is_playing.return_value = False
|
ctx.voice_client.is_playing.return_value = False
|
||||||
url = "https://www.youtube.com/watch?v=Wr9LZ1hAFpQ"
|
url = "https://www.youtube.com/watch?v=Wr9LZ1hAFpQ"
|
||||||
title = "In Flames - Deliver Us (Official Video)"
|
title = "In Flames - Deliver Us (Official Video)"
|
||||||
|
@ -116,6 +123,7 @@ async def test_bot_skip(mbot, ctx):
|
||||||
ctx.voice_client.play.call_args.args == (deliver_us_audio,), \
|
ctx.voice_client.play.call_args.args == (deliver_us_audio,), \
|
||||||
"Did not playback correct audio"
|
"Did not playback correct audio"
|
||||||
|
|
||||||
|
# Queue second song
|
||||||
ctx.voice_client.is_playing.return_value = True
|
ctx.voice_client.is_playing.return_value = True
|
||||||
url = "https://www.youtube.com/watch?v=pMDcYX2wRSg"
|
url = "https://www.youtube.com/watch?v=pMDcYX2wRSg"
|
||||||
title = "Three Days Grace - Time of Dying (lyrics)"
|
title = "Three Days Grace - Time of Dying (lyrics)"
|
||||||
|
@ -129,6 +137,7 @@ async def test_bot_skip(mbot, ctx):
|
||||||
not ctx.voice_client.play.call_args.args == (time_of_dying_audio,), \
|
not ctx.voice_client.play.call_args.args == (time_of_dying_audio,), \
|
||||||
"Did immediately playback audio instead of being queued"
|
"Did immediately playback audio instead of being queued"
|
||||||
|
|
||||||
|
# Now skip first song
|
||||||
await mbot.skip(mbot, ctx)
|
await mbot.skip(mbot, ctx)
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
assert \
|
assert \
|
||||||
|
|
Loading…
Reference in New Issue