mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
Remove some lint exclusions and fix the issues
* Replace `noqa` comments in `assert...` method definitions with a configuration option to ignore these names. * Use the `__all__` variable to specify importable items from the module, replacing `*` imports and `noqa` comments for unused imports. * Address issues with poorly named variables and methods by renaming them appropriately.
This commit is contained in:
parent
f36bc497c8
commit
5f78d1b82b
15 changed files with 92 additions and 58 deletions
|
|
@ -371,7 +371,7 @@ class Distance:
|
|||
self.tracks: Dict[TrackInfo, Distance] = {}
|
||||
|
||||
@cached_classproperty
|
||||
def _weights(cls) -> Dict[str, float]: # noqa: N805
|
||||
def _weights(cls) -> Dict[str, float]:
|
||||
"""A dictionary from keys to floating-point weights."""
|
||||
weights_view = config["match"]["distance_weights"]
|
||||
weights = {}
|
||||
|
|
|
|||
|
|
@ -32,4 +32,18 @@ from .queryparse import (
|
|||
)
|
||||
from .types import Type
|
||||
|
||||
# flake8: noqa
|
||||
__all__ = [
|
||||
"AndQuery",
|
||||
"Database",
|
||||
"FieldQuery",
|
||||
"InvalidQueryError",
|
||||
"MatchQuery",
|
||||
"Model",
|
||||
"OrQuery",
|
||||
"Query",
|
||||
"Results",
|
||||
"Type",
|
||||
"parse_sorted_query",
|
||||
"query_from_strings",
|
||||
"sort_from_strings",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -20,9 +20,34 @@ use {}-style formatting and can interpolate keywords arguments to the logging
|
|||
calls (`debug`, `info`, etc).
|
||||
"""
|
||||
|
||||
import logging
|
||||
import threading
|
||||
from copy import copy
|
||||
from logging import (
|
||||
DEBUG,
|
||||
INFO,
|
||||
NOTSET,
|
||||
WARNING,
|
||||
FileHandler,
|
||||
Filter,
|
||||
Handler,
|
||||
Logger,
|
||||
NullHandler,
|
||||
StreamHandler,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"DEBUG",
|
||||
"INFO",
|
||||
"NOTSET",
|
||||
"WARNING",
|
||||
"FileHandler",
|
||||
"Filter",
|
||||
"Handler",
|
||||
"Logger",
|
||||
"NullHandler",
|
||||
"StreamHandler",
|
||||
"getLogger",
|
||||
]
|
||||
|
||||
|
||||
def logsafe(val):
|
||||
|
|
@ -45,7 +70,7 @@ def logsafe(val):
|
|||
return val
|
||||
|
||||
|
||||
class StrFormatLogger(logging.Logger):
|
||||
class StrFormatLogger(Logger):
|
||||
"""A version of `Logger` that uses `str.format`-style formatting
|
||||
instead of %-style formatting and supports keyword arguments.
|
||||
|
||||
|
|
@ -95,12 +120,12 @@ class StrFormatLogger(logging.Logger):
|
|||
)
|
||||
|
||||
|
||||
class ThreadLocalLevelLogger(logging.Logger):
|
||||
class ThreadLocalLevelLogger(Logger):
|
||||
"""A version of `Logger` whose level is thread-local instead of shared."""
|
||||
|
||||
def __init__(self, name, level=logging.NOTSET):
|
||||
def __init__(self, name, level=NOTSET):
|
||||
self._thread_level = threading.local()
|
||||
self.default_level = logging.NOTSET
|
||||
self.default_level = NOTSET
|
||||
super().__init__(name, level)
|
||||
|
||||
@property
|
||||
|
|
@ -127,17 +152,13 @@ class BeetsLogger(ThreadLocalLevelLogger, StrFormatLogger):
|
|||
pass
|
||||
|
||||
|
||||
my_manager = copy(logging.Logger.manager)
|
||||
my_manager = copy(Logger.manager)
|
||||
my_manager.loggerClass = BeetsLogger
|
||||
|
||||
|
||||
# Act like the stdlib logging module by re-exporting its namespace.
|
||||
from logging import * # noqa
|
||||
|
||||
|
||||
# Override the `getLogger` to use our machinery.
|
||||
def getLogger(name=None): # noqa
|
||||
if name:
|
||||
return my_manager.getLogger(name)
|
||||
else:
|
||||
return logging.Logger.root
|
||||
return Logger.root
|
||||
|
|
|
|||
|
|
@ -143,19 +143,19 @@ def import_session(lib=None, loghandler=None, paths=[], query=[], cli=False):
|
|||
class Assertions:
|
||||
"""A mixin with additional unit test assertions."""
|
||||
|
||||
def assertExists(self, path): # noqa
|
||||
def assertExists(self, path):
|
||||
assert os.path.exists(syspath(path)), f"file does not exist: {path!r}"
|
||||
|
||||
def assertNotExists(self, path): # noqa
|
||||
def assertNotExists(self, path):
|
||||
assert not os.path.exists(syspath(path)), f"file exists: {path!r}"
|
||||
|
||||
def assertIsFile(self, path): # noqa
|
||||
def assertIsFile(self, path):
|
||||
self.assertExists(path)
|
||||
assert os.path.isfile(
|
||||
syspath(path)
|
||||
), "path exists, but is not a regular file: {!r}".format(path)
|
||||
|
||||
def assertIsDir(self, path): # noqa
|
||||
def assertIsDir(self, path):
|
||||
self.assertExists(path)
|
||||
assert os.path.isdir(
|
||||
syspath(path)
|
||||
|
|
|
|||
|
|
@ -1069,7 +1069,7 @@ def par_map(transform: Callable[[T], Any], items: Sequence[T]) -> None:
|
|||
pool.join()
|
||||
|
||||
|
||||
class cached_classproperty: # noqa: N801
|
||||
class cached_classproperty:
|
||||
"""A decorator implementing a read-only property that is *lazy* in
|
||||
the sense that the getter is only invoked once. Subsequent accesses
|
||||
through *any* instance use the cached result.
|
||||
|
|
|
|||
|
|
@ -738,13 +738,13 @@ class BaseServer:
|
|||
|
||||
# Additions to the MPD protocol.
|
||||
|
||||
def cmd_crash_TypeError(self, conn): # noqa: N802
|
||||
def cmd_crash(self, conn):
|
||||
"""Deliberately trigger a TypeError for testing purposes.
|
||||
We want to test that the server properly responds with ERROR_SYSTEM
|
||||
without crashing, and that this is not treated as ERROR_ARG (since it
|
||||
is caused by a programming error, not a protocol error).
|
||||
"""
|
||||
"a" + 2
|
||||
raise TypeError
|
||||
|
||||
|
||||
class Connection:
|
||||
|
|
|
|||
|
|
@ -260,3 +260,4 @@ ignore-variadic-names = true
|
|||
|
||||
[tool.ruff.lint.pep8-naming]
|
||||
classmethod-decorators = ["cached_classproperty"]
|
||||
extend-ignore-names = ["assert*", "cached_classproperty"]
|
||||
|
|
|
|||
|
|
@ -865,7 +865,7 @@ class ArtForAlbumTest(UseThePlugin):
|
|||
fetchart.FileSystem.get = self.old_fs_source_get
|
||||
super().tearDown()
|
||||
|
||||
def _assertImageIsValidArt(self, image_file, should_exist): # noqa
|
||||
def assertImageIsValidArt(self, image_file, should_exist):
|
||||
self.assertExists(image_file)
|
||||
self.image_file = image_file
|
||||
|
||||
|
|
@ -896,42 +896,42 @@ class ArtForAlbumTest(UseThePlugin):
|
|||
def test_respect_minwidth(self):
|
||||
self._require_backend()
|
||||
self.plugin.minwidth = 300
|
||||
self._assertImageIsValidArt(self.IMG_225x225, False)
|
||||
self._assertImageIsValidArt(self.IMG_348x348, True)
|
||||
self.assertImageIsValidArt(self.IMG_225x225, False)
|
||||
self.assertImageIsValidArt(self.IMG_348x348, True)
|
||||
|
||||
def test_respect_enforce_ratio_yes(self):
|
||||
self._require_backend()
|
||||
self.plugin.enforce_ratio = True
|
||||
self._assertImageIsValidArt(self.IMG_500x490, False)
|
||||
self._assertImageIsValidArt(self.IMG_225x225, True)
|
||||
self.assertImageIsValidArt(self.IMG_500x490, False)
|
||||
self.assertImageIsValidArt(self.IMG_225x225, True)
|
||||
|
||||
def test_respect_enforce_ratio_no(self):
|
||||
self.plugin.enforce_ratio = False
|
||||
self._assertImageIsValidArt(self.IMG_500x490, True)
|
||||
self.assertImageIsValidArt(self.IMG_500x490, True)
|
||||
|
||||
def test_respect_enforce_ratio_px_above(self):
|
||||
self._require_backend()
|
||||
self.plugin.enforce_ratio = True
|
||||
self.plugin.margin_px = 5
|
||||
self._assertImageIsValidArt(self.IMG_500x490, False)
|
||||
self.assertImageIsValidArt(self.IMG_500x490, False)
|
||||
|
||||
def test_respect_enforce_ratio_px_below(self):
|
||||
self._require_backend()
|
||||
self.plugin.enforce_ratio = True
|
||||
self.plugin.margin_px = 15
|
||||
self._assertImageIsValidArt(self.IMG_500x490, True)
|
||||
self.assertImageIsValidArt(self.IMG_500x490, True)
|
||||
|
||||
def test_respect_enforce_ratio_percent_above(self):
|
||||
self._require_backend()
|
||||
self.plugin.enforce_ratio = True
|
||||
self.plugin.margin_percent = (500 - 490) / 500 * 0.5
|
||||
self._assertImageIsValidArt(self.IMG_500x490, False)
|
||||
self.assertImageIsValidArt(self.IMG_500x490, False)
|
||||
|
||||
def test_respect_enforce_ratio_percent_below(self):
|
||||
self._require_backend()
|
||||
self.plugin.enforce_ratio = True
|
||||
self.plugin.margin_percent = (500 - 490) / 500 * 1.5
|
||||
self._assertImageIsValidArt(self.IMG_500x490, True)
|
||||
self.assertImageIsValidArt(self.IMG_500x490, True)
|
||||
|
||||
def test_resize_if_necessary(self):
|
||||
self._require_backend()
|
||||
|
|
@ -948,7 +948,7 @@ class ArtForAlbumTest(UseThePlugin):
|
|||
self._require_backend()
|
||||
self.plugin.max_filesize = self.IMG_225x225_SIZE
|
||||
self._assert_image_operated(self.IMG_225x225, self.RESIZE_OP, False)
|
||||
self._assertImageIsValidArt(self.IMG_225x225, True)
|
||||
self.assertImageIsValidArt(self.IMG_225x225, True)
|
||||
|
||||
def test_fileresize_no_scale(self):
|
||||
self._require_backend()
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class ConvertMixin:
|
|||
shell_quote(sys.executable), shell_quote(stub), tag
|
||||
)
|
||||
|
||||
def assertFileTag(self, path, tag): # noqa
|
||||
def assertFileTag(self, path, tag):
|
||||
"""Assert that the path is a file and the files content ends
|
||||
with `tag`.
|
||||
"""
|
||||
|
|
@ -68,7 +68,7 @@ class ConvertMixin:
|
|||
f.read() == tag
|
||||
), f"{displayable_path(path)} is not tagged with {display_tag}"
|
||||
|
||||
def assertNoFileTag(self, path, tag): # noqa
|
||||
def assertNoFileTag(self, path, tag):
|
||||
"""Assert that the path is a file and the files content does not
|
||||
end with `tag`.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ class EditMixin(PluginMixin):
|
|||
|
||||
plugin = "edit"
|
||||
|
||||
def assertItemFieldsModified( # noqa
|
||||
def assertItemFieldsModified(
|
||||
self, library_items, items, fields=[], allowed=["path"]
|
||||
):
|
||||
"""Assert that items in the library (`lib_items`) have different values
|
||||
|
|
@ -134,7 +134,7 @@ class EditCommandTest(EditMixin, BeetsTestCase):
|
|||
{f: item[f] for f in item._fields} for item in self.album.items()
|
||||
]
|
||||
|
||||
def assertCounts( # noqa
|
||||
def assertCounts(
|
||||
self,
|
||||
mock_write,
|
||||
album_count=ALBUM_COUNT,
|
||||
|
|
|
|||
|
|
@ -74,11 +74,11 @@ class ImportAddedTest(PluginMixin, ImportTestCase):
|
|||
"No MediaFile found for Item " + displayable_path(item.path)
|
||||
)
|
||||
|
||||
def assertEqualTimes(self, first, second, msg=None): # noqa
|
||||
def assertEqualTimes(self, first, second, msg=None):
|
||||
"""For comparing file modification times at a sufficient precision"""
|
||||
assert first == pytest.approx(second, rel=1e-4), msg
|
||||
|
||||
def assertAlbumImport(self): # noqa
|
||||
def assertAlbumImport(self):
|
||||
self.importer.run()
|
||||
album = self.lib.albums().get()
|
||||
assert album.added == self.min_mtime
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class PermissionsPluginTest(AsIsImporterMixin, PluginMixin, ImportTestCase):
|
|||
for path in dirs_in_library(self.lib.directory, item.path):
|
||||
self.assertPerms(path, "dir", expect_success)
|
||||
|
||||
def assertPerms(self, path, typ, expect_success): # noqa
|
||||
def assertPerms(self, path, typ, expect_success):
|
||||
for x in [
|
||||
(True, self.exp_perms[expect_success][typ], "!="),
|
||||
(False, self.exp_perms[not expect_success][typ], "=="),
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ gstplayer = importlib.util.module_from_spec(
|
|||
)
|
||||
|
||||
|
||||
def _gstplayer_play(*_): # noqa: 42
|
||||
def _gstplayer_play(*_):
|
||||
bpd.gstplayer._GstPlayer.playing = True
|
||||
return mock.DEFAULT
|
||||
|
||||
|
|
@ -242,7 +242,7 @@ class MPCClient:
|
|||
return line
|
||||
|
||||
|
||||
def implements(commands, expectedFailure=False): # noqa: N803
|
||||
def implements(commands, fail=False):
|
||||
def _test(self):
|
||||
with self.run_bpd() as client:
|
||||
response = client.send_command("commands")
|
||||
|
|
@ -250,7 +250,7 @@ def implements(commands, expectedFailure=False): # noqa: N803
|
|||
implemented = response.data["command"]
|
||||
assert commands.intersection(implemented) == commands
|
||||
|
||||
return unittest.expectedFailure(_test) if expectedFailure else _test
|
||||
return unittest.expectedFailure(_test) if fail else _test
|
||||
|
||||
|
||||
bluelet_listener = bluelet.Listener
|
||||
|
|
@ -437,7 +437,7 @@ class BPDTest(BPDTestHelper):
|
|||
|
||||
def test_system_error(self):
|
||||
with self.run_bpd() as client:
|
||||
response = client.send_command("crash_TypeError")
|
||||
response = client.send_command("crash")
|
||||
self._assert_failed(response, bpd.ERROR_SYSTEM)
|
||||
|
||||
def test_empty_request(self):
|
||||
|
|
@ -763,7 +763,7 @@ class BPDControlTest(BPDTestHelper):
|
|||
"seekid",
|
||||
"seekcur",
|
||||
},
|
||||
expectedFailure=True,
|
||||
fail=True,
|
||||
)
|
||||
|
||||
def test_cmd_play(self):
|
||||
|
|
@ -873,7 +873,7 @@ class BPDQueueTest(BPDTestHelper):
|
|||
"addtagid",
|
||||
"cleartagid",
|
||||
},
|
||||
expectedFailure=True,
|
||||
fail=True,
|
||||
)
|
||||
|
||||
METADATA = {"Pos", "Time", "Id", "file", "duration"}
|
||||
|
|
@ -990,7 +990,7 @@ class BPDDatabaseTest(BPDTestHelper):
|
|||
"update",
|
||||
"rescan",
|
||||
},
|
||||
expectedFailure=True,
|
||||
fail=True,
|
||||
)
|
||||
|
||||
def test_cmd_search(self):
|
||||
|
|
@ -1050,7 +1050,7 @@ class BPDMountsTest(BPDTestHelper):
|
|||
"listmounts",
|
||||
"listneighbors",
|
||||
},
|
||||
expectedFailure=True,
|
||||
fail=True,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -1059,7 +1059,7 @@ class BPDStickerTest(BPDTestHelper):
|
|||
{
|
||||
"sticker",
|
||||
},
|
||||
expectedFailure=True,
|
||||
fail=True,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -1142,7 +1142,7 @@ class BPDPartitionTest(BPDTestHelper):
|
|||
"listpartitions",
|
||||
"newpartition",
|
||||
},
|
||||
expectedFailure=True,
|
||||
fail=True,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -1154,7 +1154,7 @@ class BPDDeviceTest(BPDTestHelper):
|
|||
"toggleoutput",
|
||||
"outputs",
|
||||
},
|
||||
expectedFailure=True,
|
||||
fail=True,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -1166,7 +1166,7 @@ class BPDReflectionTest(BPDTestHelper):
|
|||
"notcommands",
|
||||
"urlhandlers",
|
||||
},
|
||||
expectedFailure=True,
|
||||
fail=True,
|
||||
)
|
||||
|
||||
def test_cmd_decoders(self):
|
||||
|
|
@ -1187,5 +1187,5 @@ class BPDPeersTest(BPDTestHelper):
|
|||
"readmessages",
|
||||
"sendmessage",
|
||||
},
|
||||
expectedFailure=True,
|
||||
fail=True,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -133,16 +133,14 @@ class DateIntervalTest(unittest.TestCase):
|
|||
self.assertContains("..", date=datetime.min)
|
||||
self.assertContains("..", "1000-01-01T00:00:00")
|
||||
|
||||
def assertContains( # noqa
|
||||
self, interval_pattern, date_pattern=None, date=None
|
||||
):
|
||||
def assertContains(self, interval_pattern, date_pattern=None, date=None):
|
||||
if date is None:
|
||||
date = _date(date_pattern)
|
||||
(start, end) = _parse_periods(interval_pattern)
|
||||
interval = DateInterval.from_periods(start, end)
|
||||
assert interval.contains(date)
|
||||
|
||||
def assertExcludes(self, interval_pattern, date_pattern): # noqa
|
||||
def assertExcludes(self, interval_pattern, date_pattern):
|
||||
date = _date(date_pattern)
|
||||
(start, end) = _parse_periods(interval_pattern)
|
||||
interval = DateInterval.from_periods(start, end)
|
||||
|
|
|
|||
|
|
@ -47,11 +47,11 @@ class AssertsMixin:
|
|||
def assert_albums_matched(self, results, albums):
|
||||
assert {a.album for a in results} == set(albums)
|
||||
|
||||
def assertInResult(self, item, results): # noqa
|
||||
def assertInResult(self, item, results):
|
||||
result_ids = [i.id for i in results]
|
||||
assert item.id in result_ids
|
||||
|
||||
def assertNotInResult(self, item, results): # noqa
|
||||
def assertNotInResult(self, item, results):
|
||||
result_ids = [i.id for i in results]
|
||||
assert item.id not in result_ids
|
||||
|
||||
|
|
@ -927,7 +927,7 @@ class NotQueryTest(DummyDataTestCase):
|
|||
- `test_get_yyy`: tests on query strings (similar to `GetTest`)
|
||||
"""
|
||||
|
||||
def assertNegationProperties(self, q): # noqa
|
||||
def assertNegationProperties(self, q):
|
||||
"""Given a Query `q`, assert that:
|
||||
- q OR not(q) == all items
|
||||
- q AND not(q) == 0
|
||||
|
|
|
|||
Loading…
Reference in a new issue