close files we open, but forgot to close

This fixes all the obvious `ResourceWarning`s seen in the tests
This commit is contained in:
Johnny Robeson 2016-08-09 01:15:28 -04:00
parent fcbfce3984
commit d41949d326
3 changed files with 8 additions and 6 deletions

View file

@ -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

View file

@ -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')

View file

@ -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