예제 #1
0
    def test_snapcraft_utils_in_path_if_snap(self):
        self.useFixture(fixture_setup.FakeSnapcraftIsASnap())

        os.mkdir("builddir")

        runner = _runner.Runner(
            part_properties={"override-build": "echo $PATH > path"},
            partdir=self.partdir,
            sourcedir="sourcedir",
            builddir="builddir",
            stagedir="stagedir",
            primedir="primedir",
            builtin_functions={},
            env_generator=lambda step: "export FOO=BAR",
        )

        runner.build()

        expected_path_segment = "/snap/snapcraft/current/bin/scriptlet-bin"

        self.assertThat(os.path.join("builddir", "path"), FileExists())
        self.assertThat(
            os.path.join("builddir", "path"),
            FileContains(matcher=Contains(expected_path_segment)),
        )
예제 #2
0
    def test_snapcraftctl_errors_on_exception(self):
        os.mkdir("primedir")

        class _TestException(errors.ScriptletBaseError):
            fmt = "I'm an error"

        def _raise():
            raise _TestException()

        runner = _runner.Runner(
            part_properties={"override-prime": "snapcraftctl prime"},
            partdir=self.partdir,
            sourcedir="sourcedir",
            builddir="builddir",
            stagedir="stagedir",
            primedir="primedir",
            builtin_functions={"prime": _raise},
            env_generator=lambda step: "export FOO=BAR",
        )

        silent_popen = functools.partial(subprocess.Popen,
                                         stdout=subprocess.DEVNULL,
                                         stderr=subprocess.DEVNULL)

        with mock.patch("subprocess.Popen", wraps=silent_popen):
            self.assertRaises(_TestException, runner.prime)
예제 #3
0
    def test_builtin_function_from_pull(self):
        os.mkdir("sourcedir")

        runner = _runner.Runner(
            part_properties={"override-pull": "snapcraftctl pull"},
            partdir=self.partdir,
            sourcedir="sourcedir",
            builddir="builddir",
            stagedir="stagedir",
            primedir="primedir",
            builtin_functions={"pull": _fake_pull},
            env_generator=lambda step: "export FOO=BAR",
        )

        runner.pull()

        self.assertThat(os.path.join("sourcedir", "fake-pull"), FileExists())
예제 #4
0
    def test_snapcraftctl_no_alias_if_not_snap(self):
        os.mkdir("builddir")

        runner = _runner.Runner(
            part_properties={
                "override-build": "alias snapcraftctl 2> /dev/null"
            },
            partdir=self.partdir,
            sourcedir="sourcedir",
            builddir="builddir",
            stagedir="stagedir",
            primedir="primedir",
            builtin_functions={},
            env_generator=lambda step: "export FOO=BAR",
        )

        self.assertRaises(errors.ScriptletRunError, runner.build)
예제 #5
0
    def test_prime(self):
        os.mkdir("primedir")

        runner = _runner.Runner(
            part_properties={"override-prime": "touch prime"},
            partdir=self.partdir,
            sourcedir="sourcedir",
            builddir="builddir",
            stagedir="stagedir",
            primedir="primedir",
            builtin_functions={},
            env_generator=lambda step: "export FOO=BAR",
        )

        runner.prime()

        self.assertThat(os.path.join("primedir", "prime"), FileExists())
예제 #6
0
    def test_failure_to_execute_mid_script_results_in_failure(self):
        os.mkdir("builddir")

        script = dedent("""\
            false  # this should trigger an error
            touch success
        """)

        runner = _runner.Runner(
            part_properties={"override-build": script},
            partdir=self.partdir,
            sourcedir="sourcedir",
            builddir="builddir",
            stagedir="stagedir",
            primedir="primedir",
            builtin_functions={},
            env_generator=lambda step: "export FOO=BAR",
        )

        self.assertRaises(errors.ScriptletRunError, runner.build)