예제 #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_to_statement_grammar(self, platform_machine_mock,
                                  platform_architecture_mock):
        platform_machine_mock.return_value = 'x86_64'
        platform_architecture_mock.return_value = ('64bit', 'ELF')
        options = snapcraft.ProjectOptions(target_deb_arch=self.target_arch)
        statement = to.ToStatement(
            to=self.to, body=self.body, project_options=options,
            checker=self.checker)

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

        self.assertThat(statement.process(), Equals(self.expected_packages))
예제 #3
0
    def test(self, monkeypatch, to_arch, body, else_bodies, target_arch,
             expected_packages):
        monkeypatch.setattr(platform, "machine", lambda: "x86_64")
        monkeypatch.setattr(platform, "architecture", lambda: ("64bit", "ELF"))
        processor = grammar.GrammarProcessor(
            None, snapcraft.ProjectOptions(target_deb_arch=target_arch),
            lambda x: True)
        statement = to.ToStatement(to=to_arch, body=body, processor=processor)

        for else_body in else_bodies:
            statement.add_else(else_body)

        assert statement.process() == expected_packages
예제 #4
0
    def test_to_statement_invalid_grammar(self):
        with testtools.ExpectedException(grammar.errors.ToStatementSyntaxError,
                                         self.expected_exception):
            options = snapcraft.ProjectOptions(
                target_deb_arch=self.target_arch)
            statement = to.ToStatement(to=self.to,
                                       body=self.body,
                                       project_options=options,
                                       checker=self.checker)

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

            statement.process()
예제 #5
0
def test_else_fail(monkeypatch):
    monkeypatch.setattr(platform, "machine", lambda: "x86_64")
    monkeypatch.setattr(platform, "architecture", lambda: ("64bit", "ELF"))

    processor = grammar.GrammarProcessor(
        None, snapcraft.ProjectOptions(target_deb_arch="i386"), lambda x: True
    )
    statement = to.ToStatement(to="to armhf", body=["foo"], processor=processor)

    statement.add_else(None)

    with pytest.raises(grammar.errors.UnsatisfiedStatementError) as error:
        statement.process()

    assert str(error.value) == "Unable to satisfy 'to armhf', failure forced"
예제 #6
0
    def test(self, to_arch, body, else_bodies, target_arch, expected_exception):
        with pytest.raises(grammar.errors.ToStatementSyntaxError) as error:
            processor = grammar.GrammarProcessor(
                None,
                snapcraft.ProjectOptions(target_deb_arch=target_arch),
                lambda x: True,
            )
            statement = to.ToStatement(to=to_arch, body=body, processor=processor)

            for else_body in else_bodies:
                statement.add_else(else_body)

            statement.process()

        assert re.match(expected_exception, str(error.value))
예제 #7
0
    def test_else_fail(self, platform_machine_mock,
                       platform_architecture_mock):
        platform_machine_mock.return_value = 'x86_64'
        platform_architecture_mock.return_value = ('64bit', 'ELF')
        options = snapcraft.ProjectOptions(target_deb_arch='i386')
        statement = to.ToStatement(to='to armhf',
                                   body=['foo'],
                                   project_options=options,
                                   checker=self.checker)

        statement.add_else(None)

        with testtools.ExpectedException(
                grammar.errors.UnsatisfiedStatementError,
                "Unable to satisfy 'to armhf', failure forced"):
            statement.process()
예제 #8
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()
예제 #9
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))
예제 #10
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))