These patches finalize the modifications to the existing tests in tests directory and to the unittesting environment so we can start writing tests which are supposed to be ran on developer's machine before any building (eg. sanity checking the methods and interfaces we have tests for).
Additionally, tests may be marked as @slow or @acceptance to specify, that they should be ran only after everything was build and installed (partitioning tests and similar).
Everything described here was made possible by moving from our unittest control script to python-nose package.
The usage now is really simple (works even before configure has been run):
make -f Makefile.am unittest - for the sanity checks make -f Makefile.am fulltest - for the full acceptance checks
Martin
--- tests/fw_test.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tests/fw_test.py b/tests/fw_test.py index 6210d58..d0df511 100644 --- a/tests/fw_test.py +++ b/tests/fw_test.py @@ -2,7 +2,7 @@ import mock
class ImportTest(mock.TestCase): def setUp(self): - self.setupModules([]) + self.setupModules(["_isys", "block"])
self.fs = mock.DiskIO()
--- Makefile.am | 3 +++ tests/kickstart_test/commands_test.py | 9 ++++++--- tests/mock/__init__.py | 10 ++++++++++ tests/storage_test/devicelibs_test/crypto_test.py | 2 ++ tests/storage_test/devicelibs_test/lvm_test.py | 2 ++ tests/storage_test/devicelibs_test/mdraid_test.py | 2 ++ tests/storage_test/devicelibs_test/mpath_test.py | 2 ++ tests/storage_test/devicelibs_test/swap_test.py | 2 ++ 8 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/Makefile.am b/Makefile.am index d4f1fd3..374430b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -106,4 +106,7 @@ archive-no-tag: dist
# UNIT TESTING TARGETS unittest: + PYTHONPATH=tests/:. nosetests -w tests/ -a !acceptance,!slow + +fulltest: PYTHONPATH=tests/:. nosetests -w tests/ diff --git a/tests/kickstart_test/commands_test.py b/tests/kickstart_test/commands_test.py index fcddced..ef33bba 100644 --- a/tests/kickstart_test/commands_test.py +++ b/tests/kickstart_test/commands_test.py @@ -18,7 +18,7 @@ # Author: Chris Lumens clumens@redhat.com import unittest import sys -from mock import Mock, patch, TestCase +from mock import Mock, patch, TestCase, acceptance
class O(object): pass @@ -57,7 +57,8 @@ class CommandVersionTestCase(TestCase): def tearDown(self): self.tearDownModules()
- def runTest(self): + @acceptance + def commands_test(self): for (commandName, commandObj) in kickstart.commandMap.iteritems(): baseClass = commandObj().__class__.__bases__[0] pykickstartClass = self.handler.commands[commandName].__class__ @@ -71,7 +72,8 @@ class DataVersionTestCase(unittest.TestCase):
self.handler = pykickstart.version.makeVersion(kickstart.ver)
- def runTest(self): + @acceptance + def data_test(self): for (dataName, dataObj) in kickstart.dataMap.iteritems(): baseClass = dataObj().__class__.__bases__[0]
@@ -80,6 +82,7 @@ class DataVersionTestCase(unittest.TestCase): pykickstartClass = eval("self.handler.%s" % dataName)
self.assertEqual(baseClass.__name__, pykickstartClass.__name__) + def suite(): suite = unittest.TestSuite() suite.addTest(CommandVersionTestCase()) diff --git a/tests/mock/__init__.py b/tests/mock/__init__.py index a72d1aa..e62086c 100644 --- a/tests/mock/__init__.py +++ b/tests/mock/__init__.py @@ -24,6 +24,16 @@ from disk import * from mock import * import unittest
+def slow(f): + """Decorates a test method as being slow, usefull for python-nose filtering""" + f.slow = True + return f + +def acceptance(f): + """Decorates test as belonging to acceptance testing and not useable in common devellopment unit testing. To be used with python-nose filtering.""" + f.acceptance = True + return f + class TestCase(unittest.TestCase): def __init__(self, *args, **kwargs): unittest.TestCase.__init__(self, *args, **kwargs) diff --git a/tests/storage_test/devicelibs_test/crypto_test.py b/tests/storage_test/devicelibs_test/crypto_test.py index 434fdcb..7837451 100644 --- a/tests/storage_test/devicelibs_test/crypto_test.py +++ b/tests/storage_test/devicelibs_test/crypto_test.py @@ -1,6 +1,7 @@ #!/usr/bin/python import baseclass import unittest +from mock import acceptance
import tempfile import os @@ -12,6 +13,7 @@ class CryptoTestCase(baseclass.DevicelibsTestCase): import storage.devicelibs.crypto as crypto
+ @acceptance def testCrypto(self): ## ## is_luks diff --git a/tests/storage_test/devicelibs_test/lvm_test.py b/tests/storage_test/devicelibs_test/lvm_test.py index 734644d..1e07345 100644 --- a/tests/storage_test/devicelibs_test/lvm_test.py +++ b/tests/storage_test/devicelibs_test/lvm_test.py @@ -1,6 +1,7 @@ #!/usr/bin/python import baseclass import unittest +from mock import acceptance
class LVMTestCase(baseclass.DevicelibsTestCase):
@@ -8,6 +9,7 @@ class LVMTestCase(baseclass.DevicelibsTestCase): baseclass.DevicelibsTestCase.setUp(self) import storage.devicelibs.lvm as lvm
+ @acceptance def testLVM(self): ## ## pvcreate diff --git a/tests/storage_test/devicelibs_test/mdraid_test.py b/tests/storage_test/devicelibs_test/mdraid_test.py index 9dde22d..4a1c836 100644 --- a/tests/storage_test/devicelibs_test/mdraid_test.py +++ b/tests/storage_test/devicelibs_test/mdraid_test.py @@ -2,6 +2,7 @@ import baseclass import unittest import time +from mock import acceptance
class MDRaidTestCase(baseclass.DevicelibsTestCase):
@@ -9,6 +10,7 @@ class MDRaidTestCase(baseclass.DevicelibsTestCase): baseclass.DevicelibsTestCase.setUp(self) import storage.devicelibs.mdraid as mdraid
+ @acceptance def testMDRaid(self): ## ## getRaidLevels diff --git a/tests/storage_test/devicelibs_test/mpath_test.py b/tests/storage_test/devicelibs_test/mpath_test.py index 813a516..7b7f9fa 100644 --- a/tests/storage_test/devicelibs_test/mpath_test.py +++ b/tests/storage_test/devicelibs_test/mpath_test.py @@ -1,12 +1,14 @@ #!/usr/bin/python import baseclass import unittest +from mock import acceptance
class MPathTestCase(baseclass.DevicelibsTestCase): def setUp(self): baseclass.DevicelibsTestCase.setUp(self) import storage.devicelibs.mpath as mpath
+ @acceptance def testMPath(self): ## ## parseMultipathOutput diff --git a/tests/storage_test/devicelibs_test/swap_test.py b/tests/storage_test/devicelibs_test/swap_test.py index ddf8d21..e399e61 100644 --- a/tests/storage_test/devicelibs_test/swap_test.py +++ b/tests/storage_test/devicelibs_test/swap_test.py @@ -1,6 +1,7 @@ #!/usr/bin/python import baseclass import unittest +from mock import acceptance
class SwapTestCase(baseclass.DevicelibsTestCase):
@@ -8,6 +9,7 @@ class SwapTestCase(baseclass.DevicelibsTestCase): baseclass.DevicelibsTestCase.setUp(self) import storage.devicelibs.swap as swap
+ @acceptance def testSwap(self): ## ## mkswap
--- tests/kickstart_test/commands_test.py | 9 +-------- 1 files changed, 1 insertions(+), 8 deletions(-)
diff --git a/tests/kickstart_test/commands_test.py b/tests/kickstart_test/commands_test.py index ef33bba..f0d5187 100644 --- a/tests/kickstart_test/commands_test.py +++ b/tests/kickstart_test/commands_test.py @@ -65,7 +65,7 @@ class CommandVersionTestCase(TestCase): self.assertEqual(baseClass.__name__, pykickstartClass.__name__)
# Do the same thing as CommandVersionTestCase, but for data objects. -class DataVersionTestCase(unittest.TestCase): +class DataVersionTestCase(TestCase): def setUp(self): import pyanaconda.kickstart import pykickstart.version @@ -83,11 +83,4 @@ class DataVersionTestCase(unittest.TestCase):
self.assertEqual(baseClass.__name__, pykickstartClass.__name__)
-def suite(): - suite = unittest.TestSuite() - suite.addTest(CommandVersionTestCase()) - suite.addTest(DataVersionTestCase()) - return suite
-s = suite() -unittest.TextTestRunner(verbosity=2).run(s)
These patches finalize the modifications to the existing tests in tests directory and to the unittesting environment so we can start writing tests which are supposed to be ran on developer's machine before any building (eg. sanity checking the methods and interfaces we have tests for).
These all look fine.
- Chris
anaconda-devel@lists.fedoraproject.org