diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index d6f4c08a3..cbaa972ca 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -141,8 +141,8 @@ class LastGenrePlugin(plugins.BeetsPlugin): c14n_filename = C14N_TREE if c14n_filename: c14n_filename = normpath(c14n_filename) - genres_file = codecs.open(c14n_filename, 'r', encoding='utf-8') - genres_tree = yaml.load(genres_file) + with codecs.open(c14n_filename, 'r', encoding='utf-8') as f: + genres_tree = yaml.load(f) flatten_tree(genres_tree, [], self.c14n_branches) @property diff --git a/test/test_mediafile_edge.py b/test/test_mediafile_edge.py index 173a0d063..fea7aebad 100644 --- a/test/test_mediafile_edge.py +++ b/test/test_mediafile_edge.py @@ -87,8 +87,9 @@ class EdgeTest(unittest.TestCase): # such aren't recognized by imghdr. Ensure that this still works thanks # to our own follow up mimetype detection based on # https://github.com/file/file/blob/master/magic/Magdir/jpeg#L12 - f = open(os.path.join(_common.RSRC, b'only-magic-bytes.jpg'), 'rb') - jpg_data = f.read() + magic_bytes_file = os.path.join(_common.RSRC, b'only-magic-bytes.jpg') + with open(magic_bytes_file, 'rb') as f: + jpg_data = f.read() self.assertEqual( beets.mediafile._image_mime_type(jpg_data), 'image/jpeg') diff --git a/test/test_play.py b/test/test_play.py index 38524aa7d..259e59383 100644 --- a/test/test_play.py +++ b/test/test_play.py @@ -88,10 +88,11 @@ class PlayPluginTest(unittest.TestCase, TestHelper): self.run_command('play', '-a', 'nice') open_mock.assert_called_once_with(ANY, open_anything()) - playlist = open(open_mock.call_args[0][0][0], 'rb') + with open(open_mock.call_args[0][0][0], 'rb') as f: + playlist = f.read().decode('utf-8') self.assertEqual(u'{}\n'.format( os.path.dirname(self.item.path.decode('utf-8'))), - playlist.read().decode('utf-8')) + playlist) def test_raw(self, open_mock): self.config['play']['raw'] = True