diff options
Diffstat (limited to 'testsuite')
30 files changed, 160 insertions, 101 deletions
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestDevice.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestDevice.py index a18327fe0..9f396b0b6 100644 --- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestDevice.py +++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestDevice.py @@ -16,9 +16,7 @@ while path != "/": path = os.path.dirname(path) from Test__init import get_posix_object from Testbase import TestPOSIXTool -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore +from common import * class TestPOSIXDevice(TestPOSIXTool): test_obj = POSIXDevice diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestDirectory.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestDirectory.py index e01bd7453..1ce6562c5 100644 --- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestDirectory.py +++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestDirectory.py @@ -17,9 +17,7 @@ while path != "/": path = os.path.dirname(path) from Test__init import get_posix_object from Testbase import TestPOSIXTool -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore +from common import * class TestPOSIXDirectory(TestPOSIXTool): test_obj = POSIXDirectory diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py index cdf11ce5e..f69c33a97 100644 --- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py +++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py @@ -20,9 +20,7 @@ while path != "/": path = os.path.dirname(path) from Test__init import get_posix_object from Testbase import TestPOSIXTool -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore +from common import * def get_file_object(posix=None): if posix is None: diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestHardlink.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestHardlink.py index d68e15837..c38e86aeb 100644 --- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestHardlink.py +++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestHardlink.py @@ -16,9 +16,7 @@ while path != "/": path = os.path.dirname(path) from Test__init import get_posix_object from Testbase import TestPOSIXTool -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore +from common import * class TestPOSIXHardlink(TestPOSIXTool): test_obj = POSIXHardlink diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py index 375ff00eb..676b18f5d 100644 --- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py +++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py @@ -16,9 +16,7 @@ while path != "/": path = os.path.dirname(path) from Test__init import get_config, get_posix_object from Testbase import TestPOSIXTool -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore +from common import * class TestPOSIXNonexistent(TestPOSIXTool): test_obj = POSIXNonexistent diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestSymlink.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestSymlink.py index b02f7b3c3..4c8ddfa3f 100644 --- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestSymlink.py +++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestSymlink.py @@ -16,9 +16,7 @@ while path != "/": path = os.path.dirname(path) from Test__init import get_posix_object from Testbase import TestPOSIXTool -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore +from common import * class TestPOSIXSymlink(TestPOSIXTool): test_obj = POSIXSymlink diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Test__init.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Test__init.py index 14a2520df..e503ebd38 100644 --- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Test__init.py +++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Test__init.py @@ -14,9 +14,7 @@ while path != "/": if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore +from common import * def get_config(entries): config = lxml.etree.Element("Configuration") diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py index bcb1d16af..39c0b02d0 100644 --- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py +++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py @@ -17,9 +17,7 @@ while path != "/": break path = os.path.dirname(path) from Test__init import get_posix_object -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore +from common import * try: import selinux @@ -33,6 +31,7 @@ try: except ImportError: HAS_ACLS = False + class TestPOSIXTool(Bcfg2TestCase): test_obj = POSIXTool @@ -52,7 +51,7 @@ class TestPOSIXTool(Bcfg2TestCase): # fully_specified should do no checking on the abstract # POSIXTool object self.assertTrue(self.ptool.fully_specified(Mock())) - + @patch('os.stat') @patch('os.walk') @patch("Bcfg2.Client.Tools.POSIX.base.%s._verify_metadata" % diff --git a/testsuite/Testsrc/Testlib/TestEncryption.py b/testsuite/Testsrc/Testlib/TestEncryption.py index 530592cd0..7e9d910d8 100644 --- a/testsuite/Testsrc/Testlib/TestEncryption.py +++ b/testsuite/Testsrc/Testlib/TestEncryption.py @@ -13,8 +13,7 @@ while path != "/": if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import call, u, can_skip, skip, skipIf, skipUnless, \ - Bcfg2TestCase, patchIf +from common import * try: from Bcfg2.Encryption import * diff --git a/testsuite/Testsrc/Testlib/TestOptions.py b/testsuite/Testsrc/Testlib/TestOptions.py index e20a320b1..dc91a499b 100644 --- a/testsuite/Testsrc/Testlib/TestOptions.py +++ b/testsuite/Testsrc/Testlib/TestOptions.py @@ -13,9 +13,7 @@ while path != '/': if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore +from common import * class TestDefaultConfigParser(Bcfg2TestCase): @patch("%s.ConfigParser.get" % ConfigParser.__name__) diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testbase.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testbase.py index 4b2f1981f..7ee3697bb 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testbase.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testbase.py @@ -13,8 +13,7 @@ while path != '/': if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import call, builtins, skip, skipIf, skipUnless, Bcfg2TestCase, \ - patchIf, datastore +from common import * class TestDebuggable(Bcfg2TestCase): diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testexceptions.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testexceptions.py index d2b72251e..916ce822d 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testexceptions.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testexceptions.py @@ -12,8 +12,7 @@ while path != '/': if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import call, builtins, skip, skipIf, skipUnless, Bcfg2TestCase, \ - patchIf, datastore +from common import * class TestPluginInitError(Bcfg2TestCase): diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py index 27d726fbb..8a1d5a949 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py @@ -17,11 +17,11 @@ while path != '/': if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import XI_NAMESPACE, XI, call, builtins, skip, skipIf, \ - skipUnless, Bcfg2TestCase, patchIf, datastore, inPy3k, can_skip, re_type +from common import * from TestServer.TestPlugin.Testbase import TestPlugin, TestDebuggable from TestServer.TestPlugin.Testinterfaces import TestGenerator + def tostring(el): return lxml.etree.tostring(el, xml_declaration=False).decode('UTF-8') @@ -155,12 +155,13 @@ class TestDirectoryBacked(Bcfg2TestCase): # such thing as a bad event def test_child_interface(self): - # ensure that the child object has the correct interface + """ ensure that the child object has the correct interface """ self.assertTrue(hasattr(self.test_obj.__child__, "HandleEvent")) def get_obj(self, fam=None): if fam is None: fam = Mock() + @patch("%s.%s.add_directory_monitor" % (self.test_obj.__module__, self.test_obj.__name__), Mock()) diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testinterfaces.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testinterfaces.py index 6ef40d385..ace509057 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testinterfaces.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testinterfaces.py @@ -14,8 +14,7 @@ while path != '/': if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import call, builtins, skip, skipIf, skipUnless, Bcfg2TestCase, \ - patchIf, datastore +from common import * from TestServer.TestPlugin.Testbase import TestPlugin diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgCheetahGenerator.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgCheetahGenerator.py index 2577b29df..1832e5e03 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgCheetahGenerator.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgCheetahGenerator.py @@ -13,9 +13,7 @@ while path != "/": if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore, re_type +from common import * from TestServer.TestPlugins.TestCfg.Test_init import TestCfgGenerator diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgEncryptedCheetahGenerator.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgEncryptedCheetahGenerator.py index 539b1e741..46062569d 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgEncryptedCheetahGenerator.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgEncryptedCheetahGenerator.py @@ -11,7 +11,7 @@ while path != "/": if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import can_skip, skipUnless +from common import * try: from TestServer.TestPlugins.TestCfg.TestCfgCheetahGenerator import \ diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgEncryptedGenerator.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgEncryptedGenerator.py index 7e4a64996..71a7410da 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgEncryptedGenerator.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgEncryptedGenerator.py @@ -14,9 +14,7 @@ while path != "/": if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore, re_type +from common import * from TestServer.TestPlugins.TestCfg.Test_init import TestCfgGenerator diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgEncryptedGenshiGenerator.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgEncryptedGenshiGenerator.py index 0375b8928..b447a9bb8 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgEncryptedGenshiGenerator.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgEncryptedGenshiGenerator.py @@ -12,9 +12,7 @@ while path != "/": if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore, re_type +from common import * try: from TestServer.TestPlugins.TestCfg.TestCfgGenshiGenerator import \ diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgExternalCommandVerifier.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgExternalCommandVerifier.py index fde7ed722..11dbdd391 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgExternalCommandVerifier.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgExternalCommandVerifier.py @@ -14,9 +14,7 @@ while path != "/": if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore, re_type +from common import * from TestServer.TestPlugins.TestCfg.Test_init import TestCfgVerifier diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgGenshiGenerator.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgGenshiGenerator.py index 2dd647352..baad10933 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgGenshiGenerator.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgGenshiGenerator.py @@ -14,9 +14,7 @@ while path != "/": if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore, re_type +from common import * from TestServer.TestPlugins.TestCfg.Test_init import TestCfgGenerator diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgInfoXML.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgInfoXML.py index 88dd1f18f..839e9c3b8 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgInfoXML.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgInfoXML.py @@ -14,9 +14,7 @@ while path != "/": if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore, re_type +from common import * from TestServer.TestPlugins.TestCfg.Test_init import TestCfgInfo diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/Test_init.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/Test_init.py index 11f06873d..8cfd69242 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/Test_init.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/Test_init.py @@ -16,9 +16,7 @@ while path != "/": if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore, re_type +from common import * from TestPlugin import TestSpecificData, TestEntrySet, TestGroupSpool, \ TestPullTarget diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py index 13e514e77..5610d9071 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py @@ -18,12 +18,11 @@ while path != "/": if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore +from common import * from TestPlugin import TestXMLFileBacked, TestMetadata as _TestMetadata, \ TestStatistics, TestDatabaseBacked + def get_clients_test_tree(): return lxml.etree.XML(''' <Clients> @@ -47,6 +46,7 @@ def get_clients_test_tree(): <Client name="client10" profile="group1" floating="true"/> </Clients>''').getroottree() + def get_groups_test_tree(): return lxml.etree.XML(''' <Groups xmlns:xi="http://www.w3.org/2001/XInclude"> diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProbes.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProbes.py index 0ad92ca72..a1d41b693 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProbes.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProbes.py @@ -15,9 +15,7 @@ while path != "/": if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore +from common import * from Bcfg2.Server.Plugins.Probes import * from TestPlugin import TestEntrySet, TestProbing, TestConnector, \ TestDatabaseBacked diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProperties.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProperties.py index 883e88ba1..fb4773d75 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProperties.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProperties.py @@ -14,9 +14,7 @@ while path != "/": if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore +from common import * from TestPlugin import TestStructFile, TestConnector, TestPlugin, \ TestDirectoryBacked diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestSEModules.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestSEModules.py index e18e2bfd6..8a148b353 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestSEModules.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestSEModules.py @@ -14,9 +14,7 @@ while path != "/": if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore +from common import * from TestPlugin import TestSpecificData, TestGroupSpool diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py index 18855a631..832857601 100644 --- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py +++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestTemplateHelper.py @@ -13,8 +13,7 @@ while path != "/": if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import call, skip, skipIf, skipUnless, Bcfg2TestCase, patchIf, \ - datastore +from common import * from TestPlugin import TestDirectoryBacked, TestConnector, TestPlugin, \ TestFileBacked diff --git a/testsuite/Testsrc/test_code_checks.py b/testsuite/Testsrc/test_code_checks.py index ac4183576..481dd7fa3 100644 --- a/testsuite/Testsrc/test_code_checks.py +++ b/testsuite/Testsrc/test_code_checks.py @@ -13,7 +13,7 @@ while _path != '/': if os.path.basename(_path) == "testsuite": break _path = os.path.dirname(_path) -from common import can_skip, skip, skipIf, skipUnless, Bcfg2TestCase +from common import * # path to Bcfg2 src directory srcpath = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", @@ -168,7 +168,6 @@ class TestPylint(Bcfg2TestCase): full_blacklist = expand_path_dict(error_checks) + contingent_blacklist + \ blacklist - @skipIf(not os.path.exists(srcpath), "%s does not exist" % srcpath) @skipIf(not os.path.exists(rcfile), "%s does not exist" % rcfile) @skipUnless(HAS_PYLINT, "pylint not found, skipping") diff --git a/testsuite/Testtools/__init__.py b/testsuite/Testtools/__init__.py index 73687eb5f..993938e07 100644 --- a/testsuite/Testtools/__init__.py +++ b/testsuite/Testtools/__init__.py @@ -11,9 +11,7 @@ while path != "/": if os.path.basename(path) == "testsuite": break path = os.path.dirname(path) -from common import XI_NAMESPACE, XI, inPy3k, call, builtins, u, can_skip, \ - skip, skipIf, skipUnless, Bcfg2TestCase, DBModelTestCase, syncdb, \ - patchIf, datastore +from common import * TOOLSDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "tools")) diff --git a/testsuite/common.py b/testsuite/common.py index 5d8157e55..0cb457461 100644 --- a/testsuite/common.py +++ b/testsuite/common.py @@ -1,19 +1,37 @@ +""" In order to make testing easier and more consistent, we provide a +number of convenience functions, variables, and classes, for a wide +variety of reasons. To import this module, first set up +:ref:`development-unit-testing-relative-imports` and then simply do: + +.. code-block:: python + + from common import * +""" + import os import re import sys +import codecs import unittest from mock import patch, MagicMock, _patch, DEFAULT from Bcfg2.Compat import wraps +#: The path to the Bcfg2 specification root for the tests. Using the +#: root directory exposes a lot of potential problems with building +#: paths. datastore = "/" +#: The XInclude namespace name XI_NAMESPACE = "http://www.w3.org/2001/XInclude" + +#: The XInclude namespace in a format suitable for use in XPath +#: expressions XI = "{%s}" % XI_NAMESPACE +#: Whether or not the tests are being run on Python 3. +inPy3k = False if sys.hexversion >= 0x03000000: inPy3k = True -else: - inPy3k = False try: from django.core.management import setup_environ @@ -33,45 +51,84 @@ try: from mock import call except ImportError: def call(*args, **kwargs): - """ the Mock call object is a fairly recent addition, but it's - very very useful, so we create our own function to create Mock - calls """ + """ Analog to the Mock call object, which is a fairly recent + addition, but it's very very useful, so we create our own + function to create Mock calls""" return (args, kwargs) +#: The name of the builtin module, for mocking Python builtins. In +#: Python 2, this is ``__builtin__``, in Python 3 ``builtins``. To +#: patch a builtin, you must do something like: +#: +#: .. code-block:: python +#: +#: @patch("%s.open" % open) +#: def test_something(self, mock_open): +#: ... +builtins = "__builtin__" + + if inPy3k: builtins = "builtins" - def u(x): - return x + def u(s): + """ Get a unicode string, whatever that means. In Python 2, + returns a unicode object; in Python 3, returns a str object. + + :param s: The string to unicode-ify. + :type s: str + :returns: str or unicode """ + return s else: - builtins = "__builtin__" + def u(s): + """ Get a unicode string, whatever that means. In Python 2, + returns a unicode object; in Python 3, returns a str object. + + :param s: The string to unicode-ify. + :type s: str + :returns: str or unicode """ + return codecs.unicode_escape_decode(s)[0] - import codecs - def u(x): - return codecs.unicode_escape_decode(x)[0] +#: Whether or not skipping tests is natively supported by +#: :mod:`unittest`. If it isn't, then we have to make tests that +#: would be skipped succeed instead. +can_skip = False if hasattr(unittest, "skip"): can_skip = True + + #: skip decorator from :func:`unittest.skip` skip = unittest.skip + + #: skipIf decorator from :func:`unittest.skipIf` skipIf = unittest.skipIf + + #: skipUnless decorator from :func:`unittest.skipUnless` skipUnless = unittest.skipUnless else: # we can't actually skip tests, we just make them pass can_skip = False def skip(msg): + """ skip decorator used when :mod:`unittest` doesn't support + skipping tests. Replaces the decorated function with a + no-op. """ def decorator(func): return lambda *args, **kwargs: None return decorator def skipIf(condition, msg): + """ skipIf decorator used when :mod:`unittest` doesn't support + skipping tests """ if not condition: return lambda f: f else: return skip(msg) def skipUnless(condition, msg): + """ skipUnless decorator used when :mod:`unittest` doesn't + support skipping tests """ if condition: return lambda f: f else: @@ -114,6 +171,7 @@ def _count_diff_all_purpose(actual, expected): result.append(diff) return result + def _assertion(predicate, default_msg=None): @wraps(predicate) def inner(self, *args, **kwargs): @@ -130,6 +188,7 @@ def _assertion(predicate, default_msg=None): assert predicate(*args, **kwargs), msg return inner + def _regex_matches(val, regex): if hasattr(regex, 'search'): return regex.search(val) @@ -138,11 +197,23 @@ def _regex_matches(val, regex): class Bcfg2TestCase(unittest.TestCase): + """ Base TestCase class that inherits from + :class:`unittest.TestCase`. This class does a few things: + + * Adds :func:`assertXMLEqual`, a useful assertion method given all + the XML used by Bcfg2; + + * Defines convenience methods that were (mostly) added in Python + 2.7. + """ if not hasattr(unittest.TestCase, "assertItemsEqual"): # TestCase in Py3k lacks assertItemsEqual, but has the other # convenience methods. this code is (mostly) cribbed from the # py2.7 unittest library def assertItemsEqual(self, expected_seq, actual_seq, msg=None): + """ Implementation of + :func:`unittest.TestCase.assertItemsEqual` for python + versions that lack it """ first_seq, second_seq = list(actual_seq), list(expected_seq) differences = _count_diff_all_purpose(first_seq, second_seq) @@ -191,6 +262,9 @@ class Bcfg2TestCase(unittest.TestCase): "%s is not less than or equal to %s") def assertXMLEqual(self, el1, el2, msg=None): + """ Test that the two XML trees given are equal. Both + elements and all children are expected to have ``name`` + attributes. """ self.assertEqual(el1.tag, el2.tag, msg=msg) self.assertEqual(el1.text, el2.text, msg=msg) self.assertItemsEqual(el1.attrib, el2.attrib, msg=msg) @@ -208,11 +282,12 @@ class Bcfg2TestCase(unittest.TestCase): class DBModelTestCase(Bcfg2TestCase): + """ Test case class for Django database models """ models = [] @skipUnless(has_django, "Django not found, skipping") def test_syncdb(self): - # create the test database + """ Create the test database and sync the schema """ setup_environ(Bcfg2.settings) import django.core.management django.core.management.call_command("syncdb", interactive=False, @@ -221,14 +296,16 @@ class DBModelTestCase(Bcfg2TestCase): @skipUnless(has_django, "Django not found, skipping") def test_cleandb(self): - # ensure that we a) can connect to the database; b) start with - # a clean database + """ Ensure that we a) can connect to the database; b) start + with a clean database """ for model in self.models: model.objects.all().delete() self.assertItemsEqual(list(model.objects.all()), []) def syncdb(modeltest): + """ Given an instance of a :class:`DBModelTestCase` object, sync + and clean the database """ inst = modeltest(methodName='test_syncdb') inst.test_syncdb() inst.test_cleandb() @@ -246,15 +323,39 @@ class _noop_patch(_patch): class patchIf(object): - """ perform conditional patching. this is necessary because some - libraries might not be installed (e.g., selinux, pylibacl), and - patching will barf on that. Other workarounds are not available - to us; e.g., context managers aren't in python 2.4, and using - inner functions doesn't work because python 2.6 applies all - decorators at compile-time, not at run-time, so decorating inner - functions does not prevent the decorators from being run. """ + """ Decorator class to perform conditional patching. This is + necessary because some libraries might not be installed (e.g., + selinux, pylibacl), and patching will barf on that. Other + workarounds are not available to us; e.g., context managers aren't + in python 2.4, and using inner functions doesn't work because + python 2.6 parses all decorators at compile-time, not at run-time, + so decorating inner functions does not prevent the decorators from + being run. """ + def __init__(self, condition, target, new=DEFAULT, spec=None, create=False, spec_set=None): + """ + :param condition: The condition to evaluate to decide if the + patch will be applied. + :type condition: bool + :param target: The name of the target object to patch + :type target: str + :param new: The new object to replace the target with. If + this is omitted, a new :class:`mock.MagicMock` is + created and passed as an extra argument to the + decorated function. + :type new: any + :param spec: Spec passed to the MagicMock object if + ``patchIf`` is creating one for you. + :type spec: List of strings or existing object + :param create: Tell patch to create attributes on the fly. + See the documentation for :func:`mock.patch` + for more details on this. + :type create: bool + :param spec_set: Spec set passed to the MagicMock object if + ``patchIf`` is creating one for you. + :type spec_set: List of strings or existing object + """ self.condition = condition self.target = target @@ -286,6 +387,8 @@ class patchIf(object): return _noop_patch(*args)(func) +#: The type of compiled regular expression objects +re_type = None try: re_type = re._pattern_type except AttributeError: |