Skip to content

Commit

Permalink
Fix pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
dotX12 committed Feb 18, 2024
1 parent 67808f7 commit b23bcbf
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ jobs:
- name: Run tests
run: |
source .venv/bin/activate
pytest tests/
poetry run pytest
6 changes: 3 additions & 3 deletions shazamio/api.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions shazamio/client.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions shazamio/converter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any
from typing import Any, Dict

from pydub import AudioSegment
from shazamio.algorithm import SignatureGenerator
Expand Down Expand Up @@ -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"]:
Expand All @@ -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},
Expand Down
4 changes: 2 additions & 2 deletions shazamio/interfaces/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from abc import ABC, abstractmethod
from typing import Any
from typing import Any, List, Dict, Union


class HTTPClientInterface(ABC):
Expand All @@ -10,5 +10,5 @@ async def request(
url: str,
*args,
**kwargs,
) -> list[Any] | dict[str, Any]:
) -> Union[List[Any], Dict[str, Any]]:
raise NotImplementedError
34 changes: 0 additions & 34 deletions shazamio/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit b23bcbf

Please sign in to comment.