예제 #1
0
    def test(
        self,
        monkeypatch,
        on_arch,
        to_arch,
        body,
        else_bodies,
        host_arch,
        expected_packages,
    ):
        monkeypatch.setattr(platform, "machine", lambda: host_arch)
        monkeypatch.setattr(platform, "architecture", lambda: ("64bit", "ELF"))

        processor = grammar.GrammarProcessor(
            None, snapcraft.ProjectOptions(target_deb_arch="armhf"), lambda x: True
        )
        statements = [
            on.OnStatement(on=on_arch, body=None, processor=processor),
            to.ToStatement(to=to_arch, body=None, processor=processor),
        ]
        statement = compound.CompoundStatement(
            statements=statements, body=body, processor=processor
        )

        for else_body in else_bodies:
            statement.add_else(else_body)

        assert statement.process() == expected_packages
예제 #2
0
    def test_on_statement_invalid_grammar(self):
        with testtools.ExpectedException(self.expected_exception,
                                         self.expected_message):
            processor = grammar.GrammarProcessor(
                None, snapcraft.ProjectOptions(target_deb_arch="armhf"),
                self.checker)
            statements = [
                on.OnStatement(on=self.on, body=None, processor=processor),
                to.ToStatement(to=self.to, body=None, processor=processor),
            ]
            statement = compound.CompoundStatement(statements=statements,
                                                   body=self.body,
                                                   processor=processor)

            for else_body in self.else_bodies:
                statement.add_else(else_body)

            statement.process()
예제 #3
0
    def test_compound_statement_grammar(self, platform_machine_mock,
                                        platform_architecture_mock):
        platform_machine_mock.return_value = self.host_arch
        platform_architecture_mock.return_value = ("64bit", "ELF")
        processor = grammar.GrammarProcessor(
            None, snapcraft.ProjectOptions(target_deb_arch="armhf"),
            self.checker)
        statements = [
            on.OnStatement(on=self.on, body=None, processor=processor),
            to.ToStatement(to=self.to, body=None, processor=processor),
        ]
        statement = compound.CompoundStatement(statements=statements,
                                               body=self.body,
                                               processor=processor)

        for else_body in self.else_bodies:
            statement.add_else(else_body)

        self.assertThat(statement.process(), Equals(self.expected_packages))
예제 #4
0
    def test(self, on_arch, to_arch, body, else_bodies, expected_exception,
             expected_message):
        with pytest.raises(expected_exception) as error:
            processor = grammar.GrammarProcessor(
                None,
                snapcraft.ProjectOptions(target_deb_arch="armhf"),
                lambda x: "invalid" not in x,
            )
            statements = [
                on.OnStatement(on=on_arch, body=None, processor=processor),
                to.ToStatement(to=to_arch, body=None, processor=processor),
            ]
            statement = compound.CompoundStatement(statements=statements,
                                                   body=body,
                                                   processor=processor)

            for else_body in else_bodies:
                statement.add_else(else_body)

            statement.process()

        assert re.match(expected_message, str(error.value))