summaryrefslogtreecommitdiff
path: root/tests/unittests/test_util.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2015-01-22 20:52:01 -0500
committerBarry Warsaw <barry@python.org>2015-01-22 20:52:01 -0500
commit6f2a62c2fde85839ed437549597498a707f5da68 (patch)
treea21a6d5de345734de8e66d3d32bde73933399e25 /tests/unittests/test_util.py
parentc0aae445119252134e8c89b3b73999ed213135f1 (diff)
downloadvyos-cloud-init-6f2a62c2fde85839ed437549597498a707f5da68.tar.gz
vyos-cloud-init-6f2a62c2fde85839ed437549597498a707f5da68.zip
Conversion from mocker to mock completed.
Diffstat (limited to 'tests/unittests/test_util.py')
-rw-r--r--tests/unittests/test_util.py31
1 files changed, 19 insertions, 12 deletions
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
index 5ac47b80..b1f5d62c 100644
--- a/tests/unittests/test_util.py
+++ b/tests/unittests/test_util.py
@@ -6,6 +6,12 @@ import tempfile
from . import helpers
import unittest
+import six
+
+try:
+ from unittest import mock
+except ImportError:
+ import mock
from cloudinit import importer
from cloudinit import util
@@ -128,23 +134,24 @@ class TestWriteFile(unittest.TestCase):
with open(my_file, "w") as fp:
fp.write("My Content")
- import_mock = self.mocker.replace(importer.import_module,
- passthrough=False)
- import_mock('selinux')
-
fake_se = FakeSelinux(my_file)
- self.mocker.result(fake_se)
- self.mocker.replay()
- with util.SeLinuxGuard(my_file) as is_on:
- self.assertTrue(is_on)
+
+ with mock.patch.object(importer, 'import_module',
+ return_value=fake_se) as mockobj:
+ with util.SeLinuxGuard(my_file) as is_on:
+ self.assertTrue(is_on)
+
self.assertEqual(1, len(fake_se.restored))
self.assertEqual(my_file, fake_se.restored[0])
+ mockobj.assert_called_once_with('selinux')
-class TestDeleteDirContents(MockerTestCase):
+
+class TestDeleteDirContents(unittest.TestCase):
def setUp(self):
super(TestDeleteDirContents, self).setUp()
- self.tmp = self.makeDir(prefix="unittest_")
+ self.tmp = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, self.tmp)
def assertDirEmpty(self, dirname):
self.assertEqual([], os.listdir(dirname))
@@ -248,8 +255,8 @@ class TestLoadYaml(unittest.TestCase):
self.mydefault)
def test_python_unicode(self):
- # complex type of python/unicde is explicitly allowed
- myobj = {'1': unicode("FOOBAR")}
+ # complex type of python/unicode is explicitly allowed
+ myobj = {'1': six.text_type("FOOBAR")}
safe_yaml = yaml.dump(myobj)
self.assertEqual(util.load_yaml(blob=safe_yaml,
default=self.mydefault),