from chrysacase import ChrysalideTestCase from pychrysalide.plugins import PluginModule class TestPlugin(ChrysalideTestCase): """TestCase for GPluginModule.""" def testPluginInfoImplementations(self): """Retrieve plugin basic information provided by __init__().""" class MyPlugin(PluginModule): def __init__(self): super().__init__('custom-name', desc='custom-desc', url='custom-url', version='0.0.1') my = MyPlugin() self.assertEqual(my.name, 'custom-name') self.assertEqual(my.desc, 'custom-desc') self.assertEqual(my.version, '0.0.1') self.assertEqual(my.url, 'custom-url') def testPluginMethodImplementations(self): """Ensure required plugins abstract methods can be implemented.""" class MyWrongPlugin(PluginModule): def __init__(self): super().__init__('pg-name') my = MyWrongPlugin() with self.assertRaisesRegex(NotImplementedError, "method implementation is missing for '_get_filename'"): print(my.filename) with self.assertRaisesRegex(NotImplementedError, "method implementation is missing for '_get_modname'"): print(my.modname) class MyPlugin(PluginModule): def __init__(self): super().__init__('pg-name') def _get_filename(self): return 'file-name' def _get_modname(self): return 'mod-name' my = MyPlugin() self.assertEqual(my.filename, 'file-name') self.assertEqual(my.modname, 'mod-name') def testPluginRequirementIncludePython(self): """Ensure that plugin requirements include the Python bindings.""" class MyPlugin(PluginModule): def __init__(self): super().__init__('pg-name') my = MyPlugin() self.assertEqual(len(my.requirements), 1) self.assertEqual(my.requirements[0], 'PyChrysalide') def testPluginRequirementUniqueness(self): """Ensure that plugin requirements are unique.""" class MyPlugin(PluginModule): def __init__(self): super().__init__('pg-name', required=[ 'PyChrysalide' ]) my = MyPlugin() self.assertEqual(my.requirements.count('PyChrysalide'), 1) class MyPlugin2(PluginModule): def __init__(self): super().__init__('pg-name2', required=[ 'AA', 'BB', 'AA' ]) my = MyPlugin2() self.assertEqual(my.requirements.count('AA'), 1) self.assertEqual(my.requirements.count('PyChrysalide'), 1)