예제 #1
0
    def test_source_plugin_missing_init_file(self):
        plugin_manager = PluginManager('')

        with mock.patch('compose.plugin_manager.os.path.isfile') as mock_isfile:
            mock_isfile.return_value = False

            with self.assertRaises(InvalidPluginError) as e:
                plugin_manager._source_plugin('plugin_path')

            self.assertEqual(str(e.exception), "Missing __init__.py file.")
예제 #2
0
    def test_source_plugin_invalid_plugin_attribute(self):
        plugin_manager = PluginManager('')

        with mock.patch('compose.plugin_manager.os.path.isfile') as mock_isfile, \
                mock.patch('imp.load_source') as mock_load_source, \
                mock.patch('os.walk') as mock_walk:
            mock_walk.return_value = []
            mock_load_source.return_value = self._get_helper_class({
                'plugin': self._get_helper_class().__class__
            })
            mock_isfile.return_value = True

            with self.assertRaises(InvalidPluginError) as e:
                plugin_manager._source_plugin('plugin')

        self.assertEqual(str(e.exception), "Wrong plugin instance.")
예제 #3
0
    def test_source_plugin_valid_plugin(self):
        plugin_manager = PluginManager('')

        with mock.patch('compose.plugin_manager.os.path.isfile') as mock_isfile, \
                mock.patch('imp.load_source') as mock_load_source, \
                mock.patch('os.walk') as mock_walk:
            mock_walk.return_value = []
            mock_load_source.return_value = self._get_helper_class({
                'plugin': Plugin
            })
            mock_isfile.return_value = True

            self.assertEqual(plugin_manager._source_plugin('plugin'), Plugin)