mirror of
https://github.com/beetbox/beets.git
synced 2026-01-03 22:42:44 +01:00
Use f-string syntax
This commit is contained in:
parent
090b62f5b0
commit
4b69b493d2
9 changed files with 26 additions and 55 deletions
|
|
@ -12,8 +12,7 @@
|
|||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
|
||||
"""Tests for the 'beatport' plugin.
|
||||
"""
|
||||
"""Tests for the 'beatport' plugin."""
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
|
|
@ -570,11 +569,7 @@ class BeatportTest(BeetsTestCase):
|
|||
# Concatenate with 'id' to pass strict equality test.
|
||||
for track, test_track, id in zip(self.tracks, self.test_tracks, ids):
|
||||
assert (
|
||||
track.url
|
||||
== "https://beatport.com/track/"
|
||||
+ test_track.url
|
||||
+ "/"
|
||||
+ str(id)
|
||||
track.url == f"https://beatport.com/track/{test_track.url}/{id}"
|
||||
)
|
||||
|
||||
def test_bpm_applied(self):
|
||||
|
|
|
|||
|
|
@ -64,9 +64,9 @@ class ConvertMixin:
|
|||
self.assertIsFile(path)
|
||||
with open(path, "rb") as f:
|
||||
f.seek(-len(display_tag), os.SEEK_END)
|
||||
assert f.read() == tag, "{} is not tagged with {}".format(
|
||||
displayable_path(path), display_tag
|
||||
)
|
||||
assert (
|
||||
f.read() == tag
|
||||
), f"{displayable_path(path)} is not tagged with {display_tag}"
|
||||
|
||||
def assertNoFileTag(self, path, tag): # noqa
|
||||
"""Assert that the path is a file and the files content does not
|
||||
|
|
@ -77,9 +77,9 @@ class ConvertMixin:
|
|||
self.assertIsFile(path)
|
||||
with open(path, "rb") as f:
|
||||
f.seek(-len(tag), os.SEEK_END)
|
||||
assert f.read() != tag, "{} is unexpectedly tagged with {}".format(
|
||||
displayable_path(path), display_tag
|
||||
)
|
||||
assert (
|
||||
f.read() != tag
|
||||
), f"{displayable_path(path)} is unexpectedly tagged with {display_tag}"
|
||||
|
||||
|
||||
class ConvertTestCase(ConvertMixin, PluginTestCase):
|
||||
|
|
@ -123,9 +123,7 @@ class ImportConvertTest(AsIsImporterMixin, ImportHelper, ConvertTestCase):
|
|||
for root, dirnames, filenames in os.walk(path):
|
||||
assert (
|
||||
len(fnmatch.filter(filenames, "*.mp3")) == 0
|
||||
), "Non-empty import directory {}".format(
|
||||
util.displayable_path(path)
|
||||
)
|
||||
), f"Non-empty import directory {util.displayable_path(path)}"
|
||||
|
||||
def get_count_of_import_files(self):
|
||||
import_file_count = 0
|
||||
|
|
|
|||
|
|
@ -155,9 +155,7 @@ class EmbedartCliTest(PluginMixin, FetchImageHelper, BeetsTestCase):
|
|||
|
||||
assert (
|
||||
mediafile.images[0].data == self.image_data
|
||||
), "Image written is not {}".format(
|
||||
displayable_path(self.abbey_artpath)
|
||||
)
|
||||
), f"Image written is not {displayable_path(self.abbey_artpath)}"
|
||||
|
||||
@require_artresizer_compare
|
||||
def test_accept_similar_art(self):
|
||||
|
|
@ -171,9 +169,7 @@ class EmbedartCliTest(PluginMixin, FetchImageHelper, BeetsTestCase):
|
|||
|
||||
assert (
|
||||
mediafile.images[0].data == self.image_data
|
||||
), "Image written is not {}".format(
|
||||
displayable_path(self.abbey_similarpath)
|
||||
)
|
||||
), f"Image written is not {displayable_path(self.abbey_similarpath)}"
|
||||
|
||||
def test_non_ascii_album_path(self):
|
||||
resource_path = os.path.join(_common.RSRC, b"image.mp3")
|
||||
|
|
|
|||
|
|
@ -98,8 +98,7 @@ class PlayPluginTest(CleanupModulesMixin, PluginTestCase):
|
|||
with open(open_mock.call_args[0][0][0], "rb") as f:
|
||||
playlist = f.read().decode("utf-8")
|
||||
assert (
|
||||
"{}\n".format(os.path.dirname(self.item.path.decode("utf-8")))
|
||||
== playlist
|
||||
f'{os.path.dirname(self.item.path.decode("utf-8"))}\n' == playlist
|
||||
)
|
||||
|
||||
def test_raw(self, open_mock):
|
||||
|
|
|
|||
|
|
@ -378,7 +378,7 @@ class BPDTestHelper(PluginTestCase):
|
|||
def _assert_ok(self, *responses):
|
||||
for response in responses:
|
||||
assert response is not None
|
||||
assert response.ok, "Response failed: {}".format(response.err_data)
|
||||
assert response.ok, f"Response failed: {response.err_data}"
|
||||
|
||||
def _assert_failed(self, response, code, pos=None):
|
||||
"""Check that a command failed with a specific error code. If this
|
||||
|
|
|
|||
|
|
@ -98,16 +98,13 @@ class PluralityTest(BeetsTestCase):
|
|||
"media",
|
||||
"albumdisambig",
|
||||
]
|
||||
items = [
|
||||
Item(**{f: "{}_{}".format(f, i or 1) for f in fields})
|
||||
for i in range(5)
|
||||
]
|
||||
items = [Item(**{f: f"{f}_{i or 1}" for f in fields}) for i in range(5)]
|
||||
likelies, _ = match.current_metadata(items)
|
||||
for f in fields:
|
||||
if isinstance(likelies[f], int):
|
||||
assert likelies[f] == 0
|
||||
else:
|
||||
assert likelies[f] == "%s_1" % f
|
||||
assert likelies[f] == f"{f}_1"
|
||||
|
||||
|
||||
def _make_item(title, track, artist="some artist"):
|
||||
|
|
|
|||
|
|
@ -175,11 +175,9 @@ class EventsTest(PluginImportTestCase):
|
|||
|
||||
logs = [line for line in logs if not line.startswith("Sending event:")]
|
||||
assert logs == [
|
||||
"Album: {}".format(
|
||||
displayable_path(os.path.join(self.import_dir, b"album"))
|
||||
),
|
||||
" {}".format(displayable_path(self.import_media[0].path)),
|
||||
" {}".format(displayable_path(self.import_media[1].path)),
|
||||
f'Album: {displayable_path(os.path.join(self.import_dir, b"album"))}',
|
||||
f" {displayable_path(self.import_media[0].path)}",
|
||||
f" {displayable_path(self.import_media[1].path)}",
|
||||
]
|
||||
|
||||
def test_import_task_created_with_plugin(self):
|
||||
|
|
@ -219,8 +217,8 @@ class EventsTest(PluginImportTestCase):
|
|||
|
||||
logs = [line for line in logs if not line.startswith("Sending event:")]
|
||||
assert logs == [
|
||||
"Singleton: {}".format(displayable_path(self.import_media[0].path)),
|
||||
"Singleton: {}".format(displayable_path(self.import_media[1].path)),
|
||||
f"Singleton: {displayable_path(self.import_media[0].path)}",
|
||||
f"Singleton: {displayable_path(self.import_media[1].path)}",
|
||||
]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -690,7 +690,7 @@ class PathQueryTest(ItemInDBTestCase, AssertsMixin):
|
|||
assert is_path_query(parent)
|
||||
|
||||
# Some non-existent path.
|
||||
assert not is_path_query(path_str + "baz")
|
||||
assert not is_path_query(f"{path_str}baz")
|
||||
|
||||
def test_detect_relative_path(self):
|
||||
"""Test detection of implicit path queries based on whether or
|
||||
|
|
|
|||
|
|
@ -53,30 +53,18 @@ class ParseTest(unittest.TestCase):
|
|||
|
||||
def _assert_symbol(self, obj, ident):
|
||||
"""Assert that an object is a Symbol with the given identifier."""
|
||||
assert isinstance(obj, functemplate.Symbol), "not a Symbol: %s" % repr(
|
||||
obj
|
||||
)
|
||||
assert obj.ident == ident, "wrong identifier: %s vs. %s" % (
|
||||
repr(obj.ident),
|
||||
repr(ident),
|
||||
)
|
||||
assert isinstance(obj, functemplate.Symbol), f"not a Symbol: {obj}"
|
||||
assert obj.ident == ident, f"wrong identifier: {obj.ident} vs. {ident}"
|
||||
|
||||
def _assert_call(self, obj, ident, numargs):
|
||||
"""Assert that an object is a Call with the given identifier and
|
||||
argument count.
|
||||
"""
|
||||
assert isinstance(obj, functemplate.Call), "not a Call: %s" % repr(obj)
|
||||
assert obj.ident == ident, "wrong identifier: %s vs. %s" % (
|
||||
repr(obj.ident),
|
||||
repr(ident),
|
||||
)
|
||||
assert isinstance(obj, functemplate.Call), f"not a Call: {obj}"
|
||||
assert obj.ident == ident, f"wrong identifier: {obj.ident} vs. {ident}"
|
||||
assert (
|
||||
len(obj.args) == numargs
|
||||
), "wrong argument count in %s: %i vs. %i" % (
|
||||
repr(obj.ident),
|
||||
len(obj.args),
|
||||
numargs,
|
||||
)
|
||||
), f"wrong argument count in {obj.ident}: {len(obj.args)} vs. {numargs}"
|
||||
|
||||
def test_plain_text(self):
|
||||
assert list(_normparse("hello world")) == ["hello world"]
|
||||
|
|
|
|||
Loading…
Reference in a new issue