Ubuntu Pastebin

Paste from smoser at Tue, 20 Dec 2016 16:01:37 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
Download as text