>=3.10 strict typing (#765)
* >=3.10 * fully typed (mypy strict mode enabled) * fix tests (get_tasteprofile now requires auth - serverside) * update linters * fix uploads search
This commit is contained in:
parent
03acc6ecff
commit
a979691bb0
47 changed files with 717 additions and 503 deletions
|
|
@ -2,7 +2,6 @@ import json
|
|||
import tempfile
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
|
@ -12,11 +11,12 @@ from ytmusicapi.auth.oauth import OAuthToken
|
|||
from ytmusicapi.auth.types import AuthType
|
||||
from ytmusicapi.exceptions import YTMusicUserError
|
||||
from ytmusicapi.setup import main
|
||||
from ytmusicapi.type_alias import JsonDict
|
||||
from ytmusicapi.ytmusic import OAuthCredentials, YTMusic
|
||||
|
||||
|
||||
@pytest.fixture(name="blank_code")
|
||||
def fixture_blank_code() -> dict[str, Any]:
|
||||
def fixture_blank_code() -> JsonDict:
|
||||
return {
|
||||
"device_code": "",
|
||||
"user_code": "",
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ class TestBrowsing:
|
|||
|
||||
def test_get_album_browse_id_issue_470(self, yt):
|
||||
escaped_browse_id = yt.get_album_browse_id("OLAK5uy_nbMYyrfeg5ZgknoOsOGBL268hGxtcbnDM")
|
||||
assert escaped_browse_id == "MPREb_scJdtUCpPE2"
|
||||
assert escaped_browse_id == "MPREb_pZhPA6GfQmN"
|
||||
|
||||
def test_get_album_2024(self, yt):
|
||||
with open(Path(__file__).parent.parent / "data" / "2024_03_get_album.json", encoding="utf8") as f:
|
||||
|
|
@ -204,21 +204,13 @@ class TestBrowsing:
|
|||
signature_timestamp = yt.get_signatureTimestamp()
|
||||
assert signature_timestamp is not None
|
||||
|
||||
def test_set_tasteprofile(self, yt, yt_brand):
|
||||
with pytest.raises(Exception):
|
||||
yt.set_tasteprofile(["not an artist"])
|
||||
taste_profile = yt.get_tasteprofile()
|
||||
assert yt.set_tasteprofile(list(taste_profile)[:5], taste_profile) is None
|
||||
|
||||
def test_set_tasteprofile(self, yt_brand):
|
||||
with pytest.raises(Exception):
|
||||
yt_brand.set_tasteprofile(["test", "test2"])
|
||||
taste_profile = yt_brand.get_tasteprofile()
|
||||
assert yt_brand.set_tasteprofile(list(taste_profile)[:1], taste_profile) is None
|
||||
|
||||
def test_get_tasteprofile(self, yt, yt_oauth):
|
||||
result = yt.get_tasteprofile()
|
||||
assert len(result) >= 0
|
||||
|
||||
result = yt_oauth.get_tasteprofile()
|
||||
assert len(result) >= 0
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ from urllib.parse import urlparse
|
|||
|
||||
import pytest
|
||||
|
||||
from ytmusicapi.exceptions import YTMusicUserError
|
||||
|
||||
|
||||
class TestLibrary:
|
||||
def test_get_library_playlists(self, config, yt_oauth, yt_empty):
|
||||
|
|
@ -111,8 +113,8 @@ class TestLibrary:
|
|||
assert "actions" in response
|
||||
response = yt_auth.rate_song(sample_video, "INDIFFERENT")
|
||||
assert response
|
||||
response = yt_auth.rate_song(sample_video, "notexist")
|
||||
assert not response
|
||||
with pytest.raises(YTMusicUserError):
|
||||
yt_auth.rate_song(sample_video, "notexist")
|
||||
|
||||
@pytest.mark.skip(reason="edit_song_library_status is currently broken due to server-side update")
|
||||
def test_edit_song_library_status(self, yt_brand, sample_album):
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from ytmusicapi import YTMusic
|
||||
|
|
@ -51,7 +53,7 @@ class TestSearch:
|
|||
),
|
||||
],
|
||||
)
|
||||
def test_search_album_artists(self, yt, case: tuple[str, dict]):
|
||||
def test_search_album_artists(self, yt, case: tuple[str, dict[str, Any]]):
|
||||
(query, expected) = case
|
||||
results = yt.search(query, filter="albums")
|
||||
|
||||
|
|
@ -125,6 +127,9 @@ class TestSearch:
|
|||
)
|
||||
results = yt_oauth.search(config["queries"]["uploads_songs"], scope="uploads", limit=40)
|
||||
assert len(results) > 20
|
||||
assert all(isinstance(item["title"], str) for item in results)
|
||||
assert all(item.get("browseId", None) or item.get("videoId", None) for item in results)
|
||||
assert all(len(item["thumbnails"]) >= 2 for item in results)
|
||||
|
||||
def test_search_library(self, config, yt_oauth):
|
||||
results = yt_oauth.search(config["queries"]["library_any"], scope="library")
|
||||
|
|
|
|||
Loading…
Reference in a new issue