search: fix #569 (#581)

* search: fix #569

* fix an issue with localized instances

* add test for localized search
This commit is contained in:
sigma67 2024-05-09 21:23:19 +02:00 • committed by GitHub
commit 614999c77d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 61 additions and 27 deletions

View file

@ -1,5 +1,8 @@
import pytest
from ytmusicapi import YTMusic
from ytmusicapi.parsers.search import ALL_RESULT_TYPES
class TestSearch:
def test_search_exceptions(self, yt_auth):
@ -14,13 +17,30 @@ class TestSearch:
results = yt_brand.search(query)
assert ["resultType" in r for r in results] == [True] * len(results)
assert len(results) >= 10
assert not any(
artist["name"].lower() in ALL_RESULT_TYPES
for result in results
if "artists" in result
for artist in result["artists"]
)
results = yt.search(query)
assert len(results) >= 10
assert not any(
artist["name"].lower() in ALL_RESULT_TYPES
for result in results
if "artists" in result
for artist in result["artists"]
)
def test_search_ignore_spelling(self, yt_auth):
results = yt_auth.search("Martin Stig Andersen - Deteriation", ignore_spelling=True)
assert len(results) > 0
def test_search_localized(self):
yt_local = YTMusic(language="it")
results = yt_local.search("ABBA")
assert all(result["resultType"] in ALL_RESULT_TYPES for result in results)
def test_search_filters(self, yt_auth):
query = "hip hop playlist"
results = yt_auth.search(query, filter="songs")