From 54d05e1330abfc6f521853cc0204d9995150e9af Mon Sep 17 00:00:00 2001 From: Nathan Thomas Date: Tue, 14 May 2024 16:27:41 -0700 Subject: [PATCH] Fix lints in tests (#682) * Fix lints on tests * Formatting * Formatting --- streamrip/converter.py | 12 ++++++--- streamrip/metadata/__init__.py | 1 + tests/fixtures/clients.py | 2 +- tests/fixtures/util.py | 6 ++--- tests/test_config.py | 46 ++++++++++++++++----------------- tests/test_config_toml_match.py | 3 ++- tests/test_meta.py | 4 +-- tests/test_tagger.py | 9 ++++++- tests/test_track.py | 11 -------- tests/util.py | 6 ++--- 10 files changed, 50 insertions(+), 50 deletions(-) diff --git a/streamrip/converter.py b/streamrip/converter.py index 29efd16..aa4aa2a 100644 --- a/streamrip/converter.py +++ b/streamrip/converter.py @@ -124,10 +124,14 @@ class Converter: aformat = [] if isinstance(self.sampling_rate, int): - sample_rates = "|".join(str(rate) for rate in SAMPLING_RATES if rate <= self.sampling_rate) + sample_rates = "|".join( + str(rate) for rate in SAMPLING_RATES if rate <= self.sampling_rate + ) aformat.append(f"sample_rates={sample_rates}") elif self.sampling_rate is not None: - raise TypeError(f"Sampling rate must be int, not {type(self.sampling_rate)}") + raise TypeError( + f"Sampling rate must be int, not {type(self.sampling_rate)}" + ) if isinstance(self.bit_depth, int): bit_depths = ["s16p", "s16"] @@ -143,9 +147,9 @@ class Converter: raise TypeError(f"Bit depth must be int, not {type(self.bit_depth)}") if aformat: - aformat_params = ':'.join(aformat) + aformat_params = ":".join(aformat) command.extend(["-af", f"aformat={aformat_params}"]) - + # automatically overwrite command.extend(["-y", self.tempfile]) diff --git a/streamrip/metadata/__init__.py b/streamrip/metadata/__init__.py index 71da8a8..88f4d77 100644 --- a/streamrip/metadata/__init__.py +++ b/streamrip/metadata/__init__.py @@ -1,4 +1,5 @@ """Manages the information that will be embeded in the audio file.""" + from . import util from .album import AlbumInfo, AlbumMetadata from .artist import ArtistMetadata diff --git a/tests/fixtures/clients.py b/tests/fixtures/clients.py index cbc1206..9ef2eed 100644 --- a/tests/fixtures/clients.py +++ b/tests/fixtures/clients.py @@ -4,8 +4,8 @@ import os import pytest from util import arun -from streamrip.config import Config from streamrip.client.qobuz import QobuzClient +from streamrip.config import Config @pytest.fixture(scope="session") diff --git a/tests/fixtures/util.py b/tests/fixtures/util.py index 3b1b41a..f4b2f8d 100644 --- a/tests/fixtures/util.py +++ b/tests/fixtures/util.py @@ -9,9 +9,9 @@ def arun(coro): def afor(async_gen): async def _afor(async_gen): - l = [] + item = [] async for item in async_gen: - l.append(item) - return l + item.append(item) + return item return arun(_afor(async_gen)) diff --git a/tests/test_config.py b/tests/test_config.py index f4911ef..23de002 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -4,8 +4,28 @@ import shutil import pytest import tomlkit -from streamrip.config import * -from streamrip.config import _get_dict_keys_r, _nested_set +from streamrip.config import ( + ArtworkConfig, + CliConfig, + Config, + ConfigData, + ConversionConfig, + DatabaseConfig, + DeezerConfig, + DownloadsConfig, + FilepathsConfig, + LastFmConfig, + MetadataConfig, + MiscConfig, + QobuzConfig, + QobuzDiscographyFilterConfig, + SoundcloudConfig, + TidalConfig, + YoutubeConfig, + _get_dict_keys_r, + _nested_set, + update_config, +) SAMPLE_CONFIG = "tests/test_config.toml" OLD_CONFIG = "tests/test_config_old.toml" @@ -242,15 +262,6 @@ def test_sample_config_data_fields(sample_config_data): assert sample_config_data.conversion == test_config.conversion -# def test_config_save_file_called_on_del(sample_config, mocker): -# sample_config.file.set_modified() -# mockf = mocker.Mock() -# -# sample_config.save_file = mockf -# sample_config.__del__() -# mockf.assert_called_once() - - def test_config_update_on_save(): tmp_config_path = "tests/config2.toml" shutil.copy(SAMPLE_CONFIG, tmp_config_path) @@ -264,19 +275,6 @@ def test_config_update_on_save(): assert conf2.session.downloads.folder == "new_folder" -# def test_config_update_on_del(): -# tmp_config_path = "tests/config2.toml" -# shutil.copy(SAMPLE_CONFIG, tmp_config_path) -# conf = Config(tmp_config_path) -# conf.file.downloads.folder = "new_folder" -# conf.file.set_modified() -# del conf -# conf2 = Config(tmp_config_path) -# os.remove(tmp_config_path) -# -# assert conf2.session.downloads.folder == "new_folder" - - def test_config_dont_update_without_set_modified(): tmp_config_path = "tests/config2.toml" shutil.copy(SAMPLE_CONFIG, tmp_config_path) diff --git a/tests/test_config_toml_match.py b/tests/test_config_toml_match.py index 7111bec..2b1c77c 100644 --- a/tests/test_config_toml_match.py +++ b/tests/test_config_toml_match.py @@ -1,7 +1,8 @@ import pytest import tomlkit +from tomlkit.toml_document import TOMLDocument -from streamrip.config import * +from streamrip.config import ConfigData @pytest.fixture() diff --git a/tests/test_meta.py b/tests/test_meta.py index 4516f54..01032ba 100644 --- a/tests/test_meta.py +++ b/tests/test_meta.py @@ -1,6 +1,6 @@ import json -from streamrip.metadata import * +from streamrip.metadata import AlbumMetadata, TrackMetadata with open("tests/qobuz_album_resp.json") as f: qobuz_album_resp = json.load(f) @@ -16,7 +16,7 @@ def test_album_metadata_qobuz(): assert info.quality == 3 assert info.container == "FLAC" assert info.label == "Rhino - Warner Records" - assert info.explicit == False + assert info.explicit is False assert info.sampling_rate == 96 assert info.bit_depth == 24 assert info.booklets is None diff --git a/tests/test_tagger.py b/tests/test_tagger.py index d22be72..1bea481 100644 --- a/tests/test_tagger.py +++ b/tests/test_tagger.py @@ -5,7 +5,14 @@ import pytest from mutagen.flac import FLAC from util import arun -from streamrip.metadata import * +from streamrip.metadata import ( + AlbumInfo, + AlbumMetadata, + Covers, + TrackInfo, + TrackMetadata, + tag_file, +) TEST_FLAC_ORIGINAL = "tests/silence.flac" TEST_FLAC_COPY = "tests/silence_copy.flac" diff --git a/tests/test_track.py b/tests/test_track.py index aed0408..26b168f 100644 --- a/tests/test_track.py +++ b/tests/test_track.py @@ -25,19 +25,8 @@ def test_pending_resolve(qobuz_client: QobuzClient): dir = "tests/tests/Fleetwood Mac - Rumours (1977) [FLAC] [24B-96kHz]" assert os.path.isdir(dir) assert os.path.isfile(os.path.join(dir, "cover.jpg")) - # embedded_cover_path aka t.cover_path is - # ./tests/./tests/Fleetwood Mac - Rumours (1977) [FLAC] [24B-96kHz]/ - # __artwork/cover-9202762427033526105.jpg assert os.path.isfile(t.cover_path) assert isinstance(t, Track) assert isinstance(t.downloadable, Downloadable) assert t.cover_path is not None shutil.rmtree(dir) - - -# def test_pending_resolve_mp3(qobuz_client: QobuzClient): -# qobuz_client.config.session.qobuz.quality = 1 -# p = PendingSingle("19512574", qobuz_client, qobuz_client.config) -# t = arun(p.resolve()) -# assert isinstance(t, Track) -# assert False diff --git a/tests/util.py b/tests/util.py index 3b1b41a..107ecc7 100644 --- a/tests/util.py +++ b/tests/util.py @@ -9,9 +9,9 @@ def arun(coro): def afor(async_gen): async def _afor(async_gen): - l = [] + items = [] async for item in async_gen: - l.append(item) - return l + items.append(item) + return items return arun(_afor(async_gen))