diff options
| author | Vlastimil Holer <vlastimil.holer@gmail.com> | 2013-02-19 16:30:06 +0100 |
|---|---|---|
| committer | Vlastimil Holer <vlastimil.holer@gmail.com> | 2013-02-19 16:30:06 +0100 |
| commit | 6b0652745129808dc0669354cb3e0dc53962d6ea (patch) | |
| tree | 6ec307c7c245cf68d28ef05e3f1a9f7d075ff8bc /tests/unittests/helpers.py | |
| parent | e18f0f8a382729cc7c9f8df3ad0573af7eeb8f47 (diff) | |
| parent | 174bc39e6b2c1cac3f73f67f25fad87cab16fa42 (diff) | |
| download | vyos-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.py | 21 |
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() |
