summaryrefslogtreecommitdiffstats
path: root/testsuite
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-08-21 09:08:14 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-08-21 13:33:20 -0400
commitfe716cc6c541239a34d55c0ca5812379a821779a (patch)
treebc183cb1af816cb5fe184a21f99e38f15c200d6f /testsuite
parentd0efac8fde1f2bfc77b45899073c225201c64a2c (diff)
downloadbcfg2-fe716cc6c541239a34d55c0ca5812379a821779a.tar.gz
bcfg2-fe716cc6c541239a34d55c0ca5812379a821779a.tar.bz2
bcfg2-fe716cc6c541239a34d55c0ca5812379a821779a.zip
fixed builtin mocks for py3k
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py4
-rw-r--r--testsuite/Testlib/TestServer/TestPlugin.py12
-rw-r--r--testsuite/Testlib/TestServer/TestPlugins/TestMetadata.py4
-rw-r--r--testsuite/Testlib/TestServer/TestPlugins/TestProbes.py6
-rw-r--r--testsuite/common.py10
5 files changed, 23 insertions, 13 deletions
diff --git a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py
index 34784dc3d..06912c19c 100644
--- a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py
+++ b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py
@@ -74,7 +74,7 @@ class TestPOSIXFile(TestPOSIXTool):
entry.text = ustr
self.assertEqual(ptool._get_data(entry), (ustr, False))
- @patch("__builtin__.open")
+ @patch("%s.open" % builtins)
@patch("Bcfg2.Client.Tools.POSIX.base.POSIXTool.verify")
@patch("Bcfg2.Client.Tools.POSIX.File.%s._exists" % test_obj.__name__)
@patch("Bcfg2.Client.Tools.POSIX.File.%s._get_data" % test_obj.__name__)
@@ -207,7 +207,7 @@ class TestPOSIXFile(TestPOSIXTool):
mock_rename.assert_called_with(newfile, entry.get("name"))
mock_unlink.assert_called_with(newfile)
- @patch("__builtin__.open")
+ @patch("%.open" % builtins)
@patch("Bcfg2.Client.Tools.POSIX.File.%s._diff" % test_obj.__name__)
@patch("Bcfg2.Client.Tools.POSIX.File.%s._get_data" % test_obj.__name__)
@patch("Bcfg2.Client.Tools.POSIX.File.%s._is_string" % test_obj.__name__)
diff --git a/testsuite/Testlib/TestServer/TestPlugin.py b/testsuite/Testlib/TestServer/TestPlugin.py
index d59b19a32..d1904a2e6 100644
--- a/testsuite/Testlib/TestServer/TestPlugin.py
+++ b/testsuite/Testlib/TestServer/TestPlugin.py
@@ -227,7 +227,7 @@ class TestThreadedStatistics(TestStatistics):
ts = self.get_obj(core)
mock_start.assert_any_call()
- @patch("__builtin__.open")
+ @patch("%s.open" % builtins)
@patch("Bcfg2.Server.Plugin.ThreadedStatistics.run", Mock())
def test_save(self, mock_open):
core = Mock()
@@ -270,7 +270,7 @@ class TestThreadedStatistics(TestStatistics):
@patch("os.unlink")
@patch("os.path.exists")
- @patch("__builtin__.open")
+ @patch("%s.open" % builtins)
@patch("lxml.etree.XML")
@patch("Bcfg2.Server.Plugin.ThreadedStatistics.run", Mock())
def test_load(self, mock_XML, mock_open, mock_exists, mock_unlink):
@@ -444,7 +444,7 @@ class TestFileBacked(Bcfg2TestCase):
def get_obj(self, path=datastore, fam=None):
return self.test_obj(path, fam=fam)
- @patch("__builtin__.open")
+ @patch("%s.open" % builtins)
def test_HandleEvent(self, mock_open):
path = "/test"
fb = self.get_obj(path)
@@ -1349,7 +1349,7 @@ class TestXMLSrc(TestXMLFileBacked):
# ensure that the node object has the necessary interface
self.assertTrue(hasattr(self.test_obj.__node__, "Match"))
- @patch("__builtin__.open")
+ @patch("%s.open" % builtins)
def test_HandleEvent(self, mock_open):
xdata = lxml.etree.Element("Test")
lxml.etree.SubElement(xdata, "Path", name="path", attr="whatever")
@@ -1603,7 +1603,7 @@ class TestSpecificData(Bcfg2TestCase):
specific = Mock()
return self.test_obj(name, specific, encoding)
- @patch("__builtin__.open")
+ @patch("%s.open" % builtins)
def test_handle_event(self, mock_open):
event = Mock()
event.code2str.return_value = 'deleted'
@@ -1912,7 +1912,7 @@ class TestEntrySet(TestDebuggable):
fails(eset, ppath + ".G20_")
fails(eset, ppath + ".H_")
- @patch("__builtin__.open")
+ @patch("%s.open" % builtins)
@patch("Bcfg2.Server.Plugin.InfoXML")
def test_update_metadata(self, mock_InfoXML, mock_open):
eset = self.get_obj()
diff --git a/testsuite/Testlib/TestServer/TestPlugins/TestMetadata.py b/testsuite/Testlib/TestServer/TestPlugins/TestMetadata.py
index ee39eb2c9..7382a4439 100644
--- a/testsuite/Testlib/TestServer/TestPlugins/TestMetadata.py
+++ b/testsuite/Testlib/TestServer/TestPlugins/TestMetadata.py
@@ -274,7 +274,7 @@ class TestXMLMetadataConfig(TestXMLFileBacked):
@patch('Bcfg2.Server.Plugins.Metadata.locked', Mock(return_value=False))
@patch('fcntl.lockf', Mock())
- @patch('__builtin__.open')
+ @patch('%s.open' % builtins)
@patch('os.unlink')
@patch('os.rename')
@patch('os.path.islink')
@@ -417,7 +417,7 @@ class TestMetadata(_TestMetadata, TestStatistics, TestDatabaseBacked):
self.get_obj, core=core, watch_clients=True)
@patch('os.makedirs', Mock())
- @patch('__builtin__.open')
+ @patch('%s.open' % builtins)
def test_init_repo(self, mock_open):
Metadata.init_repo(datastore,
groups_xml="groups", clients_xml="clients")
diff --git a/testsuite/Testlib/TestServer/TestPlugins/TestProbes.py b/testsuite/Testlib/TestServer/TestPlugins/TestProbes.py
index 3cff4ac73..a779a7707 100644
--- a/testsuite/Testlib/TestServer/TestPlugins/TestProbes.py
+++ b/testsuite/Testlib/TestServer/TestPlugins/TestProbes.py
@@ -118,7 +118,7 @@ class TestProbeSet(TestEntrySet):
ps.HandleEvent(evt)
ps.handle_event.assert_called_with(evt)
- @patch("__builtin__.list", FakeList)
+ @patch("%s.list" % builtins, FakeList)
def test_get_probe_data(self):
ps = self.get_obj()
@@ -268,7 +268,7 @@ text
probes._write_data_db.assert_called_with("test")
self.assertFalse(probes._write_data_xml.called)
- @patch("__builtin__.open")
+ @patch("%s.open" % builtins)
def test__write_data_xml(self, mock_open):
probes = self.get_probes_object(use_db=False)
probes.probedata = self.get_test_probedata()
@@ -394,7 +394,7 @@ text
probes._load_data_db.assert_any_call()
self.assertFalse(probes._load_data_xml.called)
- @patch("__builtin__.open")
+ @patch("%s.open" % builtins)
@patch("lxml.etree.parse")
def test__load_data_xml(self, mock_parse, mock_open):
probes = self.get_probes_object(use_db=False)
diff --git a/testsuite/common.py b/testsuite/common.py
index e0a27b2c7..cc24112e7 100644
--- a/testsuite/common.py
+++ b/testsuite/common.py
@@ -1,4 +1,5 @@
import os
+import sys
import unittest
from functools import wraps
@@ -7,6 +8,11 @@ datastore = "/"
XI_NAMESPACE = "http://www.w3.org/2001/XInclude"
XI = "{%s}" % XI_NAMESPACE
+if sys.hexversion >= 0x03000000:
+ inPy3k = True
+else:
+ inPy3k = False
+
try:
from django.core.management import setup_environ
has_django = True
@@ -29,6 +35,10 @@ except ImportError:
calls """
return (args, kwargs)
+if inPy3k:
+ builtins = "builtins"
+else:
+ builtins = "__builtin__"
if hasattr(unittest.TestCase, "assertItemsEqual"):
TestCase = unittest.TestCase