Replace assertIsNotNone

This commit is contained in:
Šarūnas Nejus 2024-07-29 01:15:58 +01:00
parent 5d4911e905
commit 2616bcc950
No known key found for this signature in database
GPG key ID: DD28F6704DBE3435
9 changed files with 36 additions and 35 deletions

View file

@ -214,7 +214,7 @@ class FetchImageTest(FetchImageTestCase):
def test_jpeg_type_returns_path(self): def test_jpeg_type_returns_path(self):
self.mock_response(self.URL, "image/jpeg") self.mock_response(self.URL, "image/jpeg")
self.source.fetch_image(self.candidate, self.settings) self.source.fetch_image(self.candidate, self.settings)
self.assertIsNotNone(self.candidate.path) assert self.candidate.path is not None
def test_extension_set_by_content_type(self): def test_extension_set_by_content_type(self):
self.mock_response(self.URL, "image/png") self.mock_response(self.URL, "image/png")
@ -294,7 +294,7 @@ class CombinedTest(FetchImageTestCase, CAAHelper):
self.mock_response(self.AMAZON_URL) self.mock_response(self.AMAZON_URL)
album = _common.Bag(asin=self.ASIN) album = _common.Bag(asin=self.ASIN)
candidate = self.plugin.art_for_album(album, None) candidate = self.plugin.art_for_album(album, None)
self.assertIsNotNone(candidate) assert candidate is not None
def test_main_interface_returns_none_for_missing_asin_and_path(self): def test_main_interface_returns_none_for_missing_asin_and_path(self):
album = _common.Bag() album = _common.Bag()
@ -306,14 +306,14 @@ class CombinedTest(FetchImageTestCase, CAAHelper):
self.mock_response(self.AMAZON_URL) self.mock_response(self.AMAZON_URL)
album = _common.Bag(asin=self.ASIN) album = _common.Bag(asin=self.ASIN)
candidate = self.plugin.art_for_album(album, [self.dpath]) candidate = self.plugin.art_for_album(album, [self.dpath])
self.assertIsNotNone(candidate) assert candidate is not None
self.assertEqual(candidate.path, os.path.join(self.dpath, b"art.jpg")) self.assertEqual(candidate.path, os.path.join(self.dpath, b"art.jpg"))
def test_main_interface_falls_back_to_amazon(self): def test_main_interface_falls_back_to_amazon(self):
self.mock_response(self.AMAZON_URL) self.mock_response(self.AMAZON_URL)
album = _common.Bag(asin=self.ASIN) album = _common.Bag(asin=self.ASIN)
candidate = self.plugin.art_for_album(album, [self.dpath]) candidate = self.plugin.art_for_album(album, [self.dpath])
self.assertIsNotNone(candidate) assert candidate is not None
assert not candidate.path.startswith(self.dpath) assert not candidate.path.startswith(self.dpath)
def test_main_interface_tries_amazon_before_aao(self): def test_main_interface_tries_amazon_before_aao(self):
@ -346,7 +346,7 @@ class CombinedTest(FetchImageTestCase, CAAHelper):
asin=self.ASIN, asin=self.ASIN,
) )
candidate = self.plugin.art_for_album(album, None) candidate = self.plugin.art_for_album(album, None)
self.assertIsNotNone(candidate) assert candidate is not None
self.assertEqual(len(responses.calls), 3) self.assertEqual(len(responses.calls), 3)
self.assertEqual(responses.calls[0].request.url, self.RELEASE_URL) self.assertEqual(responses.calls[0].request.url, self.RELEASE_URL)
@ -361,7 +361,7 @@ class CombinedTest(FetchImageTestCase, CAAHelper):
candidate = self.plugin.art_for_album( candidate = self.plugin.art_for_album(
album, [self.dpath], local_only=True album, [self.dpath], local_only=True
) )
self.assertIsNotNone(candidate) assert candidate is not None
self.assertEqual(candidate.path, os.path.join(self.dpath, b"art.jpg")) self.assertEqual(candidate.path, os.path.join(self.dpath, b"art.jpg"))
self.assertEqual(len(responses.calls), 0) self.assertEqual(len(responses.calls), 0)

View file

@ -121,7 +121,7 @@ class ImportConvertTest(AsIsImporterMixin, ImportHelper, ConvertTestCase):
self.run_asis_importer() self.run_asis_importer()
item = self.lib.items().get() item = self.lib.items().get()
self.assertIsNotNone(item) assert item is not None
self.assertIsFile(item.path) self.assertIsFile(item.path)
def test_delete_originals(self): def test_delete_originals(self):

View file

@ -70,7 +70,7 @@ class ExportPluginTest(PluginTestCase):
head = re.split(",", csv_list[0]) head = re.split(",", csv_list[0])
vals = re.split(",|\r", csv_list[1]) vals = re.split(",|\r", csv_list[1])
for index, column in enumerate(head): for index, column in enumerate(head):
self.assertIsNotNone(self.test_values.get(column, None)) assert self.test_values.get(column, None) is not None
self.assertEqual(vals[index], self.test_values[column]) self.assertEqual(vals[index], self.test_values[column])
def test_xml_output(self): def test_xml_output(self):

View file

@ -488,7 +488,7 @@ class GeniusScrapeLyricsFromHtmlTest(GeniusBaseTest):
url = "https://genius.com/Ttng-chinchilla-lyrics" url = "https://genius.com/Ttng-chinchilla-lyrics"
mock = MockFetchUrl() mock = MockFetchUrl()
lyrics = genius._scrape_lyrics_from_html(mock(url)) lyrics = genius._scrape_lyrics_from_html(mock(url))
self.assertIsNotNone(lyrics) assert lyrics is not None
self.assertEqual(lyrics.count("\n"), 28) self.assertEqual(lyrics.count("\n"), 28)
def test_good_lyrics_multiple_divs(self): def test_good_lyrics_multiple_divs(self):
@ -496,7 +496,7 @@ class GeniusScrapeLyricsFromHtmlTest(GeniusBaseTest):
url = "https://genius.com/2pac-all-eyez-on-me-lyrics" url = "https://genius.com/2pac-all-eyez-on-me-lyrics"
mock = MockFetchUrl() mock = MockFetchUrl()
lyrics = genius._scrape_lyrics_from_html(mock(url)) lyrics = genius._scrape_lyrics_from_html(mock(url))
self.assertIsNotNone(lyrics) assert lyrics is not None
self.assertEqual(lyrics.count("\n"), 133) self.assertEqual(lyrics.count("\n"), 133)
# TODO: find an example of a lyrics page with multiple divs and test it # TODO: find an example of a lyrics page with multiple divs and test it
@ -540,12 +540,12 @@ class GeniusFetchTest(GeniusBaseTest):
) as mock_json: ) as mock_json:
# genius uses zero-width-spaces (\u200B) for lowercase # genius uses zero-width-spaces (\u200B) for lowercase
# artists so we make sure we can match those # artists so we make sure we can match those
self.assertIsNotNone(genius.fetch("blackbear", "Idfc")) assert genius.fetch("blackbear", "Idfc") is not None
mock_fetch_url.assert_called_once_with("blackbear_url") mock_fetch_url.assert_called_once_with("blackbear_url")
mock_scrape.assert_called_once_with(True) mock_scrape.assert_called_once_with(True)
# genius uses the hyphen minus (\u002D) as their dash # genius uses the hyphen minus (\u002D) as their dash
self.assertIsNotNone(genius.fetch("El-p", "Idfc")) assert genius.fetch("El-p", "Idfc") is not None
mock_fetch_url.assert_called_with("El-p_url") mock_fetch_url.assert_called_with("El-p_url")
mock_scrape.assert_called_with(True) mock_scrape.assert_called_with(True)
@ -584,8 +584,9 @@ class TekstowoExtractLyricsTest(TekstowoBaseTest):
"""Ensure we are able to scrape a page with lyrics""" """Ensure we are able to scrape a page with lyrics"""
url = "https://www.tekstowo.pl/piosenka,24kgoldn,city_of_angels_1.html" url = "https://www.tekstowo.pl/piosenka,24kgoldn,city_of_angels_1.html"
mock = MockFetchUrl() mock = MockFetchUrl()
self.assertIsNotNone( assert (
tekstowo.extract_lyrics(mock(url), "24kGoldn", "City of Angels") tekstowo.extract_lyrics(mock(url), "24kGoldn", "City of Angels")
is not None
) )
def test_no_lyrics(self): def test_no_lyrics(self):

View file

@ -146,8 +146,8 @@ class ReplayGainCliTest:
self.skipTest("decoder plugins could not be loaded.") self.skipTest("decoder plugins could not be loaded.")
for item in self.lib.items(): for item in self.lib.items():
self.assertIsNotNone(item.rg_track_peak) assert item.rg_track_peak is not None
self.assertIsNotNone(item.rg_track_gain) assert item.rg_track_gain is not None
mediafile = MediaFile(item.path) mediafile = MediaFile(item.path)
self.assertAlmostEqual( self.assertAlmostEqual(
mediafile.rg_track_peak, item.rg_track_peak, places=6 mediafile.rg_track_peak, item.rg_track_peak, places=6
@ -167,8 +167,8 @@ class ReplayGainCliTest:
self.run_command("replaygain") self.run_command("replaygain")
item_rg.load() item_rg.load()
self.assertIsNotNone(item_rg.rg_track_gain) assert item_rg.rg_track_gain is not None
self.assertIsNotNone(item_rg.rg_track_peak) assert item_rg.rg_track_peak is not None
assert item_rg.r128_track_gain is None assert item_rg.r128_track_gain is None
item_rg.rg_track_gain += 1.0 item_rg.rg_track_gain += 1.0
@ -179,7 +179,7 @@ class ReplayGainCliTest:
if self.has_r128_support: if self.has_r128_support:
item_r128.load() item_r128.load()
self.assertIsNotNone(item_r128.r128_track_gain) assert item_r128.r128_track_gain is not None
assert item_r128.rg_track_gain is None assert item_r128.rg_track_gain is None
assert item_r128.rg_track_peak is None assert item_r128.rg_track_peak is None
@ -225,12 +225,12 @@ class ReplayGainCliTest:
item_rg.load() item_rg.load()
item_r128.load() item_r128.load()
self.assertIsNotNone(item_rg.rg_track_gain) assert item_rg.rg_track_gain is not None
self.assertIsNotNone(item_rg.rg_track_peak) assert item_rg.rg_track_peak is not None
# FIXME: Should the plugin null this field? # FIXME: Should the plugin null this field?
# assert item_rg.r128_track_gain is None # assert item_rg.r128_track_gain is None
self.assertIsNotNone(item_r128.r128_track_gain) assert item_r128.r128_track_gain is not None
# FIXME: Should the plugin null these fields? # FIXME: Should the plugin null these fields?
# assert item_r128.rg_track_gain is None # assert item_r128.rg_track_gain is None
# assert item_r128.rg_track_peak is None # assert item_r128.rg_track_peak is None
@ -277,8 +277,8 @@ class ReplayGainCliTest:
assert mediafile.rg_track_gain is None assert mediafile.rg_track_gain is None
assert mediafile.rg_album_gain is None assert mediafile.rg_album_gain is None
# writes R128_* tags # writes R128_* tags
self.assertIsNotNone(mediafile.r128_track_gain) assert mediafile.r128_track_gain is not None
self.assertIsNotNone(mediafile.r128_album_gain) assert mediafile.r128_album_gain is not None
def test_targetlevel_has_effect(self): def test_targetlevel_has_effect(self):
album = self._add_album(1) album = self._add_album(1)
@ -326,8 +326,8 @@ class ReplayGainCliTest:
# FIXME: Add fixtures with known track/album gain (within a suitable # FIXME: Add fixtures with known track/album gain (within a suitable
# tolerance) so that we can actually check per-disc operation here. # tolerance) so that we can actually check per-disc operation here.
for item in album.items(): for item in album.items():
self.assertIsNotNone(item.rg_track_gain) assert item.rg_track_gain is not None
self.assertIsNotNone(item.rg_album_gain) assert item.rg_album_gain is not None
@unittest.skipIf(not GST_AVAILABLE, "gstreamer cannot be found") @unittest.skipIf(not GST_AVAILABLE, "gstreamer cannot be found")
@ -365,8 +365,8 @@ class ImportTest(AsIsImporterMixin):
# FIXME: Add fixtures with known track/album gain (within a # FIXME: Add fixtures with known track/album gain (within a
# suitable tolerance) so that we can actually check correct # suitable tolerance) so that we can actually check correct
# operation here. # operation here.
self.assertIsNotNone(item.rg_track_gain) assert item.rg_track_gain is not None
self.assertIsNotNone(item.rg_album_gain) assert item.rg_album_gain is not None
@unittest.skipIf(not GST_AVAILABLE, "gstreamer cannot be found") @unittest.skipIf(not GST_AVAILABLE, "gstreamer cannot be found")

View file

@ -1343,11 +1343,11 @@ class ResumeImportTest(ImportTestCase):
self.importer.run() self.importer.run()
self.assertEqual(len(self.lib.albums()), 1) self.assertEqual(len(self.lib.albums()), 1)
self.assertIsNotNone(self.lib.albums("album:'Album 1'").get()) assert self.lib.albums("album:'Album 1'").get() is not None
self.importer.run() self.importer.run()
self.assertEqual(len(self.lib.albums()), 2) self.assertEqual(len(self.lib.albums()), 2)
self.assertIsNotNone(self.lib.albums("album:'Album 2'").get()) assert self.lib.albums("album:'Album 2'").get() is not None
@patch("beets.plugins.send") @patch("beets.plugins.send")
def test_resume_singleton(self, plugins_send): def test_resume_singleton(self, plugins_send):
@ -1366,11 +1366,11 @@ class ResumeImportTest(ImportTestCase):
self.importer.run() self.importer.run()
self.assertEqual(len(self.lib.items()), 1) self.assertEqual(len(self.lib.items()), 1)
self.assertIsNotNone(self.lib.items("title:'Track 1'").get()) assert self.lib.items("title:'Track 1'").get() is not None
self.importer.run() self.importer.run()
self.assertEqual(len(self.lib.items()), 2) self.assertEqual(len(self.lib.items()), 2)
self.assertIsNotNone(self.lib.items("title:'Track 1'").get()) assert self.lib.items("title:'Track 1'").get() is not None
class IncrementalImportTest(AsIsImporterMixin, ImportTestCase): class IncrementalImportTest(AsIsImporterMixin, ImportTestCase):

View file

@ -963,7 +963,7 @@ class AlbumInfoTest(BeetsTestCase):
c = self.lib._connection().cursor() c = self.lib._connection().cursor()
c.execute("select * from albums where album=?", (self.i.album,)) c.execute("select * from albums where album=?", (self.i.album,))
# Cursor should only return one row. # Cursor should only return one row.
self.assertIsNotNone(c.fetchone()) assert c.fetchone() is not None
assert c.fetchone() is None assert c.fetchone() is None
def test_individual_tracks_have_no_albuminfo(self): def test_individual_tracks_have_no_albuminfo(self):
@ -976,7 +976,7 @@ class AlbumInfoTest(BeetsTestCase):
def test_get_album_by_id(self): def test_get_album_by_id(self):
ai = self.lib.get_album(self.i) ai = self.lib.get_album(self.i)
ai = self.lib.get_album(self.i.id) ai = self.lib.get_album(self.i.id)
self.assertIsNotNone(ai) assert ai is not None
def test_album_items_consistent(self): def test_album_items_consistent(self):
ai = self.lib.get_album(self.i) ai = self.lib.get_album(self.i)

View file

@ -154,7 +154,7 @@ class ItemTypeConflictTest(PluginLoaderTestCase):
self.advent_listener_plugin = AdventListenerPlugin self.advent_listener_plugin = AdventListenerPlugin
self.register_plugin(EventListenerPlugin) self.register_plugin(EventListenerPlugin)
self.register_plugin(AdventListenerPlugin) self.register_plugin(AdventListenerPlugin)
self.assertIsNotNone(plugins.types(Item)) assert plugins.types(Item) is not None
class EventsTest(PluginImportTestCase): class EventsTest(PluginImportTestCase):

View file

@ -675,7 +675,7 @@ class UpdateTest(BeetsTestCase):
self._update(move=True) self._update(move=True)
album = self.lib.albums()[0] album = self.lib.albums()[0]
self.assertNotEqual(artpath, album.artpath) self.assertNotEqual(artpath, album.artpath)
self.assertIsNotNone(album.artpath) assert album.artpath is not None
def test_selective_modified_album_metadata_moved(self): def test_selective_modified_album_metadata_moved(self):
mf = MediaFile(syspath(self.i.path)) mf = MediaFile(syspath(self.i.path))