Ejemplo n.º 1
0
    def test_download_zip(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        fold = get_temp_folder(__file__, "temp_download")
        url = "https://docs.python.org/3.5/library/ftplib.html"
        f = download(url, fold)
        fLOG(f)
        assert os.path.exists(f)
        if not f.endswith("ftplib.html"):
            raise Exception(f)

        out = os.path.join(fold, "try.html.gz")
        r = gzip_files(out, [f], fLOG=fLOG)
        fLOG(r)
        assert os.path.exists(out)

        out = os.path.join(fold, "try.zip")
        r = zip_files(out, [f], fLOG=fLOG)
        fLOG(r)
        assert os.path.exists(out)

        if is_travis_or_appveyor() is None:
            out7 = os.path.join(fold, "try.7z")
            r = zip7_files(out7, [f, out], fLOG=fLOG, temp_folder=fold)
            fLOG(r)
            if not os.path.exists(out7):
                raise FileNotFoundError(out7)
        else:
            fLOG("skip 7z")
Ejemplo n.º 2
0
    def test_compress_7zip(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        fold = get_temp_folder(__file__, "temp_compress_7zip")
        url = "https://docs.python.org/3.5/library/ftplib.html"
        f = download(url, fold)

        if is_travis_or_appveyor() != "travis":
            out7 = os.path.join(fold, "try.7z")
            r = zip7_files(out7, [f], fLOG=fLOG, temp_folder=fold)
            fLOG(r)
            if not os.path.exists(out7):
                raise FileNotFoundError(out7)
        else:
            warnings.warn(
                "unzipping files with 7z on a is not tested on appveyor")
            return

        if sys.version_info[0] == 2:
            typbytes = bytearray
        else:
            typbytes = bytes

        if is_travis_or_appveyor() == "appveyor":
            warnings.warn(
                "py7zlib.py requires to be updated with the github version")
            return

        from py7zlib import COMPRESSION_METHOD_COPY
        fLOG("***", COMPRESSION_METHOD_COPY)
        res = un7zip_files(out7)
        assert isinstance(res, list)
        self.assertEqual(len(res), 1)
        fLOG(res[0][0])
        if not isinstance(res[0][1], (typbytes, str)):
            raise TypeError(type(res[0][1]))
        assert res[0][0].endswith("ftplib.html")

        fold = get_temp_folder(__file__, "temp_compress_7zip2")
        res = un7zip_files(out7, where_to=fold, fLOG=fLOG)

        if sys.version_info[0] == 2:
            return

        self.assertEqual(len(res), 1)
        s = res[0].replace("\\", "/")
        if not s.endswith("_unittests/ut_filehelper/temp_compress_7zip2/ftplib.html"):
            raise Exception(res[0])