Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_flex_field_type(self):
class RatingPlugin(plugins.BeetsPlugin):
item_types = {'rating': types.Float()}
self.register_plugin(RatingPlugin)
self.config['plugins'] = 'rating'
item = Item(path=u'apath', artist=u'aaa')
item.add(self.lib)
# Do not match unset values
out = self.run_with_output(u'ls', u'rating:1..3')
self.assertNotIn(u'aaa', out)
self.run_command(u'modify', u'rating=2', u'--yes')
# Match in range
out = self.run_with_output(u'ls', u'rating:1..3')
self.assertIn(u'aaa', out)
# Don't match out of range
out = self.run_with_output(u'ls', u'rating:3..5')
self.assertNotIn(u'aaa', out)
def test_matches(self):
spl = SmartPlaylistPlugin()
a = MagicMock(Album)
i = MagicMock(Item)
self.assertFalse(spl.matches(i, None, None))
self.assertFalse(spl.matches(a, None, None))
query = Mock()
query.match.side_effect = {i: True}.__getitem__
self.assertTrue(spl.matches(i, query, None))
self.assertFalse(spl.matches(a, query, None))
a_query = Mock()
a_query.match.side_effect = {a: True}.__getitem__
self.assertFalse(spl.matches(i, None, a_query))
self.assertTrue(spl.matches(a, None, a_query))
self.assertTrue(spl.matches(i, query, a_query))
self.assertTrue(spl.matches(a, query, a_query))
def boracay(l): return beets.library.Item(l.conn.execute('select * from items '
'where id=3').fetchone())
def add_album_fixture(self, track_count=1, ext='mp3'):
"""Add an album with files to the database.
"""
items = []
path = os.path.join(_common.RSRC, 'full.' + ext)
for i in range(track_count):
item = Item.from_path(str(path))
item.album = u'\u00e4lbum' # Check unicode paths
item.title = u't\u00eftle {0}'.format(i)
item.add(self.lib)
item.move(copy=True)
item.store()
items.append(item)
return self.lib.add_album(items)
# requires parsing the configuration.
if ctx.invoked_subcommand == 'config':
return
# Configure the MusicBrainz API.
mb.configure()
# Open the library database and set it on the context
# if we didn't already get it from the test suite.
if not beets_ctx.lib:
beets_ctx.lib = _open_library(config)
plugins.send('library_opened', lib=beets_ctx.lib)
# Load field types from the plugins.
library.Item._types.update(plugins.types(library.Item))
library.Album._types.update(plugins.types(library.Album))
# Tell plugins when the subcommand invocation is finished.
@ctx.call_on_close
def send_plugin_cli_exit():
plugins.send('cli_exit', lib=beets_ctx.lib)
def track_to_item(track):
data = {}
for dname, bname in FIELD_MAP.items():
data[bname] = track[dname]
data['length'] = float(track['tracklen']) / 1000
data['path'] = track.ipod_filename()
return Item(data)
def _get_fields(only_writable):
# I have seen it suggested that this is currently the thing to do.
# Notably you cannot use library.MediaFile.fields(), which returns
# fields that don't exist on Items such as "date", or so I've
# decided based on experimental evidence.
return [field for field in library.Item._fields.keys()
if not only_writable or field not in READ_ONLY_FIELDS]
# Start generating the script
yield u"_beet() {\n"
# Command names
yield u" local commands='%s'\n" % ' '.join(command_names)
yield u"\n"
# Command aliases
yield u" local aliases='%s'\n" % ' '.join(aliases.keys())
for alias, cmd in aliases.items():
yield u" local alias__%s=%s\n" % (alias, cmd)
yield u'\n'
# Fields
yield u" fields='%s'\n" % ' '.join(
set(library.Item._fields.keys() + library.Album._fields.keys())
)
# Command options
for cmd, opts in options.items():
for option_type, option_list in opts.items():
if option_list:
option_list = ' '.join(option_list)
yield u" local %s__%s='%s'\n" % (
option_type, cmd, option_list)
yield u' _beet_dispatch\n'
yield u'}\n'
def _merge(self, objs):
"""Merge duplicate items. See ``_merge_items`` and ``_merge_albums``
for the relevant strategies.
"""
kind = Item if all(isinstance(o, Item) for o in objs) else Album
if kind is Item:
objs = self._merge_items(objs)
else:
objs = self._merge_albums(objs)
return objs