summaryrefslogtreecommitdiff
path: root/tests/plugins/plugin.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/plugins/plugin.py')
-rw-r--r--tests/plugins/plugin.py219
1 files changed, 46 insertions, 173 deletions
diff --git a/tests/plugins/plugin.py b/tests/plugins/plugin.py
index 6409975..9015409 100644
--- a/tests/plugins/plugin.py
+++ b/tests/plugins/plugin.py
@@ -1,223 +1,96 @@
-#!/usr/bin/python3-dbg
-# -*- coding: utf-8 -*-
-
from chrysacase import ChrysalideTestCase
-from pychrysalide import PluginModule
-import gc
+from pychrysalide.plugins import PluginModule
class TestPlugin(ChrysalideTestCase):
"""TestCase for GPluginModule."""
- def testGarbageCollecting(self):
- """Ensure the garbarge collector is working for plugin modules."""
-
+ def testPluginInfoImplementations(self):
+ """Retrieve plugin basic information provided by __init__()."""
- class MyPG_1(PluginModule):
+ class MyPlugin(PluginModule):
def __init__(self):
+ super().__init__('custom-name', desc='custom-desc', url='custom-url', version='0.0.1')
- interface = {
- 'name' : 'some_name',
- 'desc' : 'Provide some information about the useless plugin',
- 'version' : '0.1',
- 'actions' : ( )
- }
+ my = MyPlugin()
- super(MyPG_1, self).__init__(**interface)
+ 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')
- pg = MyPG_1()
- self.assertIsNotNone(pg)
+ def testPluginMethodImplementations(self):
+ """Ensure required plugins abstract methods can be implemented."""
-
- class MyPG_2(PluginModule):
+ class MyWrongPlugin(PluginModule):
def __init__(self):
+ super().__init__('pg-name')
- interface = {
- 'name' : 'some_name',
- 'desc' : 'Provide some information about the useless plugin',
- 'version' : '0.1',
- 'actions' : ( )
- }
-
- super(MyPG_2, self).__init__(**interface)
+ my = MyWrongPlugin()
+ with self.assertRaisesRegex(NotImplementedError, "method implementation is missing for '_get_filename'"):
+ print(my.filename)
- pg = MyPG_2()
- self.assertIsNotNone(pg)
+ with self.assertRaisesRegex(NotImplementedError, "method implementation is missing for '_get_modname'"):
+ print(my.modname)
- class MyPG_3(PluginModule):
+ class MyPlugin(PluginModule):
def __init__(self):
+ super().__init__('pg-name')
- interface = {
- 'name' : 'some_name',
- 'desc' : 'Provide some information about the useless plugin',
- 'version' : '0.1',
- 'actions' : ( )
- }
+ def _get_filename(self):
+ return 'file-name'
- super(MyPG_3, self).__init__(**interface)
+ def _get_modname(self):
+ return 'mod-name'
+ my = MyPlugin()
- pg = MyPG_3()
- self.assertIsNotNone(pg)
+ self.assertEqual(my.filename, 'file-name')
+ self.assertEqual(my.modname, 'mod-name')
- class MyPG_4(PluginModule):
-
- def __init__(self):
-
- interface = {
- 'name' : 'some_name',
- 'desc' : 'Provide some information about the useless plugin',
- 'version' : '0.1',
- 'actions' : ( )
- }
- super(MyPG_4, self).__init__(**interface)
+ def testPluginRequirementIncludePython(self):
+ """Ensure that plugin requirements include the Python bindings."""
-
- pg = MyPG_4()
- self.assertIsNotNone(pg)
-
-
- class MyPG_5(PluginModule):
+ class MyPlugin(PluginModule):
def __init__(self):
+ super().__init__('pg-name')
- interface = {
- 'name' : 'some_name',
- 'desc' : 'Provide some information about the useless plugin',
- 'version' : '0.1',
- 'actions' : ( )
- }
-
- super(MyPG_5, self).__init__(**interface)
-
-
- pg = MyPG_5()
- self.assertIsNotNone(pg)
+ my = MyPlugin()
+ self.assertEqual(len(my.requirements), 1)
+ self.assertEqual(my.requirements[0], 'PyChrysalide')
- gc.collect()
+ def testPluginRequirementUniqueness(self):
+ """Ensure that plugin requirements are unique."""
- def testCreation(self):
- """Validate PluginModule creation from Python."""
-
-
- class MyPG_0(PluginModule):
- pass
-
-
- # TypeError: Required argument 'name' (pos 1) not found
- with self.assertRaises(TypeError):
- pg = MyPG_0()
-
-
- class MyPG_1(PluginModule):
+ class MyPlugin(PluginModule):
def __init__(self):
+ super().__init__('pg-name', required=[ 'PyChrysalide' ])
- interface = {
- 'name' : 'some_name',
- 'desc' : 'Provide some information about the useless plugin',
- 'version' : '0.1',
- 'actions' : ( )
- }
-
- super(MyPG_1, self).__init__(**interface)
+ my = MyPlugin()
+ self.assertEqual(my.requirements.count('PyChrysalide'), 1)
- pg = MyPG_1()
- self.assertIsNotNone(pg)
-
- class MyPG_2(PluginModule):
+ class MyPlugin2(PluginModule):
def __init__(self):
+ super().__init__('pg-name2', required=[ 'AA', 'BB', 'AA' ])
- interface = {
- 'name' : 'some_name',
- 'desc' : 'Provide some information about the useless plugin',
- 'version' : '0.1',
- 'actions' : ( 'ABC', )
- }
-
- super(MyPG_2, self).__init__(**interface)
-
-
- # TypeError: Invalid type for plugin action.
- with self.assertRaises(TypeError):
- pg = MyPG_2()
-
-
- class MyPG_3(PluginModule):
-
- def __init__(self):
-
- interface = {
- 'name' : 'some_name',
- 'desc' : 'Provide some information about the useless plugin',
- 'version' : '0.1',
- 'actions' : ( PluginModule.PGA_CONTENT_EXPLORER, )
- }
-
- super(MyPG_3, self).__init__(**interface)
-
-
- # TypeError: missing features for the declared actions.
- with self.assertRaises(TypeError):
- pg = MyPG_3()
-
-
- class MyPG_4(PluginModule):
-
- def __init__(self):
-
- interface = {
- 'name' : 'some_name4',
- 'desc' : 'Provide some information about the useless plugin',
- 'version' : '0.1',
- 'actions' : ( PluginModule.PGA_CONTENT_EXPLORER, )
- }
-
- super(MyPG_4, self).__init__(**interface)
-
- def handle_binary_content(self, action, content, wid, status):
- pass
-
-
- pg = MyPG_4()
- self.assertIsNotNone(pg)
-
-
- def testDoubleUsage(self):
- """Validate PluginModule double usage in Python."""
-
-
- class MyPG(PluginModule):
-
- def __init__(self):
-
- interface = {
- 'name' : 'some_name',
- 'desc' : 'Provide some information about the useless plugin',
- 'version' : '0.1',
- 'actions' : ( )
- }
-
- super(MyPG, self).__init__(**interface)
-
-
- pg1 = MyPG()
- self.assertIsNotNone(pg1)
+ my = MyPlugin2()
- pg2 = MyPG()
- self.assertIsNotNone(pg2)
+ self.assertEqual(my.requirements.count('AA'), 1)
+ self.assertEqual(my.requirements.count('PyChrysalide'), 1)