Beispiel #1
0
    def test_no_remove(self):
        path = self.create(os.path.join("opt", "python3.5",
                                        "sitecustomize.py"))

        BaseRepo.normalize("root")

        self.assertThat(path, FileExists())
Beispiel #2
0
    def test_skip_directories_matching_pc(self):
        snap_pc_dir = os.path.join(self.tempdir, "snap.pc")

        os.mkdir(snap_pc_dir)

        # Verify the directory is not passed to fileinput, which would
        # try to file copy snap.pc to snap.pc.bak for the inplace replace.
        BaseRepo.normalize(self.tempdir)
Beispiel #3
0
    def assert_mode(self, key, test_mod, expected_mod):
        file = os.path.join(self.tempdir, key)
        open(file, mode="w").close()
        os.chmod(file, test_mod)

        BaseRepo.normalize(self.tempdir)

        self.assertThat(stat.S_IMODE(os.stat(file).st_mode),
                        Equals(expected_mod))
Beispiel #4
0
    def assert_fix(self, src, dst):
        os.makedirs("a")
        open("1", mode="w").close()

        os.symlink(src, dst)

        BaseRepo.normalize(self.tempdir)

        self.assertThat(os.readlink(dst), Equals(src))
Beispiel #5
0
    def test_fix_shebang(self):
        for _, data in self.scenarios:
            os.makedirs(os.path.dirname(data["file_path"]), exist_ok=True)
            with open(data["file_path"], "w") as fd:
                fd.write(data["content"])

        BaseRepo.normalize("root")

        for _, data in self.scenarios:
            with open(data["file_path"], "r") as fd:
                self.expectThat(fd.read(), Equals(data["expected"]))
Beispiel #6
0
    def assert_fix(self, files):
        for test_file in files:
            path = test_file["path"]
            os.makedirs(os.path.dirname(path), exist_ok=True)
            with open(path, "w") as f:
                f.write(test_file["content"])

        BaseRepo.normalize("root")

        for test_file in files:
            self.assertThat(test_file["path"],
                            FileContains(test_file["expected"]))
Beispiel #7
0
    def test_remove(self):
        paths = [
            self.create(p) for p in [
                os.path.join("usr", "lib", "python3.5", "sitecustomize.py"),
                os.path.join("usr", "lib", "python2.7", "sitecustomize.py"),
                os.path.join("usr", "lib", "python", "sitecustomize.py"),
            ]
        ]

        BaseRepo.normalize("root")

        for p in paths:
            self.expectThat(p, Not(FileExists()))
Beispiel #8
0
    def test_fix_pkg_config(self):
        pc_file = os.path.join(self.tempdir, "granite.pc")

        with open(pc_file, "w") as f:
            f.write(
                dedent("""\
                prefix=/usr
                exec_prefix=${prefix}
                libdir=${prefix}/lib
                includedir=${prefix}/include

                Name: granite
                Description: elementary\'s Application Framework
                Version: 0.4
                Libs: -L${libdir} -lgranite
                Cflags: -I${includedir}/granite
                Requires: cairo gee-0.8 glib-2.0 gio-unix-2.0 gobject-2.0
            """))

        BaseRepo.normalize(self.tempdir)

        expected_pc_file_content = dedent("""\
            prefix={}/usr
            exec_prefix=${{prefix}}
            libdir=${{prefix}}/lib
            includedir=${{prefix}}/include

            Name: granite
            Description: elementary's Application Framework
            Version: 0.4
            Libs: -L${{libdir}} -lgranite
            Cflags: -I${{includedir}}/granite
            Requires: cairo gee-0.8 glib-2.0 gio-unix-2.0 gobject-2.0
            """.format(self.tempdir))

        self.assertThat(pc_file, FileContains(expected_pc_file_content))