示例#1
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)
示例#2
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))
示例#3
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))
示例#4
0
    def test_fix_xml_tools(self):
        for test_file in self.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 self.files:
            self.assertThat(test_file["path"],
                            FileContains(test_file["expected"]))
示例#5
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(self.tempdir).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))
示例#6
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('root').normalize('root')

        with open(self.file_path, 'r') as fd:
            self.assertEqual(fd.read(), self.expected)
示例#7
0
    def test_fix_xml_tools(self):
        for test_file in self.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('root').normalize('root')

        for test_file in self.files:
            self.assertThat(
                test_file['path'], FileContains(test_file['expected']))
示例#8
0
    def test_fix_symlinks(self):
        os.symlink(self.src, self.dst)

        BaseRepo(self.tempdir).normalize(self.tempdir)

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