本文整理汇总了Python中pluginmanager.PluginManager.set_plugins方法的典型用法代码示例。如果您正苦于以下问题:Python PluginManager.set_plugins方法的具体用法?Python PluginManager.set_plugins怎么用?Python PluginManager.set_plugins使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pluginmanager.PluginManager
的用法示例。
在下文中一共展示了PluginManager.set_plugins方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestPluginManager
# 需要导入模块: from pluginmanager import PluginManager [as 别名]
# 或者: from pluginmanager.PluginManager import set_plugins [as 别名]
class TestPluginManager(unittest.TestCase):
def setUp(self):
self.instance = InstanceClass()
self.plugin_manager = PluginManager()
self.plugin_manager.add_plugins(self.instance)
def test_add_instances(self):
self.plugin_manager.unique_instances = False
instance = InstanceClass()
self.plugin_manager.add_plugins(instance)
instances = self.plugin_manager.get_plugins()
self.assertIn(instance, instances)
self.plugin_manager.add_plugins(InstanceClass())
instances = self.plugin_manager.get_plugins()
self.assertTrue(len(instances) > 2)
uniq = self.plugin_manager._unique_class(InstanceClass)
self.assertFalse(uniq)
def test_register_class(self):
class TestClass:
pass
self.assertFalse(issubclass(TestClass, IPlugin))
self.plugin_manager.register_classes(TestClass)
self.assertTrue(issubclass(TestClass, IPlugin))
def test_class_in_blacklist(self):
self.plugin_manager.set_plugins([])
self.plugin_manager.add_blacklisted_plugins(InstanceClass)
self.plugin_manager._handle_object_instance(self.instance)
plugins = self.plugin_manager.get_plugins()
self.assertEqual(plugins, [])
def test_blacklist_plugins(self):
self.plugin_manager.add_blacklisted_plugins(InstanceClass)
blacklisted = self.plugin_manager.get_blacklisted_plugins()
self.assertIn(InstanceClass, blacklisted)
def test_handle_classs_instance(self):
self.plugin_manager.instantiate_classes = False
is_none = self.plugin_manager._handle_class_instance(5)
self.assertIsNone(is_none)
def test_class_instance_not_unique(self):
self.plugin_manager.unique_instances = False
num_plugins = len(self.plugin_manager.plugins)
self.plugin_manager._handle_class_instance(InstanceClass)
self.assertTrue(len(self.plugin_manager.plugins) > num_plugins)
def test_class_instance_unique(self):
num_plugins = len(self.plugin_manager.plugins)
self.plugin_manager.unique_instances = True
self.plugin_manager._handle_class_instance(InstanceClass)
self.assertTrue(len(self.plugin_manager.plugins) == num_plugins)
def test_get_plugins(self):
self.plugin_manager.unique_instances = False
instance_2 = InstanceClass()
instance_2.name = 'red'
self.plugin_manager.add_plugins(instance_2)
filtered_plugins = self.plugin_manager.get_plugins(_test_filter)
self.assertNotIn(self.instance, filtered_plugins)
self.assertIn(instance_2, filtered_plugins)
def test_set_plugins(self):
instance_2 = InstanceClass()
self.plugin_manager.set_plugins(instance_2)
plugins = self.plugin_manager.get_plugins()
self.assertIn(instance_2, plugins)
self.assertNotIn(self.instance, plugins)
def test_remove_plugin(self):
self.plugin_manager.remove_plugins(self.instance)
plugins = self.plugin_manager.get_plugins()
self.assertNotIn(self.instance, plugins)
def test_remove_instance(self):
self.plugin_manager.remove_instance(self.instance)
plugins = self.plugin_manager.get_plugins()
self.assertNotIn(self.instance, plugins)
def test_get_instances(self):
self.plugin_manager.unique_instances = False
instance_2 = InstanceClass()
instance_2.name = 'red'
self.plugin_manager.add_plugins((instance_2, 5.0))
instances = self.plugin_manager.get_instances((IPlugin, InstanceClass))
self.assertIn(instance_2, instances)
self.assertIn(self.instance, instances)
self.assertNotIn(5.0, instances)
filtered_instances = self.plugin_manager.get_instances(_test_filter)
self.assertIn(instance_2, filtered_instances)
self.assertNotIn(self.instance, filtered_instances)
self.assertNotIn(5.0, filtered_instances)
all_instances = self.plugin_manager.get_instances(None)
self.assertIn(self.instance, all_instances)
self.assertIn(instance_2, all_instances)
self.assertIn(5.0, all_instances)
#.........这里部分代码省略.........