Replace assertIn

This commit is contained in:
Šarūnas Nejus 2024-07-29 01:38:29 +01:00
parent 2616bcc950
commit 11e948121c
No known key found for this signature in database
GPG key ID: DD28F6704DBE3435
27 changed files with 203 additions and 206 deletions

View file

@ -442,7 +442,7 @@ class ITunesStoreTest(UseThePlugin):
with capture_log("beets.test_art") as logs:
with self.assertRaises(StopIteration):
next(self.source.get(self.album, self.settings, []))
self.assertIn(expected, logs[1])
assert expected in logs[1]
def test_itunesstore_requestexception(self):
responses.add(
@ -456,7 +456,7 @@ class ITunesStoreTest(UseThePlugin):
with capture_log("beets.test_art") as logs:
with self.assertRaises(StopIteration):
next(self.source.get(self.album, self.settings, []))
self.assertIn(expected, logs[1])
assert expected in logs[1]
def test_itunesstore_fallback_match(self):
json = """{
@ -489,7 +489,7 @@ class ITunesStoreTest(UseThePlugin):
with capture_log("beets.test_art") as logs:
with self.assertRaises(StopIteration):
next(self.source.get(self.album, self.settings, []))
self.assertIn(expected, logs[1])
assert expected in logs[1]
def test_itunesstore_returns_no_result_when_error_received(self):
json = '{"error": {"errors": [{"reason": "some reason"}]}}'
@ -499,7 +499,7 @@ class ITunesStoreTest(UseThePlugin):
with capture_log("beets.test_art") as logs:
with self.assertRaises(StopIteration):
next(self.source.get(self.album, self.settings, []))
self.assertIn(expected, logs[1])
assert expected in logs[1]
def test_itunesstore_returns_no_result_with_malformed_response(self):
json = """bla blup"""
@ -509,7 +509,7 @@ class ITunesStoreTest(UseThePlugin):
with capture_log("beets.test_art") as logs:
with self.assertRaises(StopIteration):
next(self.source.get(self.album, self.settings, []))
self.assertIn(expected, logs[1])
assert expected in logs[1]
class GoogleImageTest(UseThePlugin):
@ -584,7 +584,7 @@ class CoverArtArchiveTest(UseThePlugin, CAAHelper):
candidates = list(self.source.get(album, self.settings, []))
self.assertEqual(len(candidates), 3)
for candidate in candidates:
self.assertIn(f"-{maxwidth}.jpg", candidate.url)
assert f"-{maxwidth}.jpg" in candidate.url
def test_caa_finds_image_if_maxwidth_is_set_and_thumbnails_is_empty(self):
# CAA provides pre-sized thumbnails of width 250px, 500px, and 1200px

View file

@ -71,7 +71,7 @@ class BareascPluginTest(PluginTestCase):
with capture_stdout() as output:
self.run_command("bareasc", "with accents")
self.assertIn("Antonin Dvorak", output.getvalue())
assert "Antonin Dvorak" in output.getvalue()
def test_bareasc_format_output(self):
"""Bare-ASCII version of list -f command - check output."""

View file

@ -364,7 +364,7 @@ class DGAlbumInfoTest(BeetsTestCase):
d = DiscogsPlugin().get_album_info(release)
self.assertEqual(d, None)
self.assertIn("Release does not contain the required fields", logs[0])
assert "Release does not contain the required fields" in logs[0]
def test_album_for_id(self):
"""Test parsing for a valid Discogs release_id"""

View file

@ -411,7 +411,7 @@ class EditDuringImporterNonSingletonTest(EditDuringImporterTestCase):
assert all("match " in i.mb_trackid for i in self.lib.items())
# Ensure album is fetched from a candidate.
self.assertIn("albumid", self.lib.albums()[0].mb_albumid)
assert "albumid" in self.lib.albums()[0].mb_albumid
def test_edit_retag_apply(self):
"""Import the album using a candidate, then retag and edit and apply
@ -439,7 +439,7 @@ class EditDuringImporterNonSingletonTest(EditDuringImporterTestCase):
assert all("match " in i.mb_trackid for i in self.lib.items())
# Ensure album is fetched from a candidate.
self.assertIn("albumid", self.lib.albums()[0].mb_albumid)
assert "albumid" in self.lib.albums()[0].mb_albumid
def test_edit_discard_candidate(self):
"""Edit the album field for all items in the library, discard changes,
@ -458,7 +458,7 @@ class EditDuringImporterNonSingletonTest(EditDuringImporterTestCase):
assert all("match " in i.mb_trackid for i in self.lib.items())
# Ensure album is fetched from a candidate.
self.assertIn("albumid", self.lib.albums()[0].mb_albumid)
assert "albumid" in self.lib.albums()[0].mb_albumid
def test_edit_apply_candidate_singleton(self):
"""Edit the album field for all items in the library, apply changes,

View file

@ -52,7 +52,7 @@ class ExportPluginTest(PluginTestCase):
out = self.execute_command(format_type="json", artist=item1.artist)
json_data = json.loads(out)[0]
for key, val in self.test_values.items():
self.assertIn(key, json_data)
assert key in json_data
self.assertEqual(val, json_data[key])
def test_jsonlines_output(self):
@ -60,7 +60,7 @@ class ExportPluginTest(PluginTestCase):
out = self.execute_command(format_type="jsonlines", artist=item1.artist)
json_data = json.loads(out)
for key, val in self.test_values.items():
self.assertIn(key, json_data)
assert key in json_data
self.assertEqual(val, json_data[key])
def test_csv_output(self):
@ -82,5 +82,5 @@ class ExportPluginTest(PluginTestCase):
for details in track:
tag = details.tag
txt = details.text
self.assertIn(tag, self.test_values, msg=tag)
assert tag in self.test_values, tag
self.assertEqual(self.test_values[tag], txt, msg=txt)

View file

@ -44,26 +44,24 @@ class HookLogsTest(HookTestCase):
def test_hook_empty_command(self):
with self._configure_logs("") as logs:
self.assertIn('hook: invalid command ""', logs)
assert 'hook: invalid command ""' in logs
# FIXME: fails on windows
@unittest.skipIf(sys.platform == "win32", "win32")
def test_hook_non_zero_exit(self):
with self._configure_logs('sh -c "exit 1"') as logs:
self.assertIn(
"hook: hook for test_event exited with status 1", logs
)
assert "hook: hook for test_event exited with status 1" in logs
def test_hook_non_existent_command(self):
with self._configure_logs("non-existent-command") as logs:
logs = "\n".join(logs)
self.assertIn("hook: hook for test_event failed: ", logs)
assert "hook: hook for test_event failed: " in logs
# The error message is different for each OS. Unfortunately the text is
# different in each case, where the only shared text is the string
# 'file' and substring 'Err'
self.assertIn("Err", logs)
self.assertIn("file", logs)
assert "Err" in logs
assert "file" in logs
class HookCommandTest(HookTestCase):

View file

@ -29,7 +29,7 @@ class ImportfeedsTestTest(BeetsTestCase):
)
assert playlist_path.endswith("album_name.m3u")
with open(playlist_path) as playlist:
self.assertIn(item_path, playlist.read())
assert item_path in playlist.read()
def test_playlist_in_subdir(self):
config["importfeeds"]["formats"] = "m3u"
@ -65,4 +65,4 @@ class ImportfeedsTestTest(BeetsTestCase):
playlist = os.path.join(self.feeds_dir, f"imports_{date}.m3u")
assert os.path.isfile(playlist)
with open(playlist) as playlist_contents:
self.assertIn(item_path, playlist_contents.read())
assert item_path in playlist_contents.read()

View file

@ -33,10 +33,10 @@ class InfoTest(PluginTestCase):
mediafile.save()
out = self.run_with_output("info", path)
self.assertIn(displayable_path(path), out)
self.assertIn("albumartist: AAA", out)
self.assertIn("disctitle: DDD", out)
self.assertIn("genres: a; b; c", out)
assert displayable_path(path) in out
assert "albumartist: AAA" in out
assert "disctitle: DDD" in out
assert "genres: a; b; c" in out
self.assertNotIn("composer:", out)
def test_item_query(self):
@ -47,8 +47,8 @@ class InfoTest(PluginTestCase):
item1.store()
out = self.run_with_output("info", "album:yyyy")
self.assertIn(displayable_path(item1.path), out)
self.assertIn("album: xxxx", out)
assert displayable_path(item1.path) in out
assert "album: xxxx" in out
self.assertNotIn(displayable_path(item2.path), out)
@ -58,8 +58,8 @@ class InfoTest(PluginTestCase):
item.store()
out = self.run_with_output("info", "--library", "album:xxxx")
self.assertIn(displayable_path(item.path), out)
self.assertIn("album: xxxx", out)
assert displayable_path(item.path) in out
assert "album: xxxx" in out
def test_collect_item_and_path(self):
path = self.create_mediafile_fixture()
@ -76,9 +76,9 @@ class InfoTest(PluginTestCase):
mediafile.save()
out = self.run_with_output("info", "--summarize", "album:AAA", path)
self.assertIn("album: AAA", out)
self.assertIn("tracktotal: 5", out)
self.assertIn("title: [various]", out)
assert "album: AAA" in out
assert "tracktotal: 5" in out
assert "title: [various]" in out
def test_collect_item_and_path_with_multi_values(self):
path = self.create_mediafile_fixture()
@ -101,11 +101,11 @@ class InfoTest(PluginTestCase):
mediafile.save()
out = self.run_with_output("info", "--summarize", "album:AAA", path)
self.assertIn("album: AAA", out)
self.assertIn("tracktotal: 5", out)
self.assertIn("title: [various]", out)
self.assertIn("albumartists: [various]", out)
self.assertIn("artists: Artist A; Artist Z", out)
assert "album: AAA" in out
assert "tracktotal: 5" in out
assert "title: [various]" in out
assert "albumartists: [various]" in out
assert "artists: Artist A; Artist Z" in out
def test_custom_format(self):
self.add_item_fixtures()

View file

@ -45,34 +45,32 @@ class LyricsPluginTest(unittest.TestCase):
def test_search_artist(self):
item = Item(artist="Alice ft. Bob", title="song")
self.assertIn(("Alice ft. Bob", ["song"]), lyrics.search_pairs(item))
self.assertIn(("Alice", ["song"]), lyrics.search_pairs(item))
assert ("Alice ft. Bob", ["song"]) in lyrics.search_pairs(item)
assert ("Alice", ["song"]) in lyrics.search_pairs(item)
item = Item(artist="Alice feat Bob", title="song")
self.assertIn(("Alice feat Bob", ["song"]), lyrics.search_pairs(item))
self.assertIn(("Alice", ["song"]), lyrics.search_pairs(item))
assert ("Alice feat Bob", ["song"]) in lyrics.search_pairs(item)
assert ("Alice", ["song"]) in lyrics.search_pairs(item)
item = Item(artist="Alice feat. Bob", title="song")
self.assertIn(("Alice feat. Bob", ["song"]), lyrics.search_pairs(item))
self.assertIn(("Alice", ["song"]), lyrics.search_pairs(item))
assert ("Alice feat. Bob", ["song"]) in lyrics.search_pairs(item)
assert ("Alice", ["song"]) in lyrics.search_pairs(item)
item = Item(artist="Alice feats Bob", title="song")
self.assertIn(("Alice feats Bob", ["song"]), lyrics.search_pairs(item))
assert ("Alice feats Bob", ["song"]) in lyrics.search_pairs(item)
self.assertNotIn(("Alice", ["song"]), lyrics.search_pairs(item))
item = Item(artist="Alice featuring Bob", title="song")
self.assertIn(
("Alice featuring Bob", ["song"]), lyrics.search_pairs(item)
)
self.assertIn(("Alice", ["song"]), lyrics.search_pairs(item))
assert ("Alice featuring Bob", ["song"]) in lyrics.search_pairs(item)
assert ("Alice", ["song"]) in lyrics.search_pairs(item)
item = Item(artist="Alice & Bob", title="song")
self.assertIn(("Alice & Bob", ["song"]), lyrics.search_pairs(item))
self.assertIn(("Alice", ["song"]), lyrics.search_pairs(item))
assert ("Alice & Bob", ["song"]) in lyrics.search_pairs(item)
assert ("Alice", ["song"]) in lyrics.search_pairs(item)
item = Item(artist="Alice and Bob", title="song")
self.assertIn(("Alice and Bob", ["song"]), lyrics.search_pairs(item))
self.assertIn(("Alice", ["song"]), lyrics.search_pairs(item))
assert ("Alice and Bob", ["song"]) in lyrics.search_pairs(item)
assert ("Alice", ["song"]) in lyrics.search_pairs(item)
item = Item(artist="Alice and Bob", title="song")
self.assertEqual(
@ -81,8 +79,8 @@ class LyricsPluginTest(unittest.TestCase):
def test_search_artist_sort(self):
item = Item(artist="CHVRCHΞS", title="song", artist_sort="CHVRCHES")
self.assertIn(("CHVRCHΞS", ["song"]), lyrics.search_pairs(item))
self.assertIn(("CHVRCHES", ["song"]), lyrics.search_pairs(item))
assert ("CHVRCHΞS", ["song"]) in lyrics.search_pairs(item)
assert ("CHVRCHES", ["song"]) in lyrics.search_pairs(item)
# Make sure that the original artist name is still the first entry
self.assertEqual(
@ -92,8 +90,8 @@ class LyricsPluginTest(unittest.TestCase):
item = Item(
artist="横山克", title="song", artist_sort="Masaru Yokoyama"
)
self.assertIn(("横山克", ["song"]), lyrics.search_pairs(item))
self.assertIn(("Masaru Yokoyama", ["song"]), lyrics.search_pairs(item))
assert ("横山克", ["song"]) in lyrics.search_pairs(item)
assert ("Masaru Yokoyama", ["song"]) in lyrics.search_pairs(item)
# Make sure that the original artist name is still the first entry
self.assertEqual(
@ -102,41 +100,41 @@ class LyricsPluginTest(unittest.TestCase):
def test_search_pairs_multi_titles(self):
item = Item(title="1 / 2", artist="A")
self.assertIn(("A", ["1 / 2"]), lyrics.search_pairs(item))
self.assertIn(("A", ["1", "2"]), lyrics.search_pairs(item))
assert ("A", ["1 / 2"]) in lyrics.search_pairs(item)
assert ("A", ["1", "2"]) in lyrics.search_pairs(item)
item = Item(title="1/2", artist="A")
self.assertIn(("A", ["1/2"]), lyrics.search_pairs(item))
self.assertIn(("A", ["1", "2"]), lyrics.search_pairs(item))
assert ("A", ["1/2"]) in lyrics.search_pairs(item)
assert ("A", ["1", "2"]) in lyrics.search_pairs(item)
def test_search_pairs_titles(self):
item = Item(title="Song (live)", artist="A")
self.assertIn(("A", ["Song"]), lyrics.search_pairs(item))
self.assertIn(("A", ["Song (live)"]), lyrics.search_pairs(item))
assert ("A", ["Song"]) in lyrics.search_pairs(item)
assert ("A", ["Song (live)"]) in lyrics.search_pairs(item)
item = Item(title="Song (live) (new)", artist="A")
self.assertIn(("A", ["Song"]), lyrics.search_pairs(item))
self.assertIn(("A", ["Song (live) (new)"]), lyrics.search_pairs(item))
assert ("A", ["Song"]) in lyrics.search_pairs(item)
assert ("A", ["Song (live) (new)"]) in lyrics.search_pairs(item)
item = Item(title="Song (live (new))", artist="A")
self.assertIn(("A", ["Song"]), lyrics.search_pairs(item))
self.assertIn(("A", ["Song (live (new))"]), lyrics.search_pairs(item))
assert ("A", ["Song"]) in lyrics.search_pairs(item)
assert ("A", ["Song (live (new))"]) in lyrics.search_pairs(item)
item = Item(title="Song ft. B", artist="A")
self.assertIn(("A", ["Song"]), lyrics.search_pairs(item))
self.assertIn(("A", ["Song ft. B"]), lyrics.search_pairs(item))
assert ("A", ["Song"]) in lyrics.search_pairs(item)
assert ("A", ["Song ft. B"]) in lyrics.search_pairs(item)
item = Item(title="Song featuring B", artist="A")
self.assertIn(("A", ["Song"]), lyrics.search_pairs(item))
self.assertIn(("A", ["Song featuring B"]), lyrics.search_pairs(item))
assert ("A", ["Song"]) in lyrics.search_pairs(item)
assert ("A", ["Song featuring B"]) in lyrics.search_pairs(item)
item = Item(title="Song and B", artist="A")
self.assertNotIn(("A", ["Song"]), lyrics.search_pairs(item))
self.assertIn(("A", ["Song and B"]), lyrics.search_pairs(item))
assert ("A", ["Song and B"]) in lyrics.search_pairs(item)
item = Item(title="Song: B", artist="A")
self.assertIn(("A", ["Song"]), lyrics.search_pairs(item))
self.assertIn(("A", ["Song: B"]), lyrics.search_pairs(item))
assert ("A", ["Song"]) in lyrics.search_pairs(item)
assert ("A", ["Song: B"]) in lyrics.search_pairs(item)
def test_remove_credits(self):
self.assertEqual(

View file

@ -51,7 +51,7 @@ class MBSubmitPluginTest(PluginMixin, TerminalImportMixin, ImportTestCase):
"01. Tag Track 1 - Tag Artist (0:01)\n"
"02. Tag Track 2 - Tag Artist (0:01)"
)
self.assertIn(tracklist, output.getvalue())
assert tracklist in output.getvalue()
def test_print_tracks_output_as_tracks(self):
"""Test the output of the "print tracks" choice, as singletons."""
@ -66,4 +66,4 @@ class MBSubmitPluginTest(PluginMixin, TerminalImportMixin, ImportTestCase):
tracklist = (
"Open files with Picard? " "02. Tag Track 2 - Tag Artist (0:01)"
)
self.assertIn(tracklist, output.getvalue())
assert tracklist in output.getvalue()

View file

@ -57,8 +57,8 @@ class MbsyncCliTest(PluginTestCase):
with capture_log() as logs:
self.run_command("mbsync")
self.assertIn("Sending event: albuminfo_received", logs)
self.assertIn("Sending event: trackinfo_received", logs)
assert "Sending event: albuminfo_received" in logs
assert "Sending event: trackinfo_received" in logs
item.load()
self.assertEqual(item.title, "singleton info")

View file

@ -44,7 +44,7 @@ class MPDStatsTest(PluginTestCase):
self.assertEqual(str(mpdstats.get_item(item_path)), str(item))
assert mpdstats.get_item("/some/non-existing/path") is None
self.assertIn("item not found:", log.info.call_args[0][0])
assert "item not found:" in log.info.call_args[0][0]
FAKE_UNKNOWN_STATE = "some-unknown-one"
STATUSES = [

View file

@ -1034,7 +1034,7 @@ class BPDDatabaseTest(BPDTestHelper):
"lsinfo", response2.data["directory"]
)
self._assert_ok(response3)
self.assertIn(self.item1.title, response3.data["Title"])
assert self.item1.title in response3.data["Title"]
def test_cmd_count(self):
with self.run_bpd() as client:

View file

@ -117,9 +117,9 @@ class ExtendedFieldTestMixin(BeetsTestCase):
def test_invalid_descriptor(self):
with self.assertRaises(ValueError) as cm:
mediafile.MediaFile.add_field("somekey", True)
self.assertIn("must be an instance of MediaField", str(cm.exception))
assert "must be an instance of MediaField" in str(cm.exception)
def test_overwrite_property(self):
with self.assertRaises(ValueError) as cm:
mediafile.MediaFile.add_field("artist", mediafile.MediaField())
self.assertIn('property "artist" already exists', str(cm.exception))
assert 'property "artist" already exists' in str(cm.exception)

View file

@ -79,9 +79,9 @@ class SpotifyPluginTest(BeetsTestCase):
params = _params(responses.calls[0].request.url)
query = params["q"][0]
self.assertIn("duifhjslkef", query)
self.assertIn("artist:ujydfsuihse", query)
self.assertIn("album:lkajsdflakjsd", query)
assert "duifhjslkef" in query
assert "artist:ujydfsuihse" in query
assert "album:lkajsdflakjsd" in query
self.assertEqual(params["type"], ["track"])
@responses.activate
@ -114,9 +114,9 @@ class SpotifyPluginTest(BeetsTestCase):
params = _params(responses.calls[0].request.url)
query = params["q"][0]
self.assertIn("Happy", query)
self.assertIn("artist:Pharrell Williams", query)
self.assertIn("album:Despicable Me 2", query)
assert "Happy" in query
assert "artist:Pharrell Williams" in query
assert "album:Despicable Me 2" in query
self.assertEqual(params["type"], ["track"])
@responses.activate

View file

@ -38,7 +38,7 @@ class TypesPluginTest(PluginTestCase):
# Match in range
out = self.list("myint:1..3")
self.assertIn("aaa", out)
assert "aaa" in out
def test_album_integer_modify_and_query(self):
self.config["types"] = {"myint": "int"}
@ -54,7 +54,7 @@ class TypesPluginTest(PluginTestCase):
# Match in range
out = self.list_album("myint:1..3")
self.assertIn("aaa", out)
assert "aaa" in out
def test_float_modify_and_query(self):
self.config["types"] = {"myfloat": "float"}
@ -70,7 +70,7 @@ class TypesPluginTest(PluginTestCase):
# Match in range
out = self.list("myfloat:-10..0")
self.assertIn("aaa", out)
assert "aaa" in out
def test_bool_modify_and_query(self):
self.config["types"] = {"mybool": "bool"}
@ -101,7 +101,7 @@ class TypesPluginTest(PluginTestCase):
# Dealing with unset fields?
# self.assertEqual('false False', out)
# out = self.list('mybool:', '$artist $mybool')
# self.assertIn('unset $mybool', out)
# assert 'unset $mybool' in out
def test_date_modify_and_query(self):
self.config["types"] = {"mydate": "date"}
@ -170,9 +170,10 @@ class TypesPluginTest(PluginTestCase):
)
bool_template = "%ifdef{starred,Starred: $starred,Not starred}"
self.assertIn(
with_fields.evaluate_template(bool_template).lower(),
("starred: true", "starred: yes", "starred: y"),
assert with_fields.evaluate_template(bool_template).lower() in (
"starred: true",
"starred: yes",
"starred: y",
)
self.assertEqual(
without_fields.evaluate_template(bool_template), "Not starred"

View file

@ -42,7 +42,7 @@ class PluralityTest(BeetsTestCase):
def test_plurality_conflict(self):
objs = [1, 1, 2, 2, 3]
obj, freq = plurality(objs)
self.assertIn(obj, (1, 2))
assert obj in (1, 2)
self.assertEqual(freq, 2)
def test_plurality_empty_sequence_raises_error(self):

View file

@ -114,8 +114,8 @@ class ConfigCommandTest(BeetsTestCase):
with patch("os.execlp") as execlp:
execlp.side_effect = OSError("here is problem")
self.run_command("config", "-e")
self.assertIn("Could not edit configuration", str(user_error.exception))
self.assertIn("here is problem", str(user_error.exception))
assert "Could not edit configuration" in str(user_error.exception)
assert "here is problem" in str(user_error.exception)
def test_edit_invalid_config_file(self):
with open(self.config_path, "w") as file:

View file

@ -314,14 +314,14 @@ class ModelTest(unittest.TestCase):
def test_delete_flexattr(self):
model = ModelFixture1()
model["foo"] = "bar"
self.assertIn("foo", model)
assert "foo" in model
del model["foo"]
self.assertNotIn("foo", model)
def test_delete_flexattr_via_dot(self):
model = ModelFixture1()
model["foo"] = "bar"
self.assertIn("foo", model)
assert "foo" in model
del model.foo
self.assertNotIn("foo", model)
@ -377,7 +377,7 @@ class ModelTest(unittest.TestCase):
model1.add(self.db)
model2 = self.db._get(ModelFixture1, model1.id)
self.assertIn("flex_field", model2)
assert "flex_field" in model2
del model1["flex_field"]
model1.store()

View file

@ -124,20 +124,20 @@ class MoveTest(BeetsTestCase):
def test_move_file_with_colon(self):
self.i.artist = "C:DOS"
self.i.move()
self.assertIn("C_DOS", self.i.path.decode())
assert "C_DOS" in self.i.path.decode()
def test_move_file_with_multiple_colons(self):
# print(beets.config["replace"])
self.i.artist = "COM:DOS"
self.i.move()
self.assertIn("COM_DOS", self.i.path.decode())
assert "COM_DOS" in self.i.path.decode()
def test_move_file_with_colon_alt_separator(self):
old = beets.config["drive_sep_replace"]
beets.config["drive_sep_replace"] = "0"
self.i.artist = "C:DOS"
self.i.move()
self.assertIn("C0DOS", self.i.path.decode())
assert "C0DOS" in self.i.path.decode()
beets.config["drive_sep_replace"] = old
def test_read_only_file_copied_writable(self):
@ -302,7 +302,7 @@ class AlbumFileTest(BeetsTestCase):
self.ai.move(basedir=self.otherdir)
self.i.load()
self.ai.store()
self.assertIn(b"testotherdir", self.i.path)
assert b"testotherdir" in self.i.path
class ArtFileTest(BeetsTestCase):
@ -352,7 +352,7 @@ class ArtFileTest(BeetsTestCase):
self.assertNotExists(self.art)
newart = self.lib.get_album(self.i).artpath
self.assertExists(newart)
self.assertIn(b"testotherdir", newart)
assert b"testotherdir" in newart
def test_setart_copies_image(self):
util.remove(self.art)

View file

@ -556,7 +556,7 @@ class ImportTest(ImportTestCase):
self.importer.run()
import_dir = displayable_path(import_dir)
self.assertIn(f"No files imported from {import_dir}", logs)
assert f"No files imported from {import_dir}" in logs
def test_empty_directory_singleton_warning(self):
import_dir = os.path.join(self.temp_dir, b"empty")
@ -566,7 +566,7 @@ class ImportTest(ImportTestCase):
self.importer.run()
import_dir = displayable_path(import_dir)
self.assertIn(f"No files imported from {import_dir}", logs)
assert f"No files imported from {import_dir}" in logs
def test_asis_no_data_source(self):
assert self.lib.items().get() is None
@ -1317,14 +1317,14 @@ class TagLogTest(BeetsTestCase):
handler = logging.StreamHandler(sio)
session = _common.import_session(loghandler=handler)
session.tag_log("status", "path")
self.assertIn("status path", sio.getvalue())
assert "status path" in sio.getvalue()
def test_tag_log_unicode(self):
sio = StringIO()
handler = logging.StreamHandler(sio)
session = _common.import_session(loghandler=handler)
session.tag_log("status", "caf\xe9") # send unicode
self.assertIn("status caf\xe9", sio.getvalue())
assert "status caf\xe9" in sio.getvalue()
class ResumeImportTest(ImportTestCase):
@ -1440,10 +1440,10 @@ class AlbumsInDirTest(BeetsTestCase):
found = []
for _, album in albums_in_dir(self.base):
found.append(re.search(rb"album(.)song", album[0]).group(1))
self.assertIn(b"1", found)
self.assertIn(b"2", found)
self.assertIn(b"3", found)
self.assertIn(b"4", found)
assert b"1" in found
assert b"2" in found
assert b"3" in found
assert b"4" in found
def test_finds_multiple_songs(self):
for _, album in albums_in_dir(self.base):

View file

@ -48,7 +48,7 @@ class LoadTest(ItemInDBTestCase):
def test_load_clears_dirty_flags(self):
self.i.artist = "something"
self.assertIn("artist", self.i._dirty)
assert "artist" in self.i._dirty
self.i.load()
self.assertNotIn("artist", self.i._dirty)
@ -143,7 +143,7 @@ class GetSetTest(BeetsTestCase):
def test_set_sets_dirty_flag(self):
self.i.comp = not self.i.comp
self.assertIn("comp", self.i._dirty)
assert "comp" in self.i._dirty
def test_set_does_not_dirty_if_value_unchanged(self):
self.i.title = self.i.title
@ -159,7 +159,7 @@ class GetSetTest(BeetsTestCase):
album["flex"] = "foo"
album.store()
self.assertIn("flex", i)
assert "flex" in i
self.assertNotIn("flex", i.keys(with_album=False))
self.assertEqual(i["flex"], "foo")
self.assertEqual(i.get("flex"), "foo")
@ -231,21 +231,21 @@ class DestinationTest(BeetsTestCase):
def test_destination_escapes_slashes(self):
self.i.album = "one/two"
dest = self.i.destination()
self.assertIn(b"one", dest)
self.assertIn(b"two", dest)
assert b"one" in dest
assert b"two" in dest
self.assertNotIn(b"one/two", dest)
def test_destination_escapes_leading_dot(self):
self.i.album = ".something"
dest = self.i.destination()
self.assertIn(b"something", dest)
assert b"something" in dest
self.assertNotIn(b"/.something", dest)
def test_destination_preserves_legitimate_slashes(self):
self.i.artist = "one"
self.i.album = "two"
dest = self.i.destination()
self.assertIn(os.path.join(b"one", b"two"), dest)
assert os.path.join(b"one", b"two") in dest
def test_destination_long_names_truncated(self):
self.i.title = "X" * 300
@ -271,7 +271,7 @@ class DestinationTest(BeetsTestCase):
def test_path_with_format(self):
self.lib.path_formats = [("default", "$artist/$album ($format)")]
p = self.i.destination()
self.assertIn(b"(FLAC)", p)
assert b"(FLAC)" in p
def test_heterogeneous_album_gets_single_directory(self):
i1, i2 = item(), item()
@ -429,7 +429,7 @@ class DestinationTest(BeetsTestCase):
p = self.i.destination()
self.assertNotIn(b"?", p)
# We use UTF-8 to encode Windows paths now.
self.assertIn("h\u0259d".encode(), p)
assert "h\u0259d".encode() in p
finally:
sys.getfilesystemencoding = oldfunc
@ -1052,7 +1052,7 @@ class ArtDestinationTest(BeetsTestCase):
def test_art_filename_respects_setting(self):
art = self.ai.art_destination("something.jpg")
new_art = bytestring_path("%sartimage.jpg" % os.path.sep)
self.assertIn(new_art, art)
assert new_art in art
def test_art_path_in_item_dir(self):
art = self.ai.art_destination("something.jpg")
@ -1062,7 +1062,7 @@ class ArtDestinationTest(BeetsTestCase):
def test_art_path_sanitized(self):
config["art_filename"] = "artXimage"
art = self.ai.art_destination("something.jpg")
self.assertIn(b"artYimage", art)
assert b"artYimage" in art
class PathStringTest(BeetsTestCase):

View file

@ -86,31 +86,31 @@ class LoggingLevelTest(AsIsImporterMixin, PluginMixin, ImportTestCase):
self.config["verbose"] = 0
with helper.capture_log() as logs:
self.run_command("dummy")
self.assertIn("dummy: warning cmd", logs)
self.assertIn("dummy: info cmd", logs)
assert "dummy: warning cmd" in logs
assert "dummy: info cmd" in logs
self.assertNotIn("dummy: debug cmd", logs)
def test_command_level1(self):
self.config["verbose"] = 1
with helper.capture_log() as logs:
self.run_command("dummy")
self.assertIn("dummy: warning cmd", logs)
self.assertIn("dummy: info cmd", logs)
self.assertIn("dummy: debug cmd", logs)
assert "dummy: warning cmd" in logs
assert "dummy: info cmd" in logs
assert "dummy: debug cmd" in logs
def test_command_level2(self):
self.config["verbose"] = 2
with helper.capture_log() as logs:
self.run_command("dummy")
self.assertIn("dummy: warning cmd", logs)
self.assertIn("dummy: info cmd", logs)
self.assertIn("dummy: debug cmd", logs)
assert "dummy: warning cmd" in logs
assert "dummy: info cmd" in logs
assert "dummy: debug cmd" in logs
def test_listener_level0(self):
self.config["verbose"] = 0
with helper.capture_log() as logs:
plugins.send("dummy_event")
self.assertIn("dummy: warning listener", logs)
assert "dummy: warning listener" in logs
self.assertNotIn("dummy: info listener", logs)
self.assertNotIn("dummy: debug listener", logs)
@ -118,23 +118,23 @@ class LoggingLevelTest(AsIsImporterMixin, PluginMixin, ImportTestCase):
self.config["verbose"] = 1
with helper.capture_log() as logs:
plugins.send("dummy_event")
self.assertIn("dummy: warning listener", logs)
self.assertIn("dummy: info listener", logs)
assert "dummy: warning listener" in logs
assert "dummy: info listener" in logs
self.assertNotIn("dummy: debug listener", logs)
def test_listener_level2(self):
self.config["verbose"] = 2
with helper.capture_log() as logs:
plugins.send("dummy_event")
self.assertIn("dummy: warning listener", logs)
self.assertIn("dummy: info listener", logs)
self.assertIn("dummy: debug listener", logs)
assert "dummy: warning listener" in logs
assert "dummy: info listener" in logs
assert "dummy: debug listener" in logs
def test_import_stage_level0(self):
self.config["verbose"] = 0
with helper.capture_log() as logs:
self.run_asis_importer()
self.assertIn("dummy: warning import_stage", logs)
assert "dummy: warning import_stage" in logs
self.assertNotIn("dummy: info import_stage", logs)
self.assertNotIn("dummy: debug import_stage", logs)
@ -142,17 +142,17 @@ class LoggingLevelTest(AsIsImporterMixin, PluginMixin, ImportTestCase):
self.config["verbose"] = 1
with helper.capture_log() as logs:
self.run_asis_importer()
self.assertIn("dummy: warning import_stage", logs)
self.assertIn("dummy: info import_stage", logs)
assert "dummy: warning import_stage" in logs
assert "dummy: info import_stage" in logs
self.assertNotIn("dummy: debug import_stage", logs)
def test_import_stage_level2(self):
self.config["verbose"] = 2
with helper.capture_log() as logs:
self.run_asis_importer()
self.assertIn("dummy: warning import_stage", logs)
self.assertIn("dummy: info import_stage", logs)
self.assertIn("dummy: debug import_stage", logs)
assert "dummy: warning import_stage" in logs
assert "dummy: info import_stage" in logs
assert "dummy: debug import_stage" in logs
@_common.slow_test()
@ -266,10 +266,10 @@ class ConcurrentEventsTest(AsIsImporterMixin, ImportTestCase):
with helper.capture_log() as logs:
self.run_asis_importer()
for l in logs:
self.assertIn("import", l)
self.assertIn("album", l)
assert "import" in l
assert "album" in l
blog.getLogger("beets").set_global_level(blog.DEBUG)
with helper.capture_log() as logs:
self.run_asis_importer()
self.assertIn("Sending event: database_change", logs)
assert "Sending event: database_change" in logs

View file

@ -84,19 +84,19 @@ class MetaSyncTest(PluginTestCase):
def test_load_item_types(self):
# This test also verifies that the MetaSources have loaded correctly
self.assertIn("amarok_score", Item._types)
self.assertIn("itunes_rating", Item._types)
assert "amarok_score" in Item._types
assert "itunes_rating" in Item._types
def test_pretend_sync_from_itunes(self):
out = self.run_with_output("metasync", "-p")
self.assertIn("itunes_rating: 60 -> 80", out)
self.assertIn("itunes_rating: 100", out)
self.assertIn("itunes_playcount: 31", out)
self.assertIn("itunes_skipcount: 3", out)
self.assertIn("itunes_lastplayed: 2015-05-04 12:20:51", out)
self.assertIn("itunes_lastskipped: 2015-02-05 15:41:04", out)
self.assertIn("itunes_dateadded: 2014-04-24 09:28:38", out)
assert "itunes_rating: 60 -> 80" in out
assert "itunes_rating: 100" in out
assert "itunes_playcount: 31" in out
assert "itunes_skipcount: 3" in out
assert "itunes_lastplayed: 2015-05-04 12:20:51" in out
assert "itunes_lastskipped: 2015-02-05 15:41:04" in out
assert "itunes_dateadded: 2014-04-24 09:28:38" in out
self.assertEqual(self.lib.items()[0].itunes_rating, 60)
def test_sync_from_itunes(self):

View file

@ -95,7 +95,7 @@ class ItemTypesTest(PluginLoaderTestCase):
# Match in range
out = self.run_with_output("ls", "rating:1..3")
self.assertIn("aaa", out)
assert "aaa" in out
# Don't match out of range
out = self.run_with_output("ls", "rating:3..5")

View file

@ -48,7 +48,7 @@ class AssertsMixin:
def assertInResult(self, item, results): # noqa
result_ids = [i.id for i in results]
self.assertIn(item.id, result_ids)
assert item.id in result_ids
def assertNotInResult(self, item, results): # noqa
result_ids = [i.id for i in results]
@ -406,13 +406,13 @@ class GetTest(DummyDataTestCase):
def test_invalid_query(self):
with self.assertRaises(InvalidQueryArgumentValueError) as raised:
dbcore.query.NumericQuery("year", "199a")
self.assertIn("not an int", str(raised.exception))
assert "not an int" in str(raised.exception)
with self.assertRaises(InvalidQueryArgumentValueError) as raised:
dbcore.query.RegexpQuery("year", "199(")
exception_text = str(raised.exception)
self.assertIn("not a regular expression", exception_text)
self.assertIn("unterminated subpattern", exception_text)
assert "not a regular expression" in exception_text
assert "unterminated subpattern" in exception_text
self.assertIsInstance(raised.exception, ParsingError)

View file

@ -56,7 +56,7 @@ class ListTest(BeetsTestCase):
def test_list_outputs_item(self):
stdout = self._run_list()
self.assertIn("the title", stdout.getvalue())
assert "the title" in stdout.getvalue()
def test_list_unicode_query(self):
self.item.title = "na\xefve"
@ -65,7 +65,7 @@ class ListTest(BeetsTestCase):
stdout = self._run_list(["na\xefve"])
out = stdout.getvalue()
self.assertIn("na\xefve", out)
assert "na\xefve" in out
def test_list_item_path(self):
stdout = self._run_list(fmt="$path")
@ -85,17 +85,17 @@ class ListTest(BeetsTestCase):
def test_list_uses_track_artist(self):
stdout = self._run_list()
self.assertIn("the artist", stdout.getvalue())
assert "the artist" in stdout.getvalue()
self.assertNotIn("the album artist", stdout.getvalue())
def test_list_album_uses_album_artist(self):
stdout = self._run_list(album=True)
self.assertNotIn("the artist", stdout.getvalue())
self.assertIn("the album artist", stdout.getvalue())
assert "the album artist" in stdout.getvalue()
def test_list_item_format_artist(self):
stdout = self._run_list(fmt="$artist")
self.assertIn("the artist", stdout.getvalue())
assert "the artist" in stdout.getvalue()
def test_list_item_format_multiple(self):
stdout = self._run_list(fmt="$artist - $album - $year")
@ -105,7 +105,7 @@ class ListTest(BeetsTestCase):
def test_list_album_format(self):
stdout = self._run_list(album=True, fmt="$genre")
self.assertIn("the genre", stdout.getvalue())
assert "the genre" in stdout.getvalue()
self.assertNotIn("the album", stdout.getvalue())
@ -235,7 +235,7 @@ class ModifyTest(BeetsTestCase):
def test_move(self):
self.modify("title=newTitle")
item = self.lib.items().get()
self.assertIn(b"newTitle", item.path)
assert b"newTitle" in item.path
def test_not_move(self):
self.modify("--nomove", "title=newTitle")
@ -317,7 +317,7 @@ class ModifyTest(BeetsTestCase):
self.modify("--album", "album=newAlbum")
item = self.lib.items().get()
item.read()
self.assertIn(b"newAlbum", item.path)
assert b"newAlbum" in item.path
def test_album_not_move(self):
self.modify("--nomove", "--album", "album=newAlbum")
@ -439,7 +439,7 @@ class WriteTest(BeetsTestCase):
output = self.write_cmd()
self.assertIn(f"{old_title} -> new title", output)
assert f"{old_title} -> new title" in output
class MoveTest(BeetsTestCase):
@ -478,54 +478,54 @@ class MoveTest(BeetsTestCase):
def test_move_item(self):
self._move()
self.i.load()
self.assertIn(b"libdir", self.i.path)
assert b"libdir" in self.i.path
self.assertExists(self.i.path)
self.assertNotExists(self.itempath)
def test_copy_item(self):
self._move(copy=True)
self.i.load()
self.assertIn(b"libdir", self.i.path)
assert b"libdir" in self.i.path
self.assertExists(self.i.path)
self.assertExists(self.itempath)
def test_move_album(self):
self._move(album=True)
self.i.load()
self.assertIn(b"libdir", self.i.path)
assert b"libdir" in self.i.path
self.assertExists(self.i.path)
self.assertNotExists(self.itempath)
def test_copy_album(self):
self._move(copy=True, album=True)
self.i.load()
self.assertIn(b"libdir", self.i.path)
assert b"libdir" in self.i.path
self.assertExists(self.i.path)
self.assertExists(self.itempath)
def test_move_item_custom_dir(self):
self._move(dest=self.otherdir)
self.i.load()
self.assertIn(b"testotherdir", self.i.path)
assert b"testotherdir" in self.i.path
self.assertExists(self.i.path)
self.assertNotExists(self.itempath)
def test_move_album_custom_dir(self):
self._move(dest=self.otherdir, album=True)
self.i.load()
self.assertIn(b"testotherdir", self.i.path)
assert b"testotherdir" in self.i.path
self.assertExists(self.i.path)
self.assertNotExists(self.itempath)
def test_pretend_move_item(self):
self._move(dest=self.otherdir, pretend=True)
self.i.load()
self.assertIn(b"srcfile", self.i.path)
assert b"srcfile" in self.i.path
def test_pretend_move_album(self):
self._move(album=True, pretend=True)
self.i.load()
self.assertIn(b"srcfile", self.i.path)
assert b"srcfile" in self.i.path
def test_export_item_custom_dir(self):
self._move(dest=self.otherdir, export=True)
@ -542,7 +542,7 @@ class MoveTest(BeetsTestCase):
def test_pretend_export_item(self):
self._move(dest=self.otherdir, pretend=True, export=True)
self.i.load()
self.assertIn(b"srcfile", self.i.path)
assert b"srcfile" in self.i.path
self.assertNotExists(self.otherdir)
@ -629,7 +629,7 @@ class UpdateTest(BeetsTestCase):
mf.save()
self._update(move=True)
item = self.lib.items().get()
self.assertIn(b"differentTitle", item.path)
assert b"differentTitle" in item.path
def test_modified_metadata_not_moved(self):
mf = MediaFile(syspath(self.i.path))
@ -646,7 +646,7 @@ class UpdateTest(BeetsTestCase):
mf.save()
self._update(move=True, fields=["title"])
item = self.lib.items().get()
self.assertIn(b"differentTitle", item.path)
assert b"differentTitle" in item.path
self.assertNotEqual(item.genre, "differentGenre")
def test_selective_modified_metadata_not_moved(self):
@ -665,7 +665,7 @@ class UpdateTest(BeetsTestCase):
mf.save()
self._update(move=True)
item = self.lib.items().get()
self.assertIn(b"differentAlbum", item.path)
assert b"differentAlbum" in item.path
def test_modified_album_metadata_art_moved(self):
artpath = self.album.artpath
@ -684,7 +684,7 @@ class UpdateTest(BeetsTestCase):
mf.save()
self._update(move=True, fields=["album"])
item = self.lib.items().get()
self.assertIn(b"differentAlbum", item.path)
assert b"differentAlbum" in item.path
self.assertNotEqual(item.genre, "differentGenre")
def test_selective_modified_album_metadata_not_moved(self):
@ -1152,13 +1152,13 @@ class ShowModelChangeTest(BeetsTestCase):
self.b.title = "x"
change, out = self._show()
assert change
self.assertIn("title", out)
assert "title" in out
def test_int_fixed_field_change(self):
self.b.track = 9
change, out = self._show()
assert change
self.assertIn("track", out)
assert "track" in out
def test_floats_close_to_identical(self):
self.a.length = 1.00001
@ -1172,14 +1172,14 @@ class ShowModelChangeTest(BeetsTestCase):
self.b.length = 2.00001
change, out = self._show()
assert change
self.assertIn("length", out)
assert "length" in out
def test_both_values_shown(self):
self.a.title = "foo"
self.b.title = "bar"
change, out = self._show()
self.assertIn("foo", out)
self.assertIn("bar", out)
assert "foo" in out
assert "bar" in out
class ShowChangeTest(BeetsTestCase):
@ -1228,15 +1228,15 @@ class ShowChangeTest(BeetsTestCase):
def test_null_change(self):
msg = self._show_change()
self.assertIn("match (90.0%)", msg)
self.assertIn("album, artist", msg)
assert "match (90.0%)" in msg
assert "album in artist", msg
def test_album_data_change(self):
msg = self._show_change(
cur_artist="another artist", cur_album="another album"
)
self.assertIn("another artist -> the artist", msg)
self.assertIn("another album -> the album", msg)
assert "another artist -> the artist" in msg
assert "another album -> the album" in msg
def test_item_data_change(self):
self.items[0].title = "different"
@ -1317,8 +1317,8 @@ class ShowChangeTest(BeetsTestCase):
cur_artist=long_name, cur_album="another album"
)
# _common.log.info("Message:{}".format(msg))
self.assertIn("artist: another artist", msg)
self.assertIn(" -> the artist", msg)
assert "artist: another artist" in msg
assert " -> the artist" in msg
self.assertNotIn("another album -> the album", msg)
def test_item_data_change_wrap_column(self):
@ -1329,7 +1329,7 @@ class ShowChangeTest(BeetsTestCase):
long_title = "a track with a" + (" very" * 10) + " long name"
self.items[0].title = long_title
msg = self._show_change()
self.assertIn("(#1) a track (1:00) -> (#1) the title (0:00)", msg)
assert "(#1) a track (1:00) -> (#1) the title (0:00)" in msg
def test_item_data_change_wrap_newline(self):
# Patch ui.term_width to force wrapping
@ -1338,8 +1338,8 @@ class ShowChangeTest(BeetsTestCase):
long_title = "a track with a" + (" very" * 10) + " long name"
self.items[0].title = long_title
msg = self._show_change()
self.assertIn("(#1) a track with", msg)
self.assertIn(" -> (#1) the title (0:00)", msg)
assert "(#1) a track with" in msg
assert " -> (#1) the title (0:00)" in msg
@patch("beets.library.Item.try_filesize", Mock(return_value=987))
@ -1499,30 +1499,30 @@ class CommonOptionsParserCliTest(BeetsTestCase):
def test_help(self):
l = self.run_with_output("help")
self.assertIn("Usage:", l)
assert "Usage:" in l
l = self.run_with_output("help", "list")
self.assertIn("Usage:", l)
assert "Usage:" in l
with self.assertRaises(ui.UserError):
self.run_command("help", "this.is.not.a.real.command")
def test_stats(self):
l = self.run_with_output("stats")
self.assertIn("Approximate total size:", l)
assert "Approximate total size:" in l
# # Need to have more realistic library setup for this to work
# l = self.run_with_output('stats', '-e')
# self.assertIn('Total size:', l)
# assert 'Total size:' in l
def test_version(self):
l = self.run_with_output("version")
self.assertIn("Python version", l)
self.assertIn("no plugins loaded", l)
assert "Python version" in l
assert "no plugins loaded" in l
# # Need to have plugin loaded
# l = self.run_with_output('version')
# self.assertIn('plugins: ', l)
# assert 'plugins: ' in l
class CommonOptionsParserTest(BeetsTestCase):