From b23bcbf1b1767c4c37b22d3d5a27d0ea4c75113b Mon Sep 17 00:00:00 2001 From: dotX12 Date: Sun, 18 Feb 2024 21:48:57 +0300 Subject: [PATCH] Fix pytest --- .github/workflows/pytest.yml | 2 +- shazamio/api.py | 6 +++--- shazamio/client.py | 4 ++-- shazamio/converter.py | 6 +++--- shazamio/interfaces/client.py | 4 ++-- shazamio/signature.py | 34 ---------------------------------- 6 files changed, 11 insertions(+), 45 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 1841999..82c11dc 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -63,4 +63,4 @@ jobs: - name: Run tests run: | source .venv/bin/activate - pytest tests/ \ No newline at end of file + poetry run pytest \ No newline at end of file diff --git a/shazamio/api.py b/shazamio/api.py index 2416e5c..82dfc05 100644 --- a/shazamio/api.py +++ b/shazamio/api.py @@ -1,7 +1,7 @@ import pathlib import time import uuid -from typing import Dict, Any, Union +from typing import Dict, Any, Union, List from typing import Optional from aiohttp_retry import ExponentialRetry @@ -401,9 +401,9 @@ async def listening_counter( async def listening_counter_many( self, - track_ids: list[int], + track_ids: List[int], proxy: Optional[str] = None, - ) -> list[dict[str, Any]]: + ) -> List[Dict[str, Any]]: """ Returns the total track listener counter. :param track_ids: Track numbers (list). Example: ([559284007]) diff --git a/shazamio/client.py b/shazamio/client.py index dcc3867..0925103 100644 --- a/shazamio/client.py +++ b/shazamio/client.py @@ -1,5 +1,5 @@ from types import SimpleNamespace -from typing import Any, Optional +from typing import Any, Optional, List, Dict, Union from aiohttp import ClientSession, TraceRequestStartParams, TraceConfig from aiohttp_retry import RetryClient, RetryOptionsBase @@ -40,7 +40,7 @@ async def request( url: str, *args, **kwargs, - ) -> list[Any] | dict[str, Any]: + ) -> Union[List[Any], Dict[str, Any]]: async with RetryClient( retry_options=self.retry_options, raise_for_status=False, diff --git a/shazamio/converter.py b/shazamio/converter.py index e8a70a7..a748de3 100644 --- a/shazamio/converter.py +++ b/shazamio/converter.py @@ -1,4 +1,4 @@ -from typing import Any +from typing import Any, Dict from pydub import AudioSegment from shazamio.algorithm import SignatureGenerator @@ -29,7 +29,7 @@ async def city_id_from(self, country: Union[CountryCode, str], city: str) -> int return response_city["id"] raise BadCityName("City not found, check city name") - async def all_cities_from_country(self, country: Union[CountryCode, str]) -> list[str]: + async def all_cities_from_country(self, country: Union[CountryCode, str]) -> List[str]: cities = [] data = await self.client.request("GET", ShazamUrl.LOCATIONS, "application/json") for response_country in data["countries"]: @@ -42,7 +42,7 @@ async def all_cities_from_country(self, country: Union[CountryCode, str]) -> lis class Converter: @staticmethod - def data_search(timezone: str, uri: str, samplems: int, timestamp: int) -> dict[str, Any]: + def data_search(timezone: str, uri: str, samplems: int, timestamp: int) -> Dict[str, Any]: return { "timezone": timezone, "signature": {"uri": uri, "samplems": samplems}, diff --git a/shazamio/interfaces/client.py b/shazamio/interfaces/client.py index 6a2dc51..61aa1d9 100644 --- a/shazamio/interfaces/client.py +++ b/shazamio/interfaces/client.py @@ -1,5 +1,5 @@ from abc import ABC, abstractmethod -from typing import Any +from typing import Any, List, Dict, Union class HTTPClientInterface(ABC): @@ -10,5 +10,5 @@ async def request( url: str, *args, **kwargs, - ) -> list[Any] | dict[str, Any]: + ) -> Union[List[Any], Dict[str, Any]]: raise NotImplementedError diff --git a/shazamio/signature.py b/shazamio/signature.py index fc3cf95..879c773 100644 --- a/shazamio/signature.py +++ b/shazamio/signature.py @@ -164,40 +164,6 @@ def decode_from_binary(cls, data: bytes): return self - @classmethod - def decode_from_uri(cls, uri: str): - assert uri.startswith(DATA_URI_PREFIX) - - return cls.decode_from_binary(b64decode(uri.replace(DATA_URI_PREFIX, "", 1))) - - """ - Encode the current object to a readable JSON format, for debugging - purposes. - """ - - def encode_to_json(self) -> dict: - return { - "sample_rate_hz": self.sample_rate_hz, - "number_samples": self.number_samples, - "_seconds": self.number_samples / self.sample_rate_hz, - "frequency_band_to_peaks": { - frequency_band.name.strip("_"): [ - { - "fft_pass_number": frequency_peak.fft_pass_number, - "peak_magnitude": frequency_peak.peak_magnitude, - "corrected_peak_frequency_bin": frequency_peak.corrected_peak_frequency_bin, - "_frequency_hz": frequency_peak.get_frequency_hz(), - "_amplitude_pcm": frequency_peak.get_amplitude_pcm(), - "_seconds": frequency_peak.get_seconds(), - } - for frequency_peak in frequency_peaks - ] - for frequency_band, frequency_peaks in sorted( - self.frequency_band_to_sound_peaks.items() - ) - }, - } - def encode_to_binary(self) -> bytes: header = RawSignatureHeader()