예제 #1
0
    def test_load(self, signal, pkg_resources, logger):
        entry_points = [
            Mock(load=lambda: 'foo'),
            Mock(load=lambda: 'snowman'),
            Mock(),
        ]
        entry_points[0].name = 'foo'
        entry_points[1].name = self.snowman

        # Exceptions should not bomb the load process
        entry_points[2].name = 'bar'
        entry_points[2].load.side_effect = Exception

        pkg_resources.iter_entry_points.return_value = entry_points

        with patch.multiple(registry,
                            register=Mock(),
                            whitelist_plugins=set(['foo', self.snowman,
                                                   'bar']),
                            blacklist_plugins=set()):
            registry.load()
            registry.register.assert_has_calls([
                call('foo', 'foo'),
                call(self.snowman, 'snowman'),
            ])

            logger.exception.assert_called_with('Error initializing plugin %s',
                                                entry_points[2])

        # Ensure that we sent the signal
        signal.emit.assert_called_with('plugins_loaded')
예제 #2
0
    def test_load_skips_blacklisted(self, pkg_resources):
        entry_points = [
            Mock(),
            Mock(),
            Mock(),
        ]

        entry_points[0].name = 'foo'
        entry_points[1].name = 'bar'
        entry_points[2].name = 'baz'

        whitelist = ['a', 'b', 'c']
        blacklist = ['foo', 'bar', 'baz']

        pkg_resources.iter_entry_points.return_value = entry_points

        with patch.multiple(registry,
                            whitelist_plugins=whitelist,
                            blacklist_plugins=blacklist):
            registry.load()
            assert not any([
                entry_points[0].load.called,
                entry_points[1].load.called,
                entry_points[2].load.called,
            ])
예제 #3
0
    def test_load(self, signal, pkg_resources, logger):
        entry_points = [
            Mock(load=lambda: 'foo'),
            Mock(load=lambda: 'snowman'),
            Mock(),
        ]
        entry_points[0].name = 'foo'
        entry_points[1].name = self.snowman

        # Exceptions should not bomb the load process
        entry_points[2].name = 'bar'
        entry_points[2].load.side_effect = Exception

        pkg_resources.iter_entry_points.return_value = entry_points

        with patch.multiple(registry,
                            register=Mock(),
                            whitelist_plugins=set(['foo', self.snowman, 'bar']),
                            blacklist_plugins=set()):
            registry.load()
            registry.register.assert_has_calls([
                call('foo', 'foo'),
                call(self.snowman, 'snowman'),
            ])

            logger.exception.assert_called_with('Error initializing plugin %s', entry_points[2])

        # Ensure that we sent the signal
        signal.emit.assert_called_with('plugins_loaded')
예제 #4
0
    def test_load_with_no_whitelist(self, pkg_resources):
        entry_points = [
            Mock(),
            Mock(),
            Mock(),
        ]

        with patch.object(registry, 'whitelist_plugins', []):
            registry.load()
            assert not any([
                entry_points[0].load.called,
                entry_points[1].load.called,
                entry_points[2].load.called,
            ])
예제 #5
0
    def test_load_with_no_whitelist(self, pkg_resources):
        entry_points = [
            Mock(),
            Mock(),
            Mock(),
        ]

        with patch.object(registry, 'whitelist_plugins', []):
            registry.load()
            assert not any([
                entry_points[0].load.called,
                entry_points[1].load.called,
                entry_points[2].load.called,
            ])
예제 #6
0
    def test_load_skips_non_whitelist(self, pkg_resources):
        entry_points = [
            Mock(),
            Mock(),
            Mock(),
        ]

        entry_points[0].name = 'foo'
        entry_points[1].name = 'bar'
        entry_points[2].name = 'baz'

        pkg_resources.iter_entry_points.return_value = entry_points

        whitelist = ['a', 'b', 'c']

        with patch.multiple(registry, whitelist_plugins=whitelist, blacklist_plugins=[]):
            registry.load()
            assert not any([
                entry_points[0].load.called,
                entry_points[1].load.called,
                entry_points[2].load.called,
            ])
예제 #7
0
    def test_load(self, signal, pkg_resources):
        entry_points = [
            Mock(load=lambda: 'foo'),
            Mock(load=lambda: 'snowman'),
            Mock(),
        ]
        entry_points[0].name = 'foo'
        entry_points[1].name = self.snowman

        # Exceptions should not bomb the load process
        entry_points[2].name = 'bar'
        entry_points[2].load.side_effect = Exception

        pkg_resources.iter_entry_points.return_value = entry_points

        with patch.object(registry, 'register') as register:
            registry.load()
            assert ('foo', 'foo') == register.call_args_list[0][0]
            assert (self.snowman, 'snowman') == register.call_args_list[1][0]
            assert len(register.call_args_list) == 2  # Only the first two

        # Ensure that we sent the signal
        signal.emit.assert_called_with('plugins_loaded')