Skip to content

Commit

Permalink
Merge pull request #1061 from sampsyo/types_conflict
Browse files Browse the repository at this point in the history
Allow plugins to define the same flexible fields if they are of the same type #1059
  • Loading branch information
sampsyo committed Nov 5, 2014
2 parents 559cccf + 2916753 commit e7d5d0e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
7 changes: 3 additions & 4 deletions beets/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,11 @@ def types(model_cls):
for plugin in find_plugins():
plugin_types = getattr(plugin, attr_name, {})
for field in plugin_types:
if field in types:
if field in types and plugin_types[field] != types[field]:
raise PluginConflictException(
u'Plugin {0} defines flexible field {1} '
'which has already been defined.'.format(
plugin.name, field
)
'which has already been defined with '
'another type.'.format(plugin.name, field)
)
types.update(plugin_types)
return types
Expand Down
39 changes: 39 additions & 0 deletions test/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,45 @@ def register_listener(self, event, func):
self.event_listener_plugin.register_listener(event, func)


class ItemTypeConflictTest(unittest.TestCase, TestHelper):

def setUp(self):
self.setup_plugin_loader()
self.setup_beets()

def tearDown(self):
self.teardown_plugin_loader()
self.teardown_beets()

def test_mismatch(self):
class EventListenerPlugin(plugins.BeetsPlugin):
item_types = {'duplicate': types.INTEGER}

class AdventListenerPlugin(plugins.BeetsPlugin):
item_types = {'duplicate': types.FLOAT}

self.event_listener_plugin = EventListenerPlugin
self.advent_listener_plugin = AdventListenerPlugin
self.register_plugin(EventListenerPlugin)
self.register_plugin(AdventListenerPlugin)
self.assertRaises(plugins.PluginConflictException,
plugins.types, Item
)

def test_match(self):
class EventListenerPlugin(plugins.BeetsPlugin):
item_types = {'duplicate': types.INTEGER}

class AdventListenerPlugin(plugins.BeetsPlugin):
item_types = {'duplicate': types.INTEGER}

self.event_listener_plugin = EventListenerPlugin
self.advent_listener_plugin = AdventListenerPlugin
self.register_plugin(EventListenerPlugin)
self.register_plugin(AdventListenerPlugin)
self.assertNotEqual(None, plugins.types(Item))


def suite():
return unittest.TestLoader().loadTestsFromName(__name__)

Expand Down

0 comments on commit e7d5d0e

Please sign in to comment.