diff options
author | Daniel Watkins <daniel.watkins@canonical.com> | 2015-02-11 11:54:48 +0000 |
---|---|---|
committer | Daniel Watkins <daniel.watkins@canonical.com> | 2015-02-11 11:54:48 +0000 |
commit | abccec1150d6fada29eae9819968e3d4419440ab (patch) | |
tree | b79626a2bcf3a97b35936460fd977265bc65d3c4 /tests | |
parent | 4cfdde8be624f5dc9a9ec214ea60f9d1f43ee424 (diff) | |
download | vyos-cloud-init-abccec1150d6fada29eae9819968e3d4419440ab.tar.gz vyos-cloud-init-abccec1150d6fada29eae9819968e3d4419440ab.zip |
Add helpers for patching open and stdout/stderr.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unittests/helpers.py | 13 |
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 |