diff --git a/qubes/tests/__init__.py b/qubes/tests/__init__.py new file mode 100644 index 00000000..193619df --- /dev/null +++ b/qubes/tests/__init__.py @@ -0,0 +1,10 @@ +#!/usr/bin/python -O + +import unittest + +class QubesTestCase(unittest.TestCase): + def __str__(self): + return '{}/{}/{}'.format( + '.'.join(self.__class__.__module__.split('.')[2:]), + self.__class__.__name__, + self._testMethodName) diff --git a/tests/events.py b/qubes/tests/events.py similarity index 93% rename from tests/events.py rename to qubes/tests/events.py index 75d94a93..d3bab601 100644 --- a/tests/events.py +++ b/qubes/tests/events.py @@ -3,10 +3,11 @@ import sys import unittest -sys.path.insert(0, '..') import qubes.events -class TC_Emitter(unittest.TestCase): +import qubes.tests + +class TC_00_Emitter(qubes.tests.QubesTestCase): def test_000_add_handler(self): # need something mutable testevent_fired = [False] diff --git a/tests/init.py b/qubes/tests/init.py similarity index 96% rename from tests/init.py rename to qubes/tests/init.py index 7a428bab..58a57729 100644 --- a/tests/init.py +++ b/qubes/tests/init.py @@ -5,12 +5,13 @@ import unittest import lxml.etree -sys.path.insert(0, '../') import qubes import qubes.events import qubes.vm -class TC_10_Label(unittest.TestCase): +import qubes.tests + +class TC_10_Label(qubes.tests.QubesTestCase): def test_000_constructor(self): label = qubes.Label(1, '#cc0000', 'red') @@ -45,7 +46,7 @@ class TestHolder(qubes.PropertyHolder): testprop3 = qubes.property('testprop3', order=2, default='testdefault') testprop4 = qubes.property('testprop4', order=3) -class TC_00_PropertyHolder(unittest.TestCase): +class TC_00_PropertyHolder(qubes.tests.QubesTestCase): def assertXMLEqual(self, xml1, xml2): self.assertEqual(xml1.tag, xml2.tag) self.assertEqual(xml1.text, xml2.text) @@ -103,7 +104,7 @@ class TestVM(qubes.vm.BaseVM): class TestApp(qubes.events.Emitter): pass -class TC_11_VMCollection(unittest.TestCase): +class TC_11_VMCollection(qubes.tests.QubesTestCase): def setUp(self): # XXX passing None may be wrong in the future self.vms = qubes.VMCollection(TestApp()) @@ -203,5 +204,5 @@ class TC_11_VMCollection(unittest.TestCase): # pass -class TC_20_Qubes(unittest.TestCase): +class TC_20_Qubes(qubes.tests.QubesTestCase): pass diff --git a/qubes/tests/run.py b/qubes/tests/run.py new file mode 100755 index 00000000..8a5b703a --- /dev/null +++ b/qubes/tests/run.py @@ -0,0 +1,26 @@ +#!/usr/bin/python -O + +import importlib +import sys +import unittest + +test_order = [ + 'qubes.tests.events', + 'qubes.tests.vm.init', + 'qubes.tests.vm.qubesvm', + 'qubes.tests.init' +] + +sys.path.insert(0, '../../') + +def main(): + suite = unittest.TestSuite() + loader = unittest.TestLoader() + for modname in test_order: + module = importlib.import_module(modname) + suite.addTests(loader.loadTestsFromModule(module)) + + unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(suite) + +if __name__ == '__main__': + main() diff --git a/qubes/tests/vm/__init__.py b/qubes/tests/vm/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/vm.py b/qubes/tests/vm/init.py similarity index 96% rename from tests/vm.py rename to qubes/tests/vm/init.py index f716b652..fc9f87b4 100644 --- a/tests/vm.py +++ b/qubes/tests/vm/init.py @@ -5,11 +5,12 @@ import unittest import lxml.etree -sys.path.insert(0, '../') import qubes import qubes.events import qubes.vm +import qubes.tests + class TestEmitter(qubes.events.Emitter): def __init__(self): @@ -38,7 +39,7 @@ class TestEmitter(qubes.events.Emitter): if self.device_pre_detached_fired: self.device_detached_fired = True -class TC_00_DeviceCollection(unittest.TestCase): +class TC_00_DeviceCollection(qubes.tests.QubesTestCase): def setUp(self): self.emitter = TestEmitter() self.collection = qubes.vm.DeviceCollection(self.emitter, 'testclass') @@ -79,7 +80,7 @@ class TC_00_DeviceCollection(unittest.TestCase): self.collection.detach('testdev') -class TC_01_DeviceManager(unittest.TestCase): +class TC_01_DeviceManager(qubes.tests.QubesTestCase): def setUp(self): self.emitter = TestEmitter() self.manager = qubes.vm.DeviceManager(self.emitter) @@ -99,7 +100,7 @@ class TestVM(qubes.vm.BaseVM): testlabel = qubes.property('testlabel') defaultprop = qubes.property('defaultprop', default='defaultvalue') -class TC_10_BaseVM(unittest.TestCase): +class TC_10_BaseVM(qubes.tests.QubesTestCase): def setUp(self): self.xml = lxml.etree.XML(''' diff --git a/tests/vm/qubesvm.py b/qubes/tests/vm/qubesvm.py similarity index 94% rename from tests/vm/qubesvm.py rename to qubes/tests/vm/qubesvm.py index 6273cd46..02750824 100644 --- a/tests/vm/qubesvm.py +++ b/qubes/tests/vm/qubesvm.py @@ -2,11 +2,12 @@ import sys import unittest -sys.path.insert(0, '../../') import qubes import qubes.vm.qubesvm +import qubes.tests + class TestProp(object): __name__ = 'testprop' @@ -21,7 +22,7 @@ class TestVM(object): return self.running -class TC_00_setters(unittest.TestCase): +class TC_00_setters(qubes.tests.QubesTestCase): def setUp(self): self.vm = TestVM() self.prop = TestProp() @@ -73,7 +74,7 @@ class TC_00_setters(unittest.TestCase): pass -class TC_90_QubesVM(unittest.TestCase): +class TC_90_QubesVM(qubes.tests.QubesTestCase): @unittest.skip('test not implemented') def test_000_init(self): pass