Skip to content

Commit

Permalink
Allow plugins to define the same flexible fields if they are of the same
Browse files Browse the repository at this point in the history
type #1059
  • Loading branch information
pscn committed Nov 4, 2014
1 parent 559cccf commit 2916753
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 2916753

Please sign in to comment.