diff --git a/test/plugins/test_art.py b/test/plugins/test_art.py index b2d1d74b4..30f08d50f 100644 --- a/test/plugins/test_art.py +++ b/test/plugins/test_art.py @@ -225,12 +225,12 @@ class FetchImageTest(FetchImageHelper, UseThePlugin): def test_invalid_type_returns_none(self): self.mock_response(self.URL, "image/watercolour") self.source.fetch_image(self.candidate, self.settings) - self.assertEqual(self.candidate.path, None) + self.assertIsNone(self.candidate.path) def test_jpeg_type_returns_path(self): self.mock_response(self.URL, "image/jpeg") self.source.fetch_image(self.candidate, self.settings) - self.assertNotEqual(self.candidate.path, None) + self.assertIsNotNone(self.candidate.path) def test_extension_set_by_content_type(self): self.mock_response(self.URL, "image/png") @@ -600,7 +600,7 @@ class CoverArtArchiveTest(UseThePlugin, CAAHelper): candidates = list(self.source.get(album, self.settings, [])) self.assertEqual(len(candidates), 3) for candidate in candidates: - self.assertTrue(f"-{maxwidth}.jpg" in candidate.url) + self.assertIn(f"-{maxwidth}.jpg", 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 @@ -621,7 +621,7 @@ class CoverArtArchiveTest(UseThePlugin, CAAHelper): candidates = list(self.source.get(album, self.settings, [])) self.assertEqual(len(candidates), 3) for candidate in candidates: - self.assertFalse(f"-{maxwidth}.jpg" in candidate.url) + self.assertNotIn(f"-{maxwidth}.jpg", candidate.url) class FanartTVTest(UseThePlugin): diff --git a/test/plugins/test_export.py b/test/plugins/test_export.py index 977184bb0..b949fe4f8 100644 --- a/test/plugins/test_export.py +++ b/test/plugins/test_export.py @@ -56,7 +56,7 @@ class ExportPluginTest(unittest.TestCase, TestHelper): 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.assertTrue(key in json_data) + self.assertIn(key, json_data) self.assertEqual(val, json_data[key]) def test_jsonlines_output(self): @@ -64,7 +64,7 @@ class ExportPluginTest(unittest.TestCase, TestHelper): out = self.execute_command(format_type="jsonlines", artist=item1.artist) json_data = json.loads(out) for key, val in self.test_values.items(): - self.assertTrue(key in json_data) + self.assertIn(key, json_data) self.assertEqual(val, json_data[key]) def test_csv_output(self): @@ -74,7 +74,7 @@ class ExportPluginTest(unittest.TestCase, TestHelper): head = re.split(",", csv_list[0]) vals = re.split(",|\r", csv_list[1]) for index, column in enumerate(head): - self.assertTrue(self.test_values.get(column, None) is not None) + self.assertIsNotNone(self.test_values.get(column, None)) self.assertEqual(vals[index], self.test_values[column]) def test_xml_output(self): @@ -86,7 +86,7 @@ class ExportPluginTest(unittest.TestCase, TestHelper): for details in track: tag = details.tag txt = details.text - self.assertTrue(tag in self.test_values, msg=tag) + self.assertIn(tag, self.test_values, msg=tag) self.assertEqual(self.test_values[tag], txt, msg=txt) diff --git a/test/plugins/test_fetchart.py b/test/plugins/test_fetchart.py index c651924af..b3307472a 100644 --- a/test/plugins/test_fetchart.py +++ b/test/plugins/test_fetchart.py @@ -60,14 +60,14 @@ class FetchartCliTest(unittest.TestCase, TestHelper): os.makedirs(os.path.join(self.album.path, b"mycover.jpg")) self.run_command("fetchart") self.album.load() - self.assertEqual(self.album["artpath"], None) + self.assertIsNone(self.album["artpath"]) def test_filesystem_does_not_pick_up_ignored_file(self): self.touch(b"co_ver.jpg", dir=self.album.path, content="IMAGE") self.config["ignore"] = ["*_*"] self.run_command("fetchart") self.album.load() - self.assertEqual(self.album["artpath"], None) + self.assertIsNone(self.album["artpath"]) def test_filesystem_picks_up_non_ignored_file(self): self.touch(b"cover.jpg", dir=self.album.path, content="IMAGE") @@ -84,7 +84,7 @@ class FetchartCliTest(unittest.TestCase, TestHelper): self.config["ignore_hidden"] = True self.run_command("fetchart") self.album.load() - self.assertEqual(self.album["artpath"], None) + self.assertIsNone(self.album["artpath"]) def test_filesystem_picks_up_non_hidden_file(self): self.touch(b"cover.jpg", dir=self.album.path, content="IMAGE") diff --git a/test/plugins/test_keyfinder.py b/test/plugins/test_keyfinder.py index 84d66dfeb..8509fe357 100644 --- a/test/plugins/test_keyfinder.py +++ b/test/plugins/test_keyfinder.py @@ -82,7 +82,7 @@ class KeyFinderTest(unittest.TestCase, TestHelper): self.run_command("keyfinder") item.load() - self.assertEqual(item["initial_key"], None) + self.assertIsNone(item["initial_key"]) def suite(): diff --git a/test/plugins/test_lyrics.py b/test/plugins/test_lyrics.py index 108f299fb..a3c6608c0 100644 --- a/test/plugins/test_lyrics.py +++ b/test/plugins/test_lyrics.py @@ -419,11 +419,10 @@ class LyricsGooglePluginMachineryTest(LyricsGoogleBaseTest, LyricsAssertions): soup = BeautifulSoup( html, "html.parser", parse_only=SoupStrainer("title") ) - self.assertEqual( + self.assertTrue( google.is_page_candidate( url, soup.title.string, s["title"], s["artist"] ), - True, url, ) @@ -436,16 +435,14 @@ class LyricsGooglePluginMachineryTest(LyricsGoogleBaseTest, LyricsAssertions): url_title = "example.com | Beats song by John doe" # very small diffs (typo) are ok eg 'beats' vs 'beets' with same artist - self.assertEqual( + self.assertTrue( google.is_page_candidate(url, url_title, s["title"], s["artist"]), - True, url, ) # reject different title url_title = "example.com | seets bong lyrics by John doe" - self.assertEqual( + self.assertTrue( google.is_page_candidate(url, url_title, s["title"], s["artist"]), - False, url, ) @@ -489,7 +486,7 @@ class GeniusScrapeLyricsFromHtmlTest(GeniusBaseTest): # expected return value None url = "https://genius.com/sample" mock = MockFetchUrl() - self.assertEqual(genius._scrape_lyrics_from_html(mock(url)), None) + self.assertIsNone(genius._scrape_lyrics_from_html(mock(url))) def test_good_lyrics(self): """Ensure we are able to scrape a page with lyrics""" diff --git a/test/plugins/test_smartplaylist.py b/test/plugins/test_smartplaylist.py index ee3bfb8ce..a9929651a 100644 --- a/test/plugins/test_smartplaylist.py +++ b/test/plugins/test_smartplaylist.py @@ -33,8 +33,8 @@ from beetsplug.smartplaylist import SmartPlaylistPlugin class SmartPlaylistTest(_common.TestCase): def test_build_queries(self): spl = SmartPlaylistPlugin() - self.assertEqual(spl._matched_playlists, None) - self.assertEqual(spl._unmatched_playlists, None) + self.assertIsNone(spl._matched_playlists) + self.assertIsNone(spl._unmatched_playlists) config["smartplaylist"]["playlists"].set([]) spl.build_queries() diff --git a/test/plugins/test_spotify.py b/test/plugins/test_spotify.py index 59c604a5f..610f39596 100644 --- a/test/plugins/test_spotify.py +++ b/test/plugins/test_spotify.py @@ -51,13 +51,13 @@ class SpotifyPluginTest(_common.TestCase, TestHelper): def test_args(self): opts = ArgumentsMock("fail", True) - self.assertEqual(False, self.spotify._parse_opts(opts)) + self.assertFalse(self.spotify._parse_opts(opts)) opts = ArgumentsMock("list", False) - self.assertEqual(True, self.spotify._parse_opts(opts)) + self.assertTrue(self.spotify._parse_opts(opts)) def test_empty_query(self): - self.assertEqual( - None, self.spotify._match_library_tracks(self.lib, "1=2") + self.assertIsNone( + self.spotify._match_library_tracks(self.lib, "1=2") ) @responses.activate diff --git a/test/plugins/test_types_plugin.py b/test/plugins/test_types_plugin.py index 1726fbf6f..8225c3302 100644 --- a/test/plugins/test_types_plugin.py +++ b/test/plugins/test_types_plugin.py @@ -92,12 +92,12 @@ class TypesPluginTest(unittest.TestCase, TestHelper): # Set true self.modify("mybool=1", "artist:true") true.load() - self.assertEqual(true["mybool"], True) + self.assertTrue(true["mybool"]) # Set false self.modify("mybool=false", "artist:false") false.load() - self.assertEqual(false["mybool"], False) + self.assertFalse(false["mybool"]) # Query bools out = self.list("mybool:true", "$artist $mybool") diff --git a/test/plugins/test_zero.py b/test/plugins/test_zero.py index f48675c5c..378e419d5 100644 --- a/test/plugins/test_zero.py +++ b/test/plugins/test_zero.py @@ -137,7 +137,7 @@ class ZeroPluginTest(unittest.TestCase, TestHelper): self.assertEqual(item["year"], 2016) self.assertEqual(mf.year, 2016) - self.assertEqual(mf.comments, None) + self.assertIsNone(mf.comments) self.assertEqual(item["comments"], "") def test_subcommand_update_database_false(self): @@ -161,7 +161,7 @@ class ZeroPluginTest(unittest.TestCase, TestHelper): self.assertEqual(item["year"], 2016) self.assertEqual(mf.year, 2016) self.assertEqual(item["comments"], "test comment") - self.assertEqual(mf.comments, None) + self.assertIsNone(mf.comments) def test_subcommand_query_include(self): item = self.add_item_fixture( @@ -180,7 +180,7 @@ class ZeroPluginTest(unittest.TestCase, TestHelper): mf = MediaFile(syspath(item.path)) self.assertEqual(mf.year, 2016) - self.assertEqual(mf.comments, None) + self.assertIsNone(mf.comments) def test_subcommand_query_exclude(self): item = self.add_item_fixture( @@ -251,7 +251,7 @@ class ZeroPluginTest(unittest.TestCase, TestHelper): z = ZeroPlugin() z.write_event(item, item.path, tags) - self.assertEqual(tags["comments"], None) + self.assertIsNone(tags["comments"]) self.assertEqual(tags["year"], 2016) def test_keep_fields_removes_preserved_tags(self): diff --git a/test/test_art_resize.py b/test/test_art_resize.py index 2f426a1dd..5cb1e7e69 100644 --- a/test/test_art_resize.py +++ b/test/test_art_resize.py @@ -129,7 +129,7 @@ class ArtResizerFileSizeTest(_common.TestCase, TestHelper): from PIL import Image with Image.open(path) as img: - self.assertFalse("progression" in img.info) + self.assertNotIn("progression", img.info) @unittest.skipUnless(IMBackend.available(), "ImageMagick not available") def test_im_file_deinterlace(self): @@ -146,7 +146,7 @@ class ArtResizerFileSizeTest(_common.TestCase, TestHelper): syspath(path, prefix=False), ] out = command_output(cmd).stdout - self.assertTrue(out == b"None") + self.assertEqual(out, b"None") @patch("beets.util.artresizer.util") def test_write_metadata_im(self, mock_util): diff --git a/test/test_autotag.py b/test/test_autotag.py index 6691348ed..868138411 100644 --- a/test/test_autotag.py +++ b/test/test_autotag.py @@ -42,7 +42,7 @@ class PluralityTest(_common.TestCase): def test_plurality_conflict(self): objs = [1, 1, 2, 2, 3] obj, freq = plurality(objs) - self.assertTrue(obj in (1, 2)) + self.assertIn(obj, (1, 2)) self.assertEqual(freq, 2) def test_plurality_empty_sequence_raises_error(self): @@ -279,9 +279,9 @@ class DistanceTest(_common.TestCase): dist.add("medium", 0.75) self.assertEqual(len(dist), 2) self.assertEqual(list(dist), [("album", 0.2), ("medium", 0.2)]) - self.assertTrue(dist == 0.4) - self.assertTrue(dist < 1.0) - self.assertTrue(dist > 0.0) + self.assertEqual(dist, 0.4) + self.assertLess(dist, 1.0) + self.assertGreater(dist, 0.0) self.assertEqual(dist - 0.4, 0.0) self.assertEqual(0.4 - dist, 0.0) self.assertEqual(float(dist), 0.4) @@ -394,7 +394,7 @@ class AlbumDistanceTest(_common.TestCase): dist = self._dist(items, info) self.assertNotEqual(dist, 0) # Make sure the distance is not too great - self.assertTrue(dist < 0.2) + self.assertLess(dist, 0.2) def test_global_artists_differ(self): items = [] @@ -1017,17 +1017,17 @@ class StringDistanceTest(unittest.TestCase): def test_leading_the_has_lower_weight(self): dist1 = string_dist("XXX Band Name", "Band Name") dist2 = string_dist("The Band Name", "Band Name") - self.assertTrue(dist2 < dist1) + self.assertLess(dist2, dist1) def test_parens_have_lower_weight(self): dist1 = string_dist("One .Two.", "One") dist2 = string_dist("One (Two)", "One") - self.assertTrue(dist2 < dist1) + self.assertLess(dist2, dist1) def test_brackets_have_lower_weight(self): dist1 = string_dist("One .Two.", "One") dist2 = string_dist("One [Two]", "One") - self.assertTrue(dist2 < dist1) + self.assertLess(dist2, dist1) def test_ep_label_has_zero_weight(self): dist = string_dist("My Song (EP)", "My Song") @@ -1036,7 +1036,7 @@ class StringDistanceTest(unittest.TestCase): def test_featured_has_lower_weight(self): dist1 = string_dist("My Song blah Someone", "My Song") dist2 = string_dist("My Song feat Someone", "My Song") - self.assertTrue(dist2 < dist1) + self.assertLess(dist2, dist1) def test_postfix_the(self): dist = string_dist("The Song Title", "Song Title, The") diff --git a/test/test_config_command.py b/test/test_config_command.py index 5ff9e6f4e..dc8e1de48 100644 --- a/test/test_config_command.py +++ b/test/test_config_command.py @@ -52,7 +52,7 @@ class ConfigCommandTest(unittest.TestCase, TestHelper): self.assertEqual(output["option"], "value") self.assertEqual(output["password"], "password_value") self.assertEqual(output["library"], "lib") - self.assertEqual(output["import"]["timid"], False) + self.assertFalse(output["import"]["timid"]) def test_show_user_config_with_cli(self): output = self._run_with_yaml_output( @@ -73,7 +73,7 @@ class ConfigCommandTest(unittest.TestCase, TestHelper): self.assertEqual(output["option"], "value") self.assertEqual(output["password"], "REDACTED") - self.assertEqual(output["import"]["timid"], False) + self.assertFalse(output["import"]["timid"]) def test_config_paths(self): output = self.run_with_output("config", "-p") diff --git a/test/test_dbcore.py b/test/test_dbcore.py index c98e9ceba..e5ab1910b 100644 --- a/test/test_dbcore.py +++ b/test/test_dbcore.py @@ -315,16 +315,16 @@ class ModelTest(unittest.TestCase): def test_delete_flexattr(self): model = ModelFixture1() model["foo"] = "bar" - self.assertTrue("foo" in model) + self.assertIn("foo", model) del model["foo"] - self.assertFalse("foo" in model) + self.assertNotIn("foo", model) def test_delete_flexattr_via_dot(self): model = ModelFixture1() model["foo"] = "bar" - self.assertTrue("foo" in model) + self.assertIn("foo", model) del model.foo - self.assertFalse("foo" in model) + self.assertNotIn("foo", model) def test_delete_flexattr_persists(self): model = ModelFixture1() @@ -337,7 +337,7 @@ class ModelTest(unittest.TestCase): model.store() model = self.db._get(ModelFixture1, model.id) - self.assertFalse("foo" in model) + self.assertNotIn("foo", model) def test_delete_non_existent_attribute(self): model = ModelFixture1() @@ -365,7 +365,7 @@ class ModelTest(unittest.TestCase): def test_null_value_stays_none_for_untyped_field(self): model = ModelFixture1() model.foo = None - self.assertEqual(model.foo, None) + self.assertIsNone(model.foo) def test_normalization_for_typed_flex_fields(self): model = ModelFixture1() diff --git a/test/test_files.py b/test/test_files.py index 8e84e2ea9..1b898dd9f 100644 --- a/test/test_files.py +++ b/test/test_files.py @@ -306,7 +306,7 @@ class AlbumFileTest(_common.TestCase): self.ai.move(basedir=self.otherdir) self.i.load() self.ai.store() - self.assertTrue(b"testotherdir" in self.i.path) + self.assertIn(b"testotherdir", self.i.path) class ArtFileTest(_common.TestCase): @@ -359,7 +359,7 @@ class ArtFileTest(_common.TestCase): self.assertNotExists(self.art) newart = self.lib.get_album(self.i).artpath self.assertExists(newart) - self.assertTrue(b"testotherdir" in newart) + self.assertIn(b"testotherdir", newart) def test_setart_copies_image(self): util.remove(self.art) @@ -372,7 +372,7 @@ class ArtFileTest(_common.TestCase): ai = self.lib.add_album((i2,)) i2.move(operation=MoveOperation.COPY) - self.assertEqual(ai.artpath, None) + self.assertIsNone(ai.artpath) ai.set_art(newart) self.assertExists(ai.artpath) @@ -478,7 +478,7 @@ class ArtFileTest(_common.TestCase): self.i.move() artpath = self.lib.albums()[0].artpath - self.assertFalse(b"different_album" in artpath) + self.assertNotIn(b"different_album", artpath) self.assertEqual(artpath, oldartpath) self.assertExists(oldartpath) diff --git a/test/test_importer.py b/test/test_importer.py index a381fc5f4..8809af49b 100644 --- a/test/test_importer.py +++ b/test/test_importer.py @@ -94,8 +94,8 @@ class ScrubbedImportTest(_common.TestCase, ImportHelper): for item in self.lib.items(): imported_file = os.path.join(item.path) imported_file = MediaFile(imported_file) - self.assertEqual(imported_file.artist, None) - self.assertEqual(imported_file.album, None) + self.assertIsNone(imported_file.artist) + self.assertIsNone(imported_file.album) @_common.slow_test() @@ -337,18 +337,18 @@ class ImportSingletonTest(_common.TestCase, ImportHelper): self.matcher.restore() def test_apply_asis_adds_track(self): - self.assertEqual(self.lib.items().get(), None) + self.assertIsNone(self.lib.items().get()) self.importer.add_choice(importer.action.ASIS) self.importer.run() self.assertEqual(self.lib.items().get().title, "Tag Title 1") def test_apply_asis_does_not_add_album(self): - self.assertEqual(self.lib.albums().get(), None) + self.assertIsNone(self.lib.albums().get()) self.importer.add_choice(importer.action.ASIS) self.importer.run() - self.assertEqual(self.lib.albums().get(), None) + self.assertIsNone(self.lib.albums().get()) def test_apply_asis_adds_singleton_path(self): self.assert_lib_dir_empty() @@ -358,7 +358,7 @@ class ImportSingletonTest(_common.TestCase, ImportHelper): self.assert_file_in_lib(b"singletons", b"Tag Title 1.mp3") def test_apply_candidate_adds_track(self): - self.assertEqual(self.lib.items().get(), None) + self.assertIsNone(self.lib.items().get()) self.importer.add_choice(importer.action.APPLY) self.importer.run() @@ -367,7 +367,7 @@ class ImportSingletonTest(_common.TestCase, ImportHelper): def test_apply_candidate_does_not_add_album(self): self.importer.add_choice(importer.action.APPLY) self.importer.run() - self.assertEqual(self.lib.albums().get(), None) + self.assertIsNone(self.lib.albums().get()) def test_apply_candidate_adds_singleton_path(self): self.assert_lib_dir_empty() @@ -379,7 +379,7 @@ class ImportSingletonTest(_common.TestCase, ImportHelper): def test_skip_does_not_add_first_track(self): self.importer.add_choice(importer.action.SKIP) self.importer.run() - self.assertEqual(self.lib.items().get(), None) + self.assertIsNone(self.lib.items().get()) def test_skip_adds_other_tracks(self): self._create_import_dir(2) @@ -418,7 +418,7 @@ class ImportSingletonTest(_common.TestCase, ImportHelper): } # As-is item import. - self.assertEqual(self.lib.albums().get(), None) + self.assertIsNone(self.lib.albums().get()) self.importer.add_choice(importer.action.ASIS) self.importer.run() @@ -431,7 +431,7 @@ class ImportSingletonTest(_common.TestCase, ImportHelper): item.remove() # Autotagged. - self.assertEqual(self.lib.albums().get(), None) + self.assertIsNone(self.lib.albums().get()) self.importer.clear_choices() self.importer.add_choice(importer.action.APPLY) self.importer.run() @@ -458,14 +458,14 @@ class ImportTest(_common.TestCase, ImportHelper): self.matcher.restore() def test_apply_asis_adds_album(self): - self.assertEqual(self.lib.albums().get(), None) + self.assertIsNone(self.lib.albums().get()) self.importer.add_choice(importer.action.ASIS) self.importer.run() self.assertEqual(self.lib.albums().get().album, "Tag Album") def test_apply_asis_adds_tracks(self): - self.assertEqual(self.lib.items().get(), None) + self.assertIsNone(self.lib.items().get()) self.importer.add_choice(importer.action.ASIS) self.importer.run() self.assertEqual(self.lib.items().get().title, "Tag Title 1") @@ -478,14 +478,14 @@ class ImportTest(_common.TestCase, ImportHelper): self.assert_file_in_lib(b"Tag Artist", b"Tag Album", b"Tag Title 1.mp3") def test_apply_candidate_adds_album(self): - self.assertEqual(self.lib.albums().get(), None) + self.assertIsNone(self.lib.albums().get()) self.importer.add_choice(importer.action.APPLY) self.importer.run() self.assertEqual(self.lib.albums().get().album, "Applied Album") def test_apply_candidate_adds_tracks(self): - self.assertEqual(self.lib.items().get(), None) + self.assertIsNone(self.lib.items().get()) self.importer.add_choice(importer.action.APPLY) self.importer.run() @@ -553,7 +553,7 @@ class ImportTest(_common.TestCase, ImportHelper): def test_skip_does_not_add_track(self): self.importer.add_choice(importer.action.SKIP) self.importer.run() - self.assertEqual(self.lib.items().get(), None) + self.assertIsNone(self.lib.items().get()) def test_skip_non_album_dirs(self): self.assertIsDir(os.path.join(self.import_dir, b"the_album")) @@ -590,7 +590,7 @@ class ImportTest(_common.TestCase, ImportHelper): self.assertIn(f"No files imported from {import_dir}", logs) def test_asis_no_data_source(self): - self.assertEqual(self.lib.items().get(), None) + self.assertIsNone(self.lib.items().get()) self.importer.add_choice(importer.action.ASIS) self.importer.run() @@ -611,7 +611,7 @@ class ImportTest(_common.TestCase, ImportHelper): } # As-is album import. - self.assertEqual(self.lib.albums().get(), None) + self.assertIsNone(self.lib.albums().get()) self.importer.add_choice(importer.action.ASIS) self.importer.run() @@ -634,7 +634,7 @@ class ImportTest(_common.TestCase, ImportHelper): album.remove() # Autotagged. - self.assertEqual(self.lib.albums().get(), None) + self.assertIsNone(self.lib.albums().get()) self.importer.clear_choices() self.importer.add_choice(importer.action.APPLY) self.importer.run() @@ -671,15 +671,15 @@ class ImportTracksTest(_common.TestCase, ImportHelper): self.matcher.restore() def test_apply_tracks_adds_singleton_track(self): - self.assertEqual(self.lib.items().get(), None) - self.assertEqual(self.lib.albums().get(), None) + self.assertIsNone(self.lib.items().get()) + self.assertIsNone(self.lib.albums().get()) self.importer.add_choice(importer.action.TRACKS) self.importer.add_choice(importer.action.APPLY) self.importer.add_choice(importer.action.APPLY) self.importer.run() self.assertEqual(self.lib.items().get().title, "Applied Title 1") - self.assertEqual(self.lib.albums().get(), None) + self.assertIsNone(self.lib.albums().get()) def test_apply_tracks_adds_singleton_path(self): self.assert_lib_dir_empty() @@ -1492,10 +1492,10 @@ class AlbumsInDirTest(_common.TestCase): found = [] for _, album in albums_in_dir(self.base): found.append(re.search(rb"album(.)song", album[0]).group(1)) - self.assertTrue(b"1" in found) - self.assertTrue(b"2" in found) - self.assertTrue(b"3" in found) - self.assertTrue(b"4" in found) + self.assertIn(b"1", found) + self.assertIn(b"2", found) + self.assertIn(b"3", found) + self.assertIn(b"4", found) def test_finds_multiple_songs(self): for _, album in albums_in_dir(self.base): diff --git a/test/test_library.py b/test/test_library.py index beb06971c..c9d0440b5 100644 --- a/test/test_library.py +++ b/test/test_library.py @@ -48,9 +48,9 @@ class LoadTest(_common.LibTestCase): def test_load_clears_dirty_flags(self): self.i.artist = "something" - self.assertTrue("artist" in self.i._dirty) + self.assertIn("artist", self.i._dirty) self.i.load() - self.assertTrue("artist" not in self.i._dirty) + self.assertNotIn("artist", self.i._dirty) class StoreTest(_common.LibTestCase): @@ -78,7 +78,7 @@ class StoreTest(_common.LibTestCase): def test_store_clears_dirty_flags(self): self.i.composer = "tvp" self.i.store() - self.assertTrue("composer" not in self.i._dirty) + self.assertNotIn("composer", self.i._dirty) def test_store_album_cascades_flex_deletes(self): album = _common.album() @@ -130,7 +130,7 @@ class RemoveTest(_common.LibTestCase): def test_remove_deletes_from_db(self): self.i.remove() c = self.lib._connection().execute("select * from items") - self.assertEqual(c.fetchone(), None) + self.assertIsNone(c.fetchone()) class GetSetTest(_common.TestCase): @@ -144,11 +144,11 @@ class GetSetTest(_common.TestCase): def test_set_sets_dirty_flag(self): self.i.comp = not self.i.comp - self.assertTrue("comp" in self.i._dirty) + self.assertIn("comp", self.i._dirty) def test_set_does_not_dirty_if_value_unchanged(self): self.i.title = self.i.title - self.assertTrue("title" not in self.i._dirty) + self.assertNotIn("title", self.i._dirty) def test_invalid_field_raises_attributeerror(self): self.assertRaises(AttributeError, getattr, self.i, "xyzzy") @@ -161,12 +161,12 @@ class GetSetTest(_common.TestCase): album["flex"] = "foo" album.store() - self.assertTrue("flex" in i) - self.assertFalse("flex" in i.keys(with_album=False)) + self.assertIn("flex", i) + self.assertNotIn("flex", i.keys(with_album=False)) self.assertEqual(i["flex"], "foo") self.assertEqual(i.get("flex"), "foo") - self.assertEqual(i.get("flex", with_album=False), None) - self.assertEqual(i.get("flexx"), None) + self.assertIsNone(i.get("flex", with_album=False)) + self.assertIsNone(i.get("flexx")) class DestinationTest(_common.TestCase): @@ -239,27 +239,27 @@ class DestinationTest(_common.TestCase): def test_destination_escapes_slashes(self): self.i.album = "one/two" dest = self.i.destination() - self.assertTrue(b"one" in dest) - self.assertTrue(b"two" in dest) - self.assertFalse(b"one/two" in dest) + self.assertIn(b"one", dest) + self.assertIn(b"two", dest) + self.assertNotIn(b"one/two", dest) def test_destination_escapes_leading_dot(self): self.i.album = ".something" dest = self.i.destination() - self.assertTrue(b"something" in dest) - self.assertFalse(b"/.something" in dest) + self.assertIn(b"something", 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.assertTrue(os.path.join(b"one", b"two") in dest) + self.assertIn(os.path.join(b"one", b"two"), dest) def test_destination_long_names_truncated(self): self.i.title = "X" * 300 self.i.artist = "Y" * 300 for c in self.i.destination().split(util.PATH_SEP): - self.assertTrue(len(c) <= 255) + self.assertLessEqual(len(c), 255) def test_destination_long_names_keep_extension(self): self.i.title = "X" * 300 @@ -271,15 +271,15 @@ class DestinationTest(_common.TestCase): self.i.title = "one \\ two / three.mp3" with _common.platform_windows(): p = self.i.destination() - self.assertFalse(b"one \\ two" in p) - self.assertFalse(b"one / two" in p) - self.assertFalse(b"two \\ three" in p) - self.assertFalse(b"two / three" in p) + self.assertNotIn(b"one \\ two", p) + self.assertNotIn(b"one / two", p) + self.assertNotIn(b"two \\ three", p) + self.assertNotIn(b"two / three", p) def test_path_with_format(self): self.lib.path_formats = [("default", "$artist/$album ($format)")] p = self.i.destination() - self.assertTrue(b"(FLAC)" in p) + self.assertIn(b"(FLAC)", p) def test_heterogeneous_album_gets_single_directory(self): i1, i2 = item(), item() @@ -435,9 +435,9 @@ class DestinationTest(_common.TestCase): self.i.title = "h\u0259d" self.lib.path_formats = [("default", "$title")] p = self.i.destination() - self.assertFalse(b"?" in p) + self.assertNotIn(b"?", p) # We use UTF-8 to encode Windows paths now. - self.assertTrue("h\u0259d".encode() in p) + self.assertIn("h\u0259d".encode(), p) finally: sys.getfilesystemencoding = oldfunc @@ -988,20 +988,20 @@ class AlbumInfoTest(_common.TestCase): c = self.lib._connection().cursor() c.execute("select * from albums where album=?", (self.i.album,)) # Cursor should only return one row. - self.assertNotEqual(c.fetchone(), None) - self.assertEqual(c.fetchone(), None) + self.assertIsNotNone(c.fetchone()) + self.assertIsNone(c.fetchone()) def test_individual_tracks_have_no_albuminfo(self): i2 = item() i2.album = "aTotallyDifferentAlbum" self.lib.add(i2) ai = self.lib.get_album(i2) - self.assertEqual(ai, None) + self.assertIsNone(ai) def test_get_album_by_id(self): ai = self.lib.get_album(self.i) ai = self.lib.get_album(self.i.id) - self.assertNotEqual(ai, None) + self.assertIsNotNone(ai) def test_album_items_consistent(self): ai = self.lib.get_album(self.i) @@ -1079,7 +1079,7 @@ class ArtDestinationTest(_common.TestCase): def test_art_filename_respects_setting(self): art = self.ai.art_destination("something.jpg") new_art = bytestring_path("%sartimage.jpg" % os.path.sep) - self.assertTrue(new_art in art) + self.assertIn(new_art, art) def test_art_path_in_item_dir(self): art = self.ai.art_destination("something.jpg") @@ -1089,7 +1089,7 @@ class ArtDestinationTest(_common.TestCase): def test_art_path_sanitized(self): config["art_filename"] = "artXimage" art = self.ai.art_destination("something.jpg") - self.assertTrue(b"artYimage" in art) + self.assertIn(b"artYimage", art) class PathStringTest(_common.TestCase): diff --git a/test/test_mb.py b/test/test_mb.py index 5290b3021..efd620522 100644 --- a/test/test_mb.py +++ b/test/test_mb.py @@ -318,7 +318,7 @@ class MBAlbumInfoTest(_common.TestCase): tracks = [self._make_track("TITLE", "ID", None)] release = self._make_release(tracks=tracks) d = mb.album_info(release) - self.assertEqual(d.tracks[0].length, None) + self.assertIsNone(d.tracks[0].length) def test_track_length_overrides_recording_length(self): tracks = [self._make_track("TITLE", "ID", 1.0 * 1000.0)] @@ -415,7 +415,7 @@ class MBAlbumInfoTest(_common.TestCase): release = self._make_release(None) del release["text-representation"]["language"] d = mb.album_info(release) - self.assertEqual(d.language, None) + self.assertIsNone(d.language) def test_parse_recording_artist(self): tracks = [self._make_track("a", "b", 1, True)] @@ -658,7 +658,7 @@ class MBAlbumInfoTest(_common.TestCase): d = mb.album_info(release) t = d.tracks self.assertEqual(len(t), 2) - self.assertEqual(t[0].trackdisambig, None) + self.assertIsNone(t[0].trackdisambig) self.assertEqual(t[1].trackdisambig, "SECOND TRACK") @@ -671,7 +671,7 @@ class ParseIDTest(_common.TestCase): def test_parse_id_non_id_returns_none(self): id_string = "blah blah" out = mb._parse_id(id_string) - self.assertEqual(out, None) + self.assertIsNone(out) def test_parse_id_url_finds_id(self): id_string = "28e32c71-1450-463e-92bf-e0a46446fc11" @@ -981,7 +981,7 @@ class MBLibraryTest(unittest.TestCase): with mock.patch("musicbrainzngs.get_release_by_id") as gp: gp.side_effect = side_effect album = mb.album_for_id("d2a6f856-b553-40a0-ac54-a321e8e2da02") - self.assertEqual(album.country, None) + self.assertIsNone(album.country) def test_pseudo_releases_without_links(self): side_effect = [ @@ -1025,7 +1025,7 @@ class MBLibraryTest(unittest.TestCase): with mock.patch("musicbrainzngs.get_release_by_id") as gp: gp.side_effect = side_effect album = mb.album_for_id("d2a6f856-b553-40a0-ac54-a321e8e2da02") - self.assertEqual(album.country, None) + self.assertIsNone(album.country) def test_pseudo_releases_with_unsupported_links(self): side_effect = [ @@ -1076,7 +1076,7 @@ class MBLibraryTest(unittest.TestCase): with mock.patch("musicbrainzngs.get_release_by_id") as gp: gp.side_effect = side_effect album = mb.album_for_id("d2a6f856-b553-40a0-ac54-a321e8e2da02") - self.assertEqual(album.country, None) + self.assertIsNone(album.country) def suite(): diff --git a/test/test_plugins.py b/test/test_plugins.py index 84f689342..b13df9607 100644 --- a/test/test_plugins.py +++ b/test/test_plugins.py @@ -167,7 +167,7 @@ class ItemTypeConflictTest(unittest.TestCase, TestHelper): self.advent_listener_plugin = AdventListenerPlugin self.register_plugin(EventListenerPlugin) self.register_plugin(AdventListenerPlugin) - self.assertNotEqual(None, plugins.types(Item)) + self.assertIsNotNone(plugins.types(Item)) class EventsTest(unittest.TestCase, ImportHelper, TestHelper): @@ -647,7 +647,7 @@ class ParseSpotifyIDTest(unittest.TestCase): def test_parse_id_non_id_returns_none(self): id_string = "blah blah" out = MetadataSourcePlugin._get_id("album", id_string, spotify_id_regex) - self.assertEqual(out, None) + self.assertIsNone(out) def test_parse_id_url_finds_id(self): id_string = "39WqpoPgZxygo6YQjehLJJ" @@ -665,7 +665,7 @@ class ParseDeezerIDTest(unittest.TestCase): def test_parse_id_non_id_returns_none(self): id_string = "blah blah" out = MetadataSourcePlugin._get_id("album", id_string, deezer_id_regex) - self.assertEqual(out, None) + self.assertIsNone(out) def test_parse_id_url_finds_id(self): id_string = "176356382" @@ -687,7 +687,7 @@ class ParseBeatportIDTest(unittest.TestCase): out = MetadataSourcePlugin._get_id( "album", id_string, beatport_id_regex ) - self.assertEqual(out, None) + self.assertIsNone(out) def test_parse_id_url_finds_id(self): id_string = "3089651" diff --git a/test/test_query.py b/test/test_query.py index 354d71dc8..b710da13b 100644 --- a/test/test_query.py +++ b/test/test_query.py @@ -67,7 +67,7 @@ class AnyFieldQueryTest(_common.LibTestCase): q = dbcore.query.AnyFieldQuery( "title", ["artist"], dbcore.query.SubstringQuery ) - self.assertEqual(self.lib.items(q).get(), None) + self.assertIsNone(self.lib.items(q).get()) def test_eq(self): q1 = dbcore.query.AnyFieldQuery( diff --git a/test/test_ui.py b/test/test_ui.py index 1aef8c9b3..915f47c69 100644 --- a/test/test_ui.py +++ b/test/test_ui.py @@ -64,7 +64,7 @@ class ListTest(unittest.TestCase): stdout = self._run_list(["na\xefve"]) out = stdout.getvalue() - self.assertTrue("na\xefve" in out) + self.assertIn("na\xefve", out) def test_list_item_path(self): stdout = self._run_list(fmt="$path") @@ -451,7 +451,7 @@ class WriteTest(unittest.TestCase, TestHelper): output = self.write_cmd() - self.assertTrue(f"{old_title} -> new title" in output) + self.assertIn(f"{old_title} -> new title", output) class MoveTest(_common.TestCase): @@ -494,42 +494,42 @@ class MoveTest(_common.TestCase): def test_move_item(self): self._move() self.i.load() - self.assertTrue(b"testlibdir" in self.i.path) + self.assertIn(b"testlibdir", 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.assertTrue(b"testlibdir" in self.i.path) + self.assertIn(b"testlibdir", 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.assertTrue(b"testlibdir" in self.i.path) + self.assertIn(b"testlibdir", 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.assertTrue(b"testlibdir" in self.i.path) + self.assertIn(b"testlibdir", 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.assertTrue(b"testotherdir" in self.i.path) + self.assertIn(b"testotherdir", 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.assertTrue(b"testotherdir" in self.i.path) + self.assertIn(b"testotherdir", self.i.path) self.assertExists(self.i.path) self.assertNotExists(self.itempath) @@ -648,7 +648,7 @@ class UpdateTest(_common.TestCase): mf.save() self._update(move=True) item = self.lib.items().get() - self.assertTrue(b"differentTitle" in item.path) + self.assertIn(b"differentTitle", item.path) def test_modified_metadata_not_moved(self): mf = MediaFile(syspath(self.i.path)) @@ -656,7 +656,7 @@ class UpdateTest(_common.TestCase): mf.save() self._update(move=False) item = self.lib.items().get() - self.assertTrue(b"differentTitle" not in item.path) + self.assertNotIn(b"differentTitle", item.path) def test_selective_modified_metadata_moved(self): mf = MediaFile(syspath(self.i.path)) @@ -665,7 +665,7 @@ class UpdateTest(_common.TestCase): mf.save() self._update(move=True, fields=["title"]) item = self.lib.items().get() - self.assertTrue(b"differentTitle" in item.path) + self.assertIn(b"differentTitle", item.path) self.assertNotEqual(item.genre, "differentGenre") def test_selective_modified_metadata_not_moved(self): @@ -675,7 +675,7 @@ class UpdateTest(_common.TestCase): mf.save() self._update(move=False, fields=["title"]) item = self.lib.items().get() - self.assertTrue(b"differentTitle" not in item.path) + self.assertNotIn(b"differentTitle", item.path) self.assertNotEqual(item.genre, "differentGenre") def test_modified_album_metadata_moved(self): @@ -684,7 +684,7 @@ class UpdateTest(_common.TestCase): mf.save() self._update(move=True) item = self.lib.items().get() - self.assertTrue(b"differentAlbum" in item.path) + self.assertIn(b"differentAlbum", item.path) def test_modified_album_metadata_art_moved(self): artpath = self.album.artpath @@ -703,7 +703,7 @@ class UpdateTest(_common.TestCase): mf.save() self._update(move=True, fields=["album"]) item = self.lib.items().get() - self.assertTrue(b"differentAlbum" in item.path) + self.assertIn(b"differentAlbum", item.path) self.assertNotEqual(item.genre, "differentGenre") def test_selective_modified_album_metadata_not_moved(self): @@ -713,7 +713,7 @@ class UpdateTest(_common.TestCase): mf.save() self._update(move=True, fields=["genre"]) item = self.lib.items().get() - self.assertTrue(b"differentAlbum" not in item.path) + self.assertNotIn(b"differentAlbum", item.path) self.assertEqual(item.genre, "differentGenre") def test_mtime_match_skips_update(self): @@ -1167,13 +1167,13 @@ class ShowModelChangeTest(_common.TestCase): self.b.title = "x" change, out = self._show() self.assertTrue(change) - self.assertTrue("title" in out) + self.assertIn("title", out) def test_int_fixed_field_change(self): self.b.track = 9 change, out = self._show() self.assertTrue(change) - self.assertTrue("track" in out) + self.assertIn("track", out) def test_floats_close_to_identical(self): self.a.length = 1.00001 @@ -1187,14 +1187,14 @@ class ShowModelChangeTest(_common.TestCase): self.b.length = 2.00001 change, out = self._show() self.assertTrue(change) - self.assertTrue("length" in out) + self.assertIn("length", out) def test_both_values_shown(self): self.a.title = "foo" self.b.title = "bar" change, out = self._show() - self.assertTrue("foo" in out) - self.assertTrue("bar" in out) + self.assertIn("foo", out) + self.assertIn("bar", out) class ShowChangeTest(_common.TestCase): @@ -1243,15 +1243,15 @@ class ShowChangeTest(_common.TestCase): def test_null_change(self): msg = self._show_change() - self.assertTrue("match (90.0%)" in msg) - self.assertTrue("album, artist" in msg) + self.assertIn("match (90.0%)", msg) + self.assertIn("album, artist", msg) def test_album_data_change(self): msg = self._show_change( cur_artist="another artist", cur_album="another album" ) - self.assertTrue("another artist -> the artist" in msg) - self.assertTrue("another album -> the album" in msg) + self.assertIn("another artist -> the artist", msg) + self.assertIn("another album -> the album", msg) def test_item_data_change(self): self.items[0].title = "different" @@ -1332,9 +1332,9 @@ class ShowChangeTest(_common.TestCase): cur_artist=long_name, cur_album="another album" ) # _common.log.info("Message:{}".format(msg)) - self.assertTrue("artist: another artist" in msg) - self.assertTrue(" -> the artist" in msg) - self.assertFalse("another album -> the album" in msg) + self.assertIn("artist: another artist", msg) + self.assertIn(" -> the artist", msg) + self.assertNotIn("another album -> the album", msg) def test_item_data_change_wrap_column(self): # Patch ui.term_width to force wrapping @@ -1344,8 +1344,8 @@ class ShowChangeTest(_common.TestCase): long_title = "a track with a" + (" very" * 10) + " long name" self.items[0].title = long_title msg = self._show_change() - self.assertTrue( - "(#1) a track (1:00) -> (#1) the title (0:00)" in msg + self.assertIn( + "(#1) a track (1:00) -> (#1) the title (0:00)", msg ) def test_item_data_change_wrap_newline(self): @@ -1355,8 +1355,8 @@ class ShowChangeTest(_common.TestCase): long_title = "a track with a" + (" very" * 10) + " long name" self.items[0].title = long_title msg = self._show_change() - self.assertTrue("(#1) a track with" in msg) - self.assertTrue(" -> (#1) the title (0:00)" in msg) + self.assertIn("(#1) a track with", msg) + self.assertIn(" -> (#1) the title (0:00)", msg) @patch("beets.library.Item.try_filesize", Mock(return_value=987)) diff --git a/test/test_util.py b/test/test_util.py index 69d4b14b2..bb5d1e691 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -51,28 +51,28 @@ class UtilTest(unittest.TestCase): def test_sanitize_unix_replaces_leading_dot(self): with _common.platform_posix(): p = util.sanitize_path("one/.two/three") - self.assertFalse("." in p) + self.assertNotIn(".", p) def test_sanitize_windows_replaces_trailing_dot(self): with _common.platform_windows(): p = util.sanitize_path("one/two./three") - self.assertFalse("." in p) + self.assertNotIn(".", p) def test_sanitize_windows_replaces_illegal_chars(self): with _common.platform_windows(): p = util.sanitize_path(':*?"<>|') - self.assertFalse(":" in p) - self.assertFalse("*" in p) - self.assertFalse("?" in p) - self.assertFalse('"' in p) - self.assertFalse("<" in p) - self.assertFalse(">" in p) - self.assertFalse("|" in p) + self.assertNotIn(":", p) + self.assertNotIn("*", p) + self.assertNotIn("?", p) + self.assertNotIn('"', p) + self.assertNotIn("<", p) + self.assertNotIn(">", p) + self.assertNotIn("|", p) def test_sanitize_windows_replaces_trailing_space(self): with _common.platform_windows(): p = util.sanitize_path("one/two /three") - self.assertFalse(" " in p) + self.assertNotIn(" ", p) def test_sanitize_path_works_on_empty_string(self): with _common.platform_posix():