Skip to content

Commit

Permalink
Merge pull request #45 from dotX12/dev-issues-35-about_artists
Browse files Browse the repository at this point in the history
Fix and added new tests
  • Loading branch information
dotX12 authored Dec 19, 2022
2 parents 29eeb44 + 84bc1e7 commit 6ed6f88
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import pytest_asyncio


@pytest_asyncio.fixture(scope="session")
@pytest_asyncio.fixture(scope="session", autouse=True)
def event_loop():
loop = asyncio.new_event_loop()
loop = asyncio.get_event_loop_policy().get_event_loop()
yield loop
loop.run_until_complete(asyncio.sleep(1))
loop.run_until_complete(asyncio.sleep(0.025))
loop.close()
2 changes: 2 additions & 0 deletions tests/test_21_issue.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
import pytest_asyncio

from shazamio import Serialize
Expand Down Expand Up @@ -250,6 +251,7 @@ def song_response():
yield response


@pytest.mark.asyncio
async def test_recognize_song_bug(song_response: bytes):
serialize_out = Serialize.full_track(data=song_response)
assert serialize_out.matches[0].channel is None
33 changes: 33 additions & 0 deletions tests/test_about_artist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest

from shazamio import Serialize
from shazamio import Shazam
from shazamio.schemas.artists import ArtistQuery
from shazamio.schemas.enums import ArtistExtend
from shazamio.schemas.enums import ArtistView


@pytest.mark.asyncio
async def test_about_artist():
shazam = Shazam(language="ES")
artist_id = 659860538

about_artist = await shazam.artist_about(
artist_id,
query=ArtistQuery(
views=[
ArtistView.FULL_ALBUMS,
ArtistView.LATEST_RELEASE,
],
extend=[
ArtistExtend.ARTIST_BIO,
ArtistExtend.BORN_OF_FORMED,
ArtistExtend.EDITORIAL_ARTWORK,
ArtistExtend.ORIGIN,
],
),
)

serialized = Serialize.artist_v2(about_artist)
assert serialized.data[0].attributes.name == "Markul"
assert "Hip-hop/Rap" in serialized.data[0].attributes.genre_names
2 changes: 2 additions & 0 deletions tests/test_peak_spreading_numpy.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from pydub import AudioSegment
from typing import List

Expand Down Expand Up @@ -35,6 +36,7 @@ def do_peak_spreading_non_numpy(self):
pass


@pytest.mark.asyncio
async def test_do_peak_spreading_numpy():
audio = AudioSegment.from_file(file="examples/data/dora.ogg")

Expand Down
4 changes: 4 additions & 0 deletions tests/test_recognize.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
import pytest_asyncio
from pydub import AudioSegment
from io import BytesIO
Expand All @@ -11,6 +12,7 @@ async def song_bytes():
yield await get_file_bytes(file="examples/data/dora.ogg")


@pytest.mark.asyncio
async def test_recognize_song_file():
shazam = Shazam()
out = await shazam.recognize_song(data="examples/data/dora.ogg")
Expand All @@ -19,6 +21,7 @@ async def test_recognize_song_file():
assert out["track"]["key"] == "549679333"


@pytest.mark.asyncio
async def test_recognize_song_bytes(song_bytes: bytes):
shazam = Shazam()
out = await shazam.recognize_song(data=song_bytes)
Expand All @@ -27,6 +30,7 @@ async def test_recognize_song_bytes(song_bytes: bytes):
assert out["track"]["key"] == "549679333"


@pytest.mark.asyncio
async def test_recognize_song_too_short():
short_audio_segment = AudioSegment.from_file(
file=BytesIO(b"0" * 126),
Expand Down

0 comments on commit 6ed6f88

Please sign in to comment.