from cloudinit import stages
from cloudinit import util
from .helpers import TestCase, mock
class TestFetchBaseConfig(TestCase):
def wrap_and_call(self, mocks, func, *args, **kwargs):
# call func(args, **kwargs) and mocks applied and then unapplied.
#
# possibly nicer than repeating dectorators on each function.
#
# mocks is a dictionary of name (under cloudinit.stages.util.)
# and either a return value or a dictionary to pass to the mock.patch
# call. This
pre = "cloudinit.stages.util."
unwraps = []
for fname, kw in mocks.items():
if not isinstance(kw, dict):
kw = {'return_value': kw}
p = mock.patch(pre + + fname, **kw)
p.start()
unwraps.append(p)
try:
return func(*args, *kwargs)
finally:
for p in unwraps:
p.stop()
def test_only_builtin_gets_builtin2(self):
ret = self.wrap_and_call(
{'read_conf_with_confd': None,
'read_cc_from_cmdline': None},
stages.fetch_base_config)
self.assertEqual(util.get_builtin_cfg(), ret)
# vi: ts=4 expandtab