示例#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())
示例#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)
示例#3
0
    def test_remove_useless_files(self):
        path = os.path.join("root", self.file_path)
        os.makedirs(os.path.dirname(path), exist_ok=True)
        open(path, "w").close()

        BaseRepo.normalize("root")

        self.assertThat(path, self.matcher)
示例#4
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))
示例#5
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))
示例#6
0
    def test_fix_suid(self):
        file = os.path.join(self.tempdir, self.key)
        open(file, mode="w").close()
        os.chmod(file, self.test_mod)

        BaseRepo.normalize(self.tempdir)

        self.assertThat(stat.S_IMODE(os.stat(file).st_mode),
                        Equals(self.expected_mod))
示例#7
0
    def test_fix_shebang(self):
        os.makedirs(os.path.dirname(self.file_path), exist_ok=True)
        with open(self.file_path, "w") as fd:
            fd.write(self.content)

        BaseRepo.normalize("root")

        with open(self.file_path, "r") as fd:
            self.assertThat(fd.read(), Equals(self.expected))
示例#8
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"]))
示例#9
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"]))
示例#10
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()))
示例#11
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))
示例#12
0
    def test_fix_symlinks(self):
        os.symlink(self.src, self.dst)

        BaseRepo.normalize(self.tempdir)

        self.assertThat(os.readlink(self.dst), Equals(self.src))