Esempio n. 1
0
    def test_build(self):
        plugin = plainbox_provider.PlainboxProviderPlugin(
            "test-part", self.options, self.project)

        os.makedirs(plugin.sourcedir)

        # Place a few files with bad shebangs, and some files that shouldn't be
        # changed.
        files = [
            {
                "path": os.path.join(plugin.installdir, "baz"),
                "contents": "#!/foo/bar/baz/python3",
                "expected": "#!/usr/bin/env python3",
            },
            {
                "path": os.path.join(plugin.installdir, "bin", "foobar"),
                "contents": "#!/foo/baz/python3.5",
                "expected": "#!/usr/bin/env python3.5",
            },
            {
                "path": os.path.join(plugin.installdir, "foo"),
                "contents": "foo",
                "expected": "foo",
            },
            {
                "path": os.path.join(plugin.installdir, "bar"),
                "contents": "bar\n#!/usr/bin/python3",
                "expected": "bar\n#!/usr/bin/python3",
            },
        ]

        for file_info in files:
            os.makedirs(os.path.dirname(file_info["path"]), exist_ok=True)
            with open(file_info["path"], "w") as f:
                f.write(file_info["contents"])

        plugin.build()

        env = os.environ.copy()
        env["PROVIDERPATH"] = ""
        calls = [
            mock.call(["python3", "manage.py", "validate"], env=env),
            mock.call(["python3", "manage.py", "build"]),
            mock.call(["python3", "manage.py", "i18n"]),
            mock.call([
                "python3",
                "manage.py",
                "install",
                "--layout=relocatable",
                "--prefix=/providers/test-part",
                "--root={}".format(plugin.installdir),
            ]),
        ]
        self.mock_run.assert_has_calls(calls)

        for file_info in files:
            with open(os.path.join(plugin.installdir, file_info["path"]),
                      "r") as f:
                self.assertThat(f.read(), Equals(file_info["expected"]))
Esempio n. 2
0
    def test_fileset_ignores(self):
        plugin = plainbox_provider.PlainboxProviderPlugin(
            "test-part", self.options, self.project)

        expected_fileset = [
            "-usr/lib/python*/sitecustomize.py",
            "-etc/python*/sitecustomize.py",
        ]
        fileset = plugin.snap_fileset()
        self.assertListEqual(expected_fileset, fileset)