Really basic test harness for plugins

This commit is contained in:
Daniel Goldberg 2019-11-09 21:20:10 +02:00
parent 4e7269b4df
commit 87cedacb7d
7 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,21 @@
# test - should run true
# test - should run false
# test - invalid parent class but should run true
# test - imported from other file, should not collect
# test - failed to instance
from unittest import TestCase
import infection_monkey.utils.plugins.plugins_testcases
from infection_monkey.utils.plugins.load_plugins import get_instances
from infection_monkey.utils.plugins.plugin import Plugin
class PluginTester(TestCase):
def setUp(self):
pass
def test_plugins(self):
res = get_instances(infection_monkey.utils.plugins.plugins_testcases.__package__,infection_monkey.utils.plugins.plugins_testcases.__file__,Plugin)
self.assertEqual(len(res), 1)

View File

@ -0,0 +1 @@
from infection_monkey.utils.plugins.plugins_testcases.plugin_test_run import PluginShouldRun

View File

@ -0,0 +1,11 @@
from infection_monkey.utils.plugins.plugin import Plugin
class PluginShouldRun(Plugin):
def __init__(self):
raise ValueError("Some Error")
@staticmethod
def should_run(class_name: str) -> bool:
return True

View File

@ -0,0 +1,4 @@
class PluginNoInherit:
@staticmethod
def should_run(class_name: str) -> bool:
return True

View File

@ -0,0 +1,7 @@
from infection_monkey.utils.plugins.plugin import Plugin
class PluginDontRun(Plugin):
@staticmethod
def should_run(class_name: str) -> bool:
return False

View File

@ -0,0 +1,7 @@
from infection_monkey.utils.plugins.plugin import Plugin
class PluginShouldRun(Plugin):
@staticmethod
def should_run(class_name: str) -> bool:
return True