Ejemplo n.º 1
0
    def setUp(self):
        super().setUp()

        # Use "clean" step for testing provider handling.
        self.step = "clean"

        # Don't actually run clean - we only want to test the command
        # line interface flag parsing.
        self.useFixture(
            fixtures.MockPatch("snapcraft_legacy.internal.lifecycle.clean"))

        # tests.legacy.unit.TestCase sets SNAPCRAFT_BUILD_ENVIRONMENT to host.
        # These build provider tests will want to set this explicitly.
        self.useFixture(
            fixtures.EnvironmentVariable("SNAPCRAFT_BUILD_ENVIRONMENT", None))

        self.mock_get_provider_for = self.useFixture(
            fixtures.MockPatch(
                "snapcraft_legacy.internal.build_providers.get_provider_for",
                return_value=ProviderImpl,
            )).mock

        # Tests need to dictate this (or not).
        self.useFixture(
            fixtures.MockPatch(
                "snapcraft_legacy.internal.common.is_process_container",
                return_value=False,
            ))

        self.useFixture(fixture_setup.FakeMultipass())

        snapcraft_yaml = fixture_setup.SnapcraftYaml(self.path, base="core20")
        snapcraft_yaml.update_part("part1", dict(plugin="nil"))
        self.useFixture(snapcraft_yaml)
Ejemplo n.º 2
0
    def setUp(self):
        super().setUp()
        self.useFixture(
            fixtures.EnvironmentVariable("SNAPCRAFT_BUILD_ENVIRONMENT",
                                         "multipass"))

        patcher = mock.patch(
            "snapcraft_legacy.internal.build_providers.get_provider_for",
            return_value=ProviderImpl,
        )
        self.provider = patcher.start()
        self.addCleanup(patcher.stop)

        self.useFixture(fixture_setup.FakeMultipass())
Ejemplo n.º 3
0
    def setUp(self):
        super().setUp()
        self.useFixture(
            fixtures.EnvironmentVariable("SNAPCRAFT_BUILD_ENVIRONMENT",
                                         "multipass"))
        self.useFixture(fixture_setup.FakeMultipass())

        clean_project_mock = mock.Mock()
        clean_mock = mock.Mock()

        class Provider(ProviderImpl):
            def execute_step(
                    self,
                    step: steps.Step,
                    part_names: Optional[Sequence[str]] = None) -> None:
                if part_names is None:
                    part_names = []
                else:
                    part_names = list(part_names)

                raise ProviderExecError(
                    provider_name="fake",
                    command=["snapcraft", "pull"] + part_names,
                    exit_code=1,
                )

            def clean_project(self):
                clean_project_mock()

            def clean_parts(self, part_names):
                clean_mock(part_names=part_names)

        patcher = mock.patch(
            "snapcraft_legacy.internal.build_providers.get_provider_for",
            return_value=Provider,
        )
        self.provider = patcher.start()
        self.addCleanup(patcher.stop)

        self.clean_project_mock = clean_project_mock
        self.clean_mock = clean_mock

        self.make_snapcraft_yaml("pull", base="core20")
Ejemplo n.º 4
0
    def setUp(self):
        super().setUp()
        self.useFixture(
            fixtures.EnvironmentVariable("SNAPCRAFT_BUILD_ENVIRONMENT",
                                         "multipass"))
        self.useFixture(fixture_setup.FakeMultipass())

        mount_prime_mock = mock.Mock(return_value=False)

        class Provider(ProviderImpl):
            def _mount_prime_directory(self) -> bool:
                return mount_prime_mock()

        patcher = mock.patch(
            "snapcraft_legacy.internal.build_providers.get_provider_for",
            return_value=Provider,
        )
        self.provider = patcher.start()
        self.addCleanup(patcher.stop)

        self.mount_prime_mock = mount_prime_mock

        self.make_snapcraft_yaml("pull", base="core20")
Ejemplo n.º 5
0
    def setUp(self):
        super().setUp()
        self.useFixture(
            fixtures.EnvironmentVariable("SNAPCRAFT_BUILD_ENVIRONMENT",
                                         "multipass"))
        self.useFixture(fixture_setup.FakeMultipass())

        shell_mock = mock.Mock()
        pack_project_mock = mock.Mock()
        execute_step_mock = mock.Mock()

        class Provider(ProviderImpl):
            def pack_project(self, *, output: Optional[str] = None) -> None:
                pack_project_mock(output)

            def execute_step(
                    self,
                    step: steps.Step,
                    part_names: Optional[Sequence[str]] = None) -> None:
                execute_step_mock(step, part_names=part_names)

            def shell(self):
                shell_mock()

        patcher = mock.patch(
            "snapcraft_legacy.internal.build_providers.get_provider_for",
            return_value=Provider,
        )
        self.provider = patcher.start()
        self.addCleanup(patcher.stop)

        self.shell_mock = shell_mock
        self.pack_project_mock = pack_project_mock
        self.execute_step_mock = execute_step_mock

        self.make_snapcraft_yaml("pull", base="core20")