summaryrefslogtreecommitdiff
path: root/tests/unittests/helpers.py
diff options
context:
space:
mode:
authorVlastimil Holer <vlastimil.holer@gmail.com>2013-02-19 16:30:06 +0100
committerVlastimil Holer <vlastimil.holer@gmail.com>2013-02-19 16:30:06 +0100
commit6b0652745129808dc0669354cb3e0dc53962d6ea (patch)
tree6ec307c7c245cf68d28ef05e3f1a9f7d075ff8bc /tests/unittests/helpers.py
parente18f0f8a382729cc7c9f8df3ad0573af7eeb8f47 (diff)
parent174bc39e6b2c1cac3f73f67f25fad87cab16fa42 (diff)
downloadvyos-cloud-init-6b0652745129808dc0669354cb3e0dc53962d6ea.tar.gz
vyos-cloud-init-6b0652745129808dc0669354cb3e0dc53962d6ea.zip
Merged trunk lp:cloud-init
Diffstat (limited to 'tests/unittests/helpers.py')
-rw-r--r--tests/unittests/helpers.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py
index 92540b0c..91a50e18 100644
--- a/tests/unittests/helpers.py
+++ b/tests/unittests/helpers.py
@@ -2,6 +2,9 @@ import os
import sys
import unittest
+from contextlib import contextmanager
+
+from mocker import Mocker
from mocker import MockerTestCase
from cloudinit import helpers as ch
@@ -31,6 +34,17 @@ else:
pass
+@contextmanager
+def mocker(verify_calls=True):
+ m = Mocker()
+ try:
+ yield m
+ finally:
+ m.restore()
+ if verify_calls:
+ m.verify()
+
+
# Makes the old path start
# with new base instead of whatever
# it previously had
@@ -168,3 +182,10 @@ class FilesystemMockingTestCase(ResourceUsingTestCase):
trap_func = retarget_many_wrapper(new_root, 1, func)
setattr(mod, f, trap_func)
self.patched_funcs.append((mod, f, func))
+
+def populate_dir(path, files):
+ os.makedirs(path)
+ for (name, content) in files.iteritems():
+ with open(os.path.join(path, name), "w") as fp:
+ fp.write(content)
+ fp.close()