Rename test classes to match PEP.

Add test case with multiple classes in file.
Remove setup in test runner.
This commit is contained in:
Daniel Goldberg 2019-11-24 10:42:56 +02:00
parent dae5c789b5
commit f118de3d21
4 changed files with 28 additions and 8 deletions

View File

@ -1,7 +1,7 @@
from infection_monkey.utils.plugins.pluginTests.PluginTestClass import TestPlugin from infection_monkey.utils.plugins.pluginTests.PluginTestClass import TestPlugin
class badPluginInit(TestPlugin): class BadPluginInit(TestPlugin):
def __init__(self): def __init__(self):
raise Exception("TestException") raise Exception("TestException")

View File

@ -0,0 +1,15 @@
from infection_monkey.utils.plugins.pluginTests.PluginTestClass import TestPlugin
class NoInheritance:
pass
class BadInit(TestPlugin):
def __init__(self):
raise Exception("TestException")
class ProperClass(TestPlugin):
pass

View File

@ -1,5 +1,5 @@
from infection_monkey.utils.plugins.pluginTests.PluginTestClass import TestPlugin from infection_monkey.utils.plugins.pluginTests.PluginTestClass import TestPlugin
class pluginWorking(TestPlugin): class PluginWorking(TestPlugin):
pass pass

View File

@ -1,18 +1,23 @@
from unittest import TestCase from unittest import TestCase
from infection_monkey.utils.plugins.pluginTests.PluginWorking import pluginWorking from infection_monkey.utils.plugins.pluginTests.ComboFile import BadInit, ProperClass
from infection_monkey.utils.plugins.pluginTests.PluginWorking import PluginWorking
from infection_monkey.utils.plugins.pluginTests.BadImport import SomeDummyPlugin from infection_monkey.utils.plugins.pluginTests.BadImport import SomeDummyPlugin
from infection_monkey.utils.plugins.pluginTests.BadInit import badPluginInit from infection_monkey.utils.plugins.pluginTests.BadInit import BadPluginInit
from infection_monkey.utils.plugins.pluginTests.PluginTestClass import TestPlugin from infection_monkey.utils.plugins.pluginTests.PluginTestClass import TestPlugin
class PluginTester(TestCase): class PluginTester(TestCase):
def setUp(self): def test_combo_file(self):
pass TestPlugin.classes_to_load = [BadInit.__name__, ProperClass.__name__]
to_init = TestPlugin.get_classes()
self.assertEqual(len(to_init), 2)
objects = TestPlugin.get_instances()
self.assertEqual(len(objects), 1)
def test_bad_init(self): def test_bad_init(self):
TestPlugin.classes_to_load = [badPluginInit.__name__] TestPlugin.classes_to_load = [BadPluginInit.__name__]
to_init = TestPlugin.get_classes() to_init = TestPlugin.get_classes()
self.assertEqual(len(to_init), 1) self.assertEqual(len(to_init), 1)
objects = TestPlugin.get_instances() objects = TestPlugin.get_instances()
@ -24,7 +29,7 @@ class PluginTester(TestCase):
self.assertEqual(len(to_init), 0) self.assertEqual(len(to_init), 0)
def test_flow(self): def test_flow(self):
TestPlugin.classes_to_load = [pluginWorking.__name__] TestPlugin.classes_to_load = [PluginWorking.__name__]
to_init = TestPlugin.get_classes() to_init = TestPlugin.get_classes()
self.assertEqual(len(to_init), 1) self.assertEqual(len(to_init), 1)
objects = TestPlugin.get_instances() objects = TestPlugin.get_instances()