summaryrefslogtreecommitdiff
path: root/tests/unittests/test_builtin_handlers.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2015-01-22 18:38:30 -0500
committerBarry Warsaw <barry@python.org>2015-01-22 18:38:30 -0500
commit508670bdaf9545b6bcc8e2009e8bd3f08d6f8796 (patch)
tree613e6abbce7556f39ff2987bf7c4aa565b5a8a39 /tests/unittests/test_builtin_handlers.py
parentb3bbd3985a75d00115e1623dc1ebd4248a7024a6 (diff)
downloadvyos-cloud-init-508670bdaf9545b6bcc8e2009e8bd3f08d6f8796.tar.gz
vyos-cloud-init-508670bdaf9545b6bcc8e2009e8bd3f08d6f8796.zip
More test ports from mocker to mock.
Diffstat (limited to 'tests/unittests/test_builtin_handlers.py')
-rw-r--r--tests/unittests/test_builtin_handlers.py38
1 files changed, 24 insertions, 14 deletions
diff --git a/tests/unittests/test_builtin_handlers.py b/tests/unittests/test_builtin_handlers.py
index af7f442e..47ff6318 100644
--- a/tests/unittests/test_builtin_handlers.py
+++ b/tests/unittests/test_builtin_handlers.py
@@ -1,6 +1,13 @@
"""Tests of the built-in user data handlers."""
import os
+import shutil
+import tempfile
+
+try:
+ from unittest import mock
+except ImportError:
+ import mock
from . import helpers as test_helpers
@@ -16,8 +23,10 @@ from cloudinit.settings import (PER_ALWAYS, PER_INSTANCE)
class TestBuiltins(test_helpers.FilesystemMockingTestCase):
def test_upstart_frequency_no_out(self):
- c_root = self.makeDir()
- up_root = self.makeDir()
+ c_root = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, c_root)
+ up_root = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, up_root)
paths = helpers.Paths({
'cloud_dir': c_root,
'upstart_dir': up_root,
@@ -36,7 +45,8 @@ class TestBuiltins(test_helpers.FilesystemMockingTestCase):
def test_upstart_frequency_single(self):
# files should be written out when frequency is ! per-instance
- new_root = self.makeDir()
+ new_root = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, new_root)
freq = PER_INSTANCE
self.patchOS(new_root)
@@ -49,16 +59,16 @@ class TestBuiltins(test_helpers.FilesystemMockingTestCase):
util.ensure_dir("/run")
util.ensure_dir("/etc/upstart")
- mock_subp = self.mocker.replace(util.subp, passthrough=False)
- mock_subp(["initctl", "reload-configuration"], capture=False)
- self.mocker.replay()
+ with mock.patch.object(util, 'subp') as mockobj:
+ h = upstart_job.UpstartJobPartHandler(paths)
+ h.handle_part('', handlers.CONTENT_START,
+ None, None, None)
+ h.handle_part('blah', 'text/upstart-job',
+ 'test.conf', 'blah', freq)
+ h.handle_part('', handlers.CONTENT_END,
+ None, None, None)
- h = upstart_job.UpstartJobPartHandler(paths)
- h.handle_part('', handlers.CONTENT_START,
- None, None, None)
- h.handle_part('blah', 'text/upstart-job',
- 'test.conf', 'blah', freq)
- h.handle_part('', handlers.CONTENT_END,
- None, None, None)
+ self.assertEquals(len(os.listdir('/etc/upstart')), 1)
- self.assertEquals(1, len(os.listdir('/etc/upstart')))
+ mockobj.assert_called_once_with(
+ ['initctl', 'reload-configuration'], capture=False)