summaryrefslogtreecommitdiff
path: root/tests/unittests
diff options
context:
space:
mode:
authorDaniel Watkins <daniel.watkins@canonical.com>2015-02-11 11:54:48 +0000
committerDaniel Watkins <daniel.watkins@canonical.com>2015-02-11 11:54:48 +0000
commitabccec1150d6fada29eae9819968e3d4419440ab (patch)
treeb79626a2bcf3a97b35936460fd977265bc65d3c4 /tests/unittests
parent4cfdde8be624f5dc9a9ec214ea60f9d1f43ee424 (diff)
downloadvyos-cloud-init-abccec1150d6fada29eae9819968e3d4419440ab.tar.gz
vyos-cloud-init-abccec1150d6fada29eae9819968e3d4419440ab.zip
Add helpers for patching open and stdout/stderr.
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/helpers.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py
index 6b9394b3..ce77af93 100644
--- a/tests/unittests/helpers.py
+++ b/tests/unittests/helpers.py
@@ -254,6 +254,19 @@ class FilesystemMockingTestCase(ResourceUsingTestCase):
self.patched_funcs.enter_context(
mock.patch.object(mod, f, trap_func))
+ def patchOpen(self, new_root):
+ trap_func = retarget_many_wrapper(new_root, 1, open)
+ name = 'builtins.open' if PY3 else '__builtin__.open'
+ self.patched_funcs.enter_context(mock.patch(name, trap_func))
+
+ def patchStdoutAndStderr(self, stdout=None, stderr=None):
+ if stdout is not None:
+ self.patched_funcs.enter_context(
+ mock.patch.object(sys, 'stdout', stdout))
+ if stderr is not None:
+ self.patched_funcs.enter_context(
+ mock.patch.object(sys, 'stderr', stderr))
+
class HttprettyTestCase(TestCase):
# necessary as http_proxy gets in the way of httpretty