示例#1
0
    def test_enforce_nice_config(self):
        atoms = [
            ("*/*::repo", "repo"),
            ("*/pkg1::repo", "pkg1"),
            ("cat/*", "cat_"),
            ("cat/pkg2", "cat/pkg2"),
            ("cat/pkg3::repo", "cat/pkg3"),
            ("<cat/pkg4-0.0.0.0", "cat/pkg4"),
            (">cat/pkg5-0.0.0.0:0", "cat/pkg5"),
            (">cat/pkg6-0.0.0.0:0::repo", "cat/pkg6"),
            ("<=cat/pkg7-0.0.0.0", "cat/pkg7"),
            ("=cat/pkg8-0.0.0.0", "cat/pkg8"),
        ]

        supported = [
            ("accept_keywords", ["~amd64"]),
            ("env", ["glibc.conf"]),
            ("license", ["LICENCE1", "LICENCE2"]),
            ("mask", [""]),
            ("properties", ["* -interactive"]),
            ("unmask", [""]),
            ("use", ["apple", "-banana", "ananas", "orange"]),
        ]

        base_path = RUNTIME_VARS.TMP + '/package.{0}'

        def make_line(atom, addition):
            return atom + (" " + addition if addition != "" else "") + "\n"

        for typ, additions in supported:
            path = base_path.format(typ)
            with salt.utils.files.fopen(path, "a") as fh:
                for atom, _ in atoms:
                    for addition in additions:
                        line = make_line(atom, addition)
                        fh.write("# comment for: " + line)
                        fh.write(line)

        with patch.object(portage_config, "BASE_PATH", base_path):
            with patch.object(portage_config, "_merge_flags",
                              lambda l1, l2, _: list(set(l1 + l2))):
                portage_config.enforce_nice_config()

        for typ, additions in supported:
            for atom, file_name in atoms:
                with salt.utils.files.fopen(
                        base_path.format(typ) + "/" + file_name, "r") as fh:
                    for line in fh:
                        self.assertTrue(atom in line,
                                        msg="'{}' not in '{}'".format(
                                            addition, line))
                        for addition in additions:
                            self.assertTrue(
                                addition in line,
                                msg="'{}' not in '{}'".format(addition, line),
                            )
示例#2
0
    def test_enforce_nice_config(self):
        atoms = [
            ('*/*::repo', 'repo'),
            ('*/pkg1::repo', 'pkg1'),
            ('cat/*', 'cat_'),
            ('cat/pkg2', 'cat/pkg2'),
            ('cat/pkg3::repo', 'cat/pkg3'),
            ('<cat/pkg4-0.0.0.0', 'cat/pkg4'),
            ('>cat/pkg5-0.0.0.0:0', 'cat/pkg5'),
            ('>cat/pkg6-0.0.0.0:0::repo', 'cat/pkg6'),
            ('<=cat/pkg7-0.0.0.0', 'cat/pkg7'),
            ('=cat/pkg8-0.0.0.0', 'cat/pkg8'),
        ]

        supported = [
            ('accept_keywords', ['~amd64']),
            ('env', ['glibc.conf']),
            ('license', ['LICENCE1', 'LICENCE2']),
            ('mask', ['']),
            ('properties', ['* -interactive']),
            ('unmask', ['']),
            ('use', ['apple', '-banana', 'ananas', 'orange']),
        ]

        base_path = TMP + '/package.{0}'

        def make_line(atom, addition):
            return atom + (' ' + addition if addition != '' else '') + '\n'

        for typ, additions in supported:
            path = base_path.format(typ)
            with salt.utils.files.fopen(path, 'a') as fh:
                for atom, _ in atoms:
                    for addition in additions:
                        line = make_line(atom, addition)
                        fh.write('# comment for: ' + line)
                        fh.write(line)

        with patch.object(portage_config, 'BASE_PATH', base_path):
            with patch.object(portage_config, '_merge_flags',
                              lambda l1, l2, _: list(set(l1 + l2))):
                portage_config.enforce_nice_config()

        for typ, additions in supported:
            for atom, file_name in atoms:
                with salt.utils.files.fopen(
                        base_path.format(typ) + "/" + file_name, 'r') as fh:
                    for line in fh:
                        self.assertTrue(atom in line,
                                        msg="'{}' not in '{}'".format(
                                            addition, line))
                        for addition in additions:
                            self.assertTrue(addition in line,
                                            msg="'{}' not in '{}'".format(
                                                addition, line))