summaryrefslogtreecommitdiff
path: root/tests/unittests/helpers.py
diff options
context:
space:
mode:
authorWesley Wiedenmeier <wesley.wiedenmeier@gmail.com>2016-12-20 10:12:24 -0600
committerScott Moser <smoser@brickies.net>2016-12-21 10:12:27 -0500
commit0b0f254a6935a1b1fff128fa177152dd519e1a3d (patch)
tree967ff205e822f6a8fac8c65ae82bcfb6d21d09c2 /tests/unittests/helpers.py
parent93cf879ddee1e492d66b02a41965323f5a165784 (diff)
downloadvyos-cloud-init-0b0f254a6935a1b1fff128fa177152dd519e1a3d.tar.gz
vyos-cloud-init-0b0f254a6935a1b1fff128fa177152dd519e1a3d.zip
Fix config order of precedence, putting kernel command line over system.
The correct order of precedence when reading the base config: builtin config system config kernel command line provided config. This reverts commit 63501f44, which actually broke the behavior it reported to fix. It also adds some unit tests to ensure this behavior is not broken again. LP: #1582323
Diffstat (limited to 'tests/unittests/helpers.py')
-rw-r--r--tests/unittests/helpers.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py
index a2355a79..a73e3f61 100644
--- a/tests/unittests/helpers.py
+++ b/tests/unittests/helpers.py
@@ -300,6 +300,39 @@ def dir2dict(startdir, prefix=None):
return flist
+def wrap_and_call(prefix, mocks, func, *args, **kwargs):
+ """
+ call func(args, **kwargs) with mocks applied, then unapplies mocks
+ nicer to read than repeating dectorators on each function
+
+ prefix: prefix for mock names (e.g. 'cloudinit.stages.util') or None
+ mocks: dictionary of names (under 'prefix') to mock and either
+ a return value or a dictionary to pass to the mock.patch call
+ func: function to call with mocks applied
+ *args,**kwargs: arguments for 'func'
+
+ return_value: return from 'func'
+ """
+ delim = '.'
+ if prefix is None:
+ prefix = ''
+ prefix = prefix.rstrip(delim)
+ unwraps = []
+ for fname, kw in mocks.items():
+ if prefix:
+ fname = delim.join((prefix, fname))
+ if not isinstance(kw, dict):
+ kw = {'return_value': kw}
+ p = mock.patch(fname, **kw)
+ p.start()
+ unwraps.append(p)
+ try:
+ return func(*args, **kwargs)
+ finally:
+ for p in unwraps:
+ p.stop()
+
+
try:
skipIf = unittest.skipIf
except AttributeError: