Skip to content

Commit

Permalink
Use f-string syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
snejus committed Aug 16, 2024
1 parent 090b62f commit 05cbc54
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 57 deletions.
9 changes: 2 additions & 7 deletions test/plugins/test_beatport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -570,11 +569,7 @@ def test_track_url_applied(self):
# 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):
Expand Down
16 changes: 7 additions & 9 deletions test/plugins/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def assertFileTag(self, path, tag): # noqa
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
Expand All @@ -77,9 +77,9 @@ def assertNoFileTag(self, path, tag): # noqa
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):
Expand Down Expand Up @@ -123,9 +123,7 @@ def test_delete_originals(self):
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
Expand Down
8 changes: 2 additions & 6 deletions test/plugins/test_embedart.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ def test_reject_different_art(self):

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):
Expand All @@ -171,9 +169,7 @@ def test_accept_similar_art(self):

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")
Expand Down
5 changes: 1 addition & 4 deletions test/plugins/test_play.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ def test_use_folders(self, open_mock):
open_mock.assert_called_once_with(ANY, open_anything())
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
)
assert f'{os.path.dirname(self.item.path.decode("utf-8"))}\n' == playlist

def test_raw(self, open_mock):
self.config["play"]["raw"] = True
Expand Down
2 changes: 1 addition & 1 deletion test/plugins/test_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def run_bpd(
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
Expand Down
7 changes: 2 additions & 5 deletions test/test_autotag.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,13 @@ def test_current_metadata_likelies(self):
"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"):
Expand Down
12 changes: 5 additions & 7 deletions test/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,9 @@ def test_import_task_created(self):

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):
Expand Down Expand Up @@ -219,8 +217,8 @@ def import_task_created_event(self, session, task):

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)}",
]


Expand Down
2 changes: 1 addition & 1 deletion test/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ def test_detect_absolute_path(self):
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
Expand Down
22 changes: 5 additions & 17 deletions test/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,18 @@ def test_empty_string(self):

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"]
Expand Down

0 comments on commit 05cbc54

Please sign in to comment.