예제 #1
0
def do_test(testfile, interps, dests, stats, hint = ""):
    cover.log("Test", hint, ":", os.path.basename(testfile))
    info = cover.read_cover_info(testfile)
    resall = ""
    # prepare
    # do tests
    hasherr = []
    for interp in interps:
        if len(interps) < 6:
            resall += (interp[1] + " - ")
        res, desc = do_test_one(testfile, interp, info, dests[interp[1]])
        if res == "hasherror":
            hasherr.append(desc)
            #cover.log("HASH =", desc)
        # update statistic
        stats["_"]["_"] += 1
        stats["_"][res] = stats["_"].get(res, 0) + 1
        stats[interp[1]]["_"] += 1
        stats[interp[1]][res] = stats[interp[1]].get(res, 0) + 1
        resall += (res + " " * 10)[:6].upper()
        resall += "  "
    cover.log(resall)
    # test if all hash
    if len(interps) == len(hasherr):
        cover.err("All hashes wrong")
예제 #2
0
def do_test(testfile, interps, dests, stats, hint=""):
    cover.log("Test", hint, ":", os.path.basename(testfile))
    info = cover.read_cover_info(testfile)
    resall = ""
    # prepare
    # do tests
    hasherr = []
    for interp in interps:
        if len(interps) < 6:
            resall += (interp[1] + " - ")
        res, desc = do_test_one(testfile, interp, info, dests[interp[1]])
        if res == "hasherror":
            hasherr.append(desc)
            #cover.log("HASH =", desc)
        # update statistic
        stats["_"]["_"] += 1
        stats["_"][res] = stats["_"].get(res, 0) + 1
        stats[interp[1]]["_"] += 1
        stats[interp[1]][res] = stats[interp[1]].get(res, 0) + 1
        resall += (res + " " * 10)[:6].upper()
        resall += "  "
    cover.log(resall)
    # test if all hash
    if len(interps) == len(hasherr):
        cover.err("All hashes wrong")
예제 #3
0
def download_fonts():
    URL = "http://pyfpdf.googlecode.com/files/fpdf_unicode_font_pack.zip"
    fntdir = os.path.join(cover.basepath, "font")
    zippath = os.path.join(cover.basepath, URL.split('/')[-1])
    if not os.path.exists(fntdir):
        os.makedirs(fntdir)
    if not os.path.exists(zippath):
        u = urlopen(URL)
        meta = u.info()
        file_size = int(meta.get("Content-Length"))
        cover.log("Downloading:", file_size, "bytes")
        with open(zippath, "wb") as f:
            file_size_dl = 0
            while True:
                buff = u.read(64 * 1024)
                if not buff:
                    break
                file_size_dl += len(buff)
                f.write(buff)
                cover.log("  ", file_size_dl * 100. / file_size, "%")
    # unpack
    cover.log("Extracting")
    import zipfile
    with open(zippath, "rb") as fh:
        z = zipfile.ZipFile(fh)
        for name in z.namelist():
            if name[:5] != "font/":
                continue
            if name[5:].find("/") >= 0:
                continue
            cover.log("  ", name[5:])
            with open(os.path.join(fntdir, name[5:]), "wb") as outfile:
                outfile.write(z.read(name))
    cover.log("Done")
예제 #4
0
def search_python_win():
    lst = []
    try:
        try:
            import _winreg as winreg
        except ImportError:
            import winreg

        def findreg(key, lst):
            PATH = "SOFTWARE\\Python\\PythonCore"
            try:
                rl = winreg.OpenKey(key, PATH)
            except WindowsError:
                return lst
            try:
                for i in range(winreg.QueryInfoKey(rl)[0]):
                    ver = winreg.EnumKey(rl, i)
                    rv = winreg.QueryValue(key,
                                           PATH + "\\" + ver + "\\InstallPath")
                    fp = os.path.join(rv, "python.exe")
                    #print(fp)
                    if os.path.exists(fp) and not fp in lst:
                        lst.append(fp)
            except WindowsError:
                pass
            return lst

        lst = findreg(winreg.HKEY_LOCAL_MACHINE, lst)
        lst = findreg(winreg.HKEY_CURRENT_USER, lst)
    except:
        traceback.print_exc()
        # fallback
        cover.log("Search python at system drive")
        try:
            path = os.environ.get("SystemDrive", "C:")
            for item in os.listdir(path):
                if item[:6].lower() != "python":
                    continue
                fp = os.path.join(path, item, "python.exe")
                if os.path.exists(fp) and not fp in lst:
                    lst.append(fp)
        except:
            traceback.print_exc()

    return lst
예제 #5
0
def search_python_win():
    lst = []
    try:
        try:
            import _winreg as winreg
        except ImportError:
            import winreg
        def findreg(key, lst):
            PATH = "SOFTWARE\\Python\\PythonCore"
            try:
                rl = winreg.OpenKey(key, PATH)
            except WindowsError:
                return lst
            try:
                for i in range(winreg.QueryInfoKey(rl)[0]):
                    ver = winreg.EnumKey(rl, i)
                    rv = winreg.QueryValue(key, PATH + "\\" + ver + "\\InstallPath")
                    fp = os.path.join(rv, "python.exe")
                    #print fp
                    if os.path.exists(fp) and not fp in lst:
                        lst.append(fp)
            except WindowsError:
                pass
            return lst
        lst = findreg(winreg.HKEY_LOCAL_MACHINE, lst)
        lst = findreg(winreg.HKEY_CURRENT_USER, lst)
    except:
        traceback.print_exc()
        # fallback
        cover.log("Search python at system drive")
        try:
            path = os.environ.get("SystemDrive", "C:")
            for item in os.listdir(path):
                if item[:6].lower() != "python":
                    continue
                fp = os.path.join(path, item, "python.exe")
                if os.path.exists(fp) and not fp in lst:
                    lst.append(fp)
        except:
            traceback.print_exc()

    return lst
예제 #6
0
def print_interps(interps):
    cover.log(">> Interpreters:", len(interps))
    dests = {}
    stats = {"_": {"_": 0}}
    for idx, interp in enumerate(interps):
        cover.log("%d) %s - %s" % (idx + 1, interp[1], interp[0]))
    cover.log()
예제 #7
0
def print_interps(interps):
    cover.log(">> Interpretors:", len(interps))
    dests = {}
    stats = {"_": {"_": 0}}
    for idx, interp in enumerate(interps):
        cover.log("%d) %s - %s" % (idx + 1, interp[1], interp[0]))
    cover.log()
예제 #8
0
def list_tests():
    tst = search_tests()
    cover.log(">> Tests:", len(tst))
    for idx, test in enumerate(tst):
        test = os.path.basename(test)
        if test[:5].lower() == "test_":
            test = test[5:]
        if test[-3:].lower() == ".py":
            test = test[:-3]
        cover.log("%d) %s" % (idx + 1, test))
    cover.log()
예제 #9
0
def list_tests():
    tst = search_tests()
    cover.log(">> Tests:", len(tst))
    for idx, test in enumerate(tst):
        test = os.path.basename(test)
        if test[:5].lower() == "test_":
            test = test[5:]
        if test[-3:].lower() == ".py":
            test = test[:-3]
        cover.log("%d) %s" % (idx + 1, test))
    cover.log()
예제 #10
0
파일: runtest.py 프로젝트: reingart/pyfpdf
def do_all_test(interps, tests):
    print_interps(interps)
    dests = {}
    stats = {"_": {"_": 0}}
    for idx, interp in enumerate(interps):
        dests[interp[1]] = prepare_dest(interp)
        stats[interp[1]] = {"_": 0}

    cover.log(">> Tests:", len(tests))
    for idx, test in enumerate(tests):
        do_test(test, interps, dests, stats, "%d / %d" % (idx + 1, len(tests)))
    cover.log()

    cover.log(">> Statistics:")
    def stat_str(stat):
        keys = list(stat.keys())
        keys.sort()
        st = "total - %d" % stat["_"]
        for key in keys:
            if key == "_":
                continue
            st += (", %s - %d" % (key, stat[key]))

        return st
    for interp in interps:
        cover.log(interp[1] + ":", stat_str(stats[interp[1]]))
    cover.log("-"*10)
    cover.log("All:", stat_str(stats["_"]))
    
    # check if no FPDF at all
    total = stats["_"]["_"]
    fpdf = stats["_"].get("nofpdf", 0)
    skip = stats["_"].get("skip", 0)
    if skip == total:
        cover.log("*** All tests skipped. Install some modules (PIL, PyBIDI, " +
            "Gluon, etc)")
    elif fpdf + skip == total:
        hint_prepare()
    # check if NORES
    nores = stats["_"].get("nores", 0)
    if nores > 0:
        items = cover.load_res_list()
        tested = []
        packs = []
        cover.log("*** Some resources are not found")
        for test in tests:
            settings = cover.read_cover_info(test)
            for res in settings.get("res", []):
                if res in tested:
                    continue
                tested.append(res)
                fn = os.path.join(cover.basepath, *res.split("/"))
                if os.path.exists(fn):
                    continue
                print("  not found " + res)
                # check with pack
                if res in items:
                    hs, tags, pack = items[res]
                    if pack and pack not in packs:
                        packs.append(pack)
        if len(packs) > 0:
            cover.log("*** You can download theese resources with:")
            for pack in packs:
                cover.log("  runtest.py --download%s" % pack)
예제 #11
0
def main():
    cover.log("Test PyFPDF")

    testsn = []
    interpsn = []
    args = sys.argv[1:]
    while len(args):
        arg = args[0]
        args = args[1:]
        if arg == "--hash":
            if len(args) == 0:
                cover.log("Param without value")
                return usage()
            return hasher(args[0], args[1:])
        if arg == "--help":
            return usage()
        elif arg == "--test":
            if len(args) > 0:
                value = args[0]
                args = args[1:]
            else:
                cover.log("Param without value")
                return usage()
            if value[:1] == "@":
                # from file
                testsn += read_list(value[1:])
            else:
                testsn.append(value)
        elif arg == "--interp":
            if len(args) > 0:
                value = args[0]
                args = args[1:]
            else:
                cover.log("Param without value")
                return usage()
            if value[:1] == "@":
                # from file
                interpsn += read_list(value[1:])
            else:
                interpsn.append(value)
        elif arg == "--listtests":
            return list_tests()
        elif arg == "--listinterps":
            return print_interps(find_python_version(search_python()))
        elif arg == "--downloadfonts":
            return download_fonts()
        else:
            cover.log("Unknown param")
            return usage()

    if len(testsn) == 0:
        tests = search_tests()
    else:
        # cheack all tests
        tests = []
        for test in testsn:
            test = test.strip()
            fn = os.path.join(cover.basepath, "cover", "test_" + test + ".py")
            if os.path.exists(fn):
                tests.append(fn)
            else:
                cover.err("Test \"%s\" not found" % test)
                return

    if len(interpsn) == 0:
        interps = find_python_version(search_python())
    else:
        # cheack all tests
        interps = []
        for interp in interpsn:
            fn = os.path.abspath(interp)
            if os.path.exists(fn):
                interps.append(fn)
            else:
                cover.err("Interpretor \"%s\" not found" % test)
                return
        interps = find_python_version(interps)

    do_all_test(interps, tests)
예제 #12
0
def usage():
    cover.log("Usage: runtest.py [...]")
    cover.log("  --listtests      - list all tests")
    cover.log("  --listinterps    - list all availiable interpretors")
    cover.log("  --test issuexx   - add test issuexx")
    cover.log("  --test @file     - add test from file")
    cover.log("  --interp path    - test against specified interpretors")
    cover.log("  --interp @file   - read interpretors list from file")
    cover.log("  --downloadfonts  - download font set")
    cover.log("  --help           - this page")
예제 #13
0
파일: runtest.py 프로젝트: reingart/pyfpdf
def main():
    cover.log("Test PyFPDF")

    testsn = []
    interpsn = []
    autodownloadres = False
    args = sys.argv[1:]
    while len(args):
        arg = args[0]
        args = args[1:]
        if arg == "--hash":
            if len(args) == 0:
                cover.log("Param without value")
                return usage()
            return hasher(args[0], args[1:])
        if arg == "--help":
            print(cover.PACKHASH)
            return usage()
        elif arg == "--test":
            if len(args) > 0:
                value = args[0]
                args = args[1:]
            else:
                cover.log("Param without value")
                return usage()
            if value[:1] == "@":
                # from file
                testsn += read_list(value[1:])
            else:
                testsn.append(value)
        elif arg == "--interp":
            if len(args) > 0:
                value = args[0]
                args = args[1:]
            else:
                cover.log("Param without value")
                return usage()
            if value[:1] == "@":
                # from file
                interpsn += read_list(value[1:])
            else:
                interpsn.append(value)
        elif arg == "--listtests":
            return list_tests()
        elif arg == "--listinterps":
            return print_interps(find_python_version(search_python()))
        elif arg.startswith("--download"):
            return download_pack(arg[10:])
        elif arg == "--ignore-res-hash":
            cover.common.RESHASH = "{IGNORE}"
        elif arg == "--ignore-pack-hash":
            cover.common.PACKHASH = "{IGNORE}"
        elif arg == "--autodownload":
            autodownloadres = True
        else:
            cover.log("Unknown param")
            return usage()

    if len(testsn) == 0:
        tests = search_tests()
    else:
        # cheack all tests
        tests = []
        for test in testsn:
            test = test.strip()
            fn = os.path.join(cover.basepath, "cover", "test_" + test + ".py")
            if os.path.exists(fn):
                tests.append(fn)
            else:
                cover.err("Test \"%s\" not found" % test)
                return

    if len(interpsn) == 0:
        interps = find_python_version(search_python())
    else:
        # cheack all tests
        interps = []
        for interp in interpsn:
            fn = os.path.abspath(interp)
            if os.path.exists(fn):
                interps.append(fn)
            else:
                cover.err("Interpreter \"%s\" not found" % test)
                return
        interps = find_python_version(interps)
    
    # check if need res
    if autodownloadres:
        usedres = []
        usedpacks = []
        for test in tests:
            settings = cover.read_cover_info(test)
            for res in settings.get("res", []):
                if res in usedres:
                    continue
                usedres.append(res)
        allres = cover.load_res_list()
        for ures in usedres:
            if ures in allres:
                hs, tags, pack = allres[ures]
                if pack and pack not in usedpacks:
                    usedpacks.append(pack)
        for pack in usedpacks:
            download_pack(pack)

    do_all_test(interps, tests)
예제 #14
0
def hasher(path, args):
    tags = []
    pack = ""
    while len(args):
        arg = args[0]
        args = args[1:]
        if arg == "--tag":
            if len(args) == 0:
                cover.log("Param without value")
                return
            value = args[0]
            args = args[1:]
            if value not in tags:
                tags.append(value)
        elif arg == "--pack":
            if len(args) == 0:
                cover.log("Param without value")
                return
            value = args[0]
            args = args[1:]
            pack = value
        else:
            cover.log("Unknown param")
            return

    lst = []
    if os.path.isdir(path):
        files = [(x.lower(), x) for x in os.listdir(path)]
        files.sort()
        for s, item in files:
            fp = os.path.join(path, item)
            # clear path
            bp = fp
            if sys.platform.startswith("win"):
                bp = fp.replace("\\", "/")
            lst += [[bp, cover.file_hash(fp)]]
    else:
        lst = [[path, cover.file_hash(path)]]
    for item, hs in lst:
        cover.log("res=" + item)
        cover.log("hash=" + hs)
        cover.log("tags=" + ",".join(tags))
        if pack:
            cover.log("pack=" + pack)
        cover.log()
예제 #15
0
def usage():
    cover.log("Usage: runtest.py [...]")
    cover.log("  --listtests      - list all tests")
    cover.log("  --listinterps    - list all availiable interpreters")
    cover.log("  --test issuexx   - add test issuexx")
    cover.log("  --test @file     - add test from file")
    cover.log("  --interp path    - test against specified interpreters")
    cover.log("  --interp @file   - read interpreters list from file")
    cover.log("  --autodownload   - download used resources automatically")
    try:
        packs = cover.load_res_packs()
        k = list(packs.keys())
        k.sort()
        for p in k:
            cover.log("  --download%s" % p)
            cover.log("             - download %s" % packs[p][0])
    except Exception:
        traceback.print_exc()
    cover.log("  --download_all   - download all resources from all packs")
    cover.log("  --help           - this page")
예제 #16
0
def hint_prepare():
    if cover.PYFPDFTESTLOCAL:
        if sys.platform.startswith("win"):
            prefix = ""
            suffix = ".bat"
        else:
            prefix = "./"
            suffix = ".sh"
        cover.log("*** Please, prepare local copy for tests")
        cover.log("***   " + prefix + "prepare_local" + suffix)
    else:
        cover.log("*** Please, install PyFPDF with")
        cover.log("***   python setup.py install")
        cover.log("*** or set PYFPDFTESTLOCAL variable to use local copy")
        if sys.platform.startswith("win"):
            cover.log("***   set PYFPDFTESTLOCAL=1")
        else:
            cover.log("***   export PYFPDFTESTLOCAL=1")
예제 #17
0
def usage():
    cover.log("Usage: runtest.py [...]")
    cover.log("  --listtests      - list all tests")
    cover.log("  --listinterps    - list all availiable interpretors")
    cover.log("  --test issuexx   - add test issuexx")
    cover.log("  --test @file     - add test from file")
    cover.log("  --interp path    - test against specified interpretors")
    cover.log("  --interp @file   - read interpretors list from file")
    cover.log("  --downloadfonts  - download font set")
    cover.log("  --help           - this page")
예제 #18
0
def do_all_test(interps, tests):
    print_interps(interps)
    dests = {}
    stats = {"_": {"_": 0}}
    for idx, interp in enumerate(interps):
        dests[interp[1]] = prepare_dest(interp)
        stats[interp[1]] = {"_": 0}

    cover.log(">> Tests:", len(tests))
    for idx, test in enumerate(tests):
        do_test(test, interps, dests, stats, "%d / %d" % (idx + 1, len(tests)))
    cover.log()

    cover.log(">> Statistics:")
    def stat_str(stat):
        keys = list(stat.keys())
        keys.sort()
        st = "total - %d" % stat["_"]
        for key in keys:
            if key == "_":
                continue
            st += (", %s - %d" % (key, stat[key]))

        return st
    for interp in interps:
        cover.log(interp[1] + ":", stat_str(stats[interp[1]]))
    cover.log("-"*10)
    cover.log("All:", stat_str(stats["_"]))

    # check if no FPDF at all
    total = stats["_"]["_"]
    fpdf = stats["_"].get("nofpdf", 0)
    skip = stats["_"].get("skip", 0)
    if skip == total:
        cover.log("All tests skipped. Install some modules (PIL, PyBIDI, Gluon etc)")
    elif fpdf + skip == total:
        hint_prepare()
예제 #19
0
파일: runtest.py 프로젝트: reingart/pyfpdf
def usage():
    cover.log("Usage: runtest.py [...]")
    cover.log("  --listtests      - list all tests")
    cover.log("  --listinterps    - list all availiable interpreters")
    cover.log("  --test issuexx   - add test issuexx")
    cover.log("  --test @file     - add test from file")
    cover.log("  --interp path    - test against specified interpreters")
    cover.log("  --interp @file   - read interpreters list from file")
    cover.log("  --autodownload   - download used resources automatically")
    try:
        packs = cover.load_res_packs()
        k = list(packs.keys())
        k.sort()
        for p in k:
            cover.log("  --download%s" % p)
            cover.log("             - download %s" % packs[p][0])
    except Exception:
            traceback.print_exc()
    cover.log("  --download_all   - download all resources from all packs")
    cover.log("  --help           - this page")
예제 #20
0
def do_all_test(interps, tests):
    print_interps(interps)
    dests = {}
    stats = {"_": {"_": 0}}
    for idx, interp in enumerate(interps):
        dests[interp[1]] = prepare_dest(interp)
        stats[interp[1]] = {"_": 0}

    cover.log(">> Tests:", len(tests))
    for idx, test in enumerate(tests):
        do_test(test, interps, dests, stats, "%d / %d" % (idx + 1, len(tests)))
    cover.log()

    cover.log(">> Statistics:")

    def stat_str(stat):
        keys = list(stat.keys())
        keys.sort()
        st = "total - %d" % stat["_"]
        for key in keys:
            if key == "_":
                continue
            st += (", %s - %d" % (key, stat[key]))

        return st

    for interp in interps:
        cover.log(interp[1] + ":", stat_str(stats[interp[1]]))
    cover.log("-" * 10)
    cover.log("All:", stat_str(stats["_"]))

    # check if no FPDF at all
    total = stats["_"]["_"]
    fpdf = stats["_"].get("nofpdf", 0)
    skip = stats["_"].get("skip", 0)
    if skip == total:
        cover.log(
            "*** All tests skipped. Install some modules (PIL, PyBIDI, " +
            "Gluon, etc)")
    elif fpdf + skip == total:
        hint_prepare()
    # check if NORES
    nores = stats["_"].get("nores", 0)
    if nores > 0:
        items = cover.load_res_list()
        tested = []
        packs = []
        cover.log("*** Some resources are not found")
        for test in tests:
            settings = cover.read_cover_info(test)
            for res in settings.get("res", []):
                if res in tested:
                    continue
                tested.append(res)
                fn = os.path.join(cover.basepath, *res.split("/"))
                if os.path.exists(fn):
                    continue
                print("  not found " + res)
                # check with pack
                if res in items:
                    hs, tags, pack = items[res]
                    if pack and pack not in packs:
                        packs.append(pack)
        if len(packs) > 0:
            cover.log("*** You can download theese resources with:")
            for pack in packs:
                cover.log("  runtest.py --download%s" % pack)
예제 #21
0
def download_pack(packname):
    if packname[:1] == "-":
        packname = packname[1:]
    packs = cover.load_res_packs()
    if packname == "_all":
        dnpacks = packs.keys()
    else:
        dnpacks = [packname]
        if packname not in packs:
            cover.err("Unknown pack \"%s\"" % packname)
            return
    for pidx, packname in enumerate(dnpacks):
        name, url, filename, dest, valid, strip = packs[packname]
        cover.log("Downloading: %d/%d %s" % (pidx + 1, len(dnpacks), name))
        destdir = os.path.join(cover.basepath, *dest)
        if not os.path.exists(destdir):
            os.makedirs(destdir)
        zippath = os.path.join(cover.basepath, filename)
        if not os.path.exists(zippath):
            u = urlopen(url)
            meta = u.info()
            try:
                file_size = int(meta.get("Content-Length"))
                cover.log("Downloading: %s bytes" % str(file_size))
            except Exception:
                file_size = None
                cover.log("Downloading:")
            with open(zippath, "wb") as f:
                file_size_dl = 0
                while True:
                    buff = u.read(64 * 1024)
                    if not buff:
                        break
                    file_size_dl += len(buff)
                    f.write(buff)
                    if file_size:
                        cover.log("  ", file_size_dl * 100. / file_size, "%")
                    else:
                        cover.log("  ", file_size_dl, "bytes")
        # unpack
        cover.log("Extracting")
        import zipfile, re
        newfiles = []
        with open(zippath, "rb") as fh:
            z = zipfile.ZipFile(fh)
            for name in z.namelist():
                if not re.match(valid, name):
                    cover.log("  skip " + name)
                    continue
                # strip slashes
                ename = name
                ns = strip
                while ns > 0:
                    ns -= 1
                    ps = ename.find("/")
                    if ps > 0:
                        ename = ename[ps + 1:]
                    else:
                        ename = ""
                        break
                if not ename:
                    cover.log("  strip " + name)
                    continue
                if name != ename:
                    cover.log("  ok " + name + " -> " + ename)
                else:
                    cover.log("  ok " + name)
                # extract
                fn = os.path.join(destdir, *ename.split("/"))
                if ename[-1:] == "/":
                    if not os.path.exists(fn):
                        os.makedirs(fn)
                else:
                    base = os.path.dirname(fn)
                    if not os.path.exists(base):
                        os.makedirs(base)
                    with open(fn, "wb") as outfile:
                        outfile.write(z.read(name))
                    newfn = "/".join(dest + ename.split("/"))
                    newfiles.append(newfn)
        # check extracted
        for res, (hs, tags, pack) in cover.load_res_list().items():
            if pack != packname: continue
            fp = os.path.join(cover.basepath, *res.split("/"))
            if not os.path.exists(fp):
                cover.err("Resource \"%s\" not found" % res)
                return
            if cover.file_hash(fp) != hs:
                if cover.common.RESHASH == "{IGNORE}":
                    cover.log("  ignore hash " + res)
                else:
                    cover.err("Resource \"%s\" damaged (hash mismatch)" % res)
                    return
            if res in newfiles:
                newfiles.remove(res)
        # check unchecked
        for fn in newfiles:
            print("  no hash for " + fn)
    cover.log("Done")
예제 #22
0
파일: runtest.py 프로젝트: search5/pyfpdf
def download_pack(packname):
    packs = cover.load_res_packs()
    if packname not in packs:
        cover.err("Unknown pack \"%s\"" % packname)
        return
    name, url, filename, dest, valid = packs[packname]
    cover.log("Downloading: " + name)
    destdir = os.path.join(cover.basepath, *dest)
    if not os.path.exists(destdir):
        os.makedirs(destdir)
    zippath = os.path.join(cover.basepath, filename)
    if not os.path.exists(zippath):
        u = urlopen(url)
        meta = u.info()
        file_size = int(meta.get("Content-Length"))
        cover.log("Downloading:", file_size, "bytes")
        with open(zippath, "wb") as f:
            file_size_dl = 0
            while True:
                buff = u.read(64 * 1024)
                if not buff:
                    break
                file_size_dl += len(buff)
                f.write(buff)
                cover.log("  ", file_size_dl * 100. / file_size, "%")
    # unpack
    cover.log("Extracting")
    import zipfile, re
    with open(zippath, "rb") as fh:
        z = zipfile.ZipFile(fh)
        for name in z.namelist():
            if not re.match(valid, name):
                cover.log("  skip " + name)
                continue
            cover.log("  ok ", name)
            with open(os.path.join(destdir, *name.split("/")), "wb") as outfile:
                outfile.write(z.read(name))
    # check extracted
    for res, (hs, tags, pack) in cover.load_res_list().items():
        if pack != packname: continue
        fp = os.path.join(cover.basepath, *res.split("/"))
        if not os.path.exists(fp):
            cover.err("Resource \"%s\" not found" % res)
            return
        if cover.file_hash(fp) != hs:
            cover.err("Resource \"%s\" damaged (hash mismatch)" % res)
            return
        pass
    cover.log("Done")
예제 #23
0
def hint_prepare():
    if cover.PYFPDFTESTLOCAL:
        if sys.platform.startswith("win"):
            prefix = ""
            suffix = ".bat"
        else:
            prefix = "./"
            suffix = ".sh"
        cover.log("*** Please, prepare local copy for tests")
        cover.log("***   " + prefix + "prepare_local" + suffix)
    else:
        cover.log("*** Please, install PyFPDF with")
        cover.log("***   python setup.py install")
        cover.log("*** or set PYFPDFTESTLOCAL variable to use local copy")
        if sys.platform.startswith("win"):
            cover.log("***   set PYFPDFTESTLOCAL=1")
        else:
            cover.log("***   export PYFPDFTESTLOCAL=1")
예제 #24
0
def do_all_test(interps, tests):
    print_interps(interps)
    dests = {}
    stats = {"_": {"_": 0}}
    for idx, interp in enumerate(interps):
        dests[interp[1]] = prepare_dest(interp)
        stats[interp[1]] = {"_": 0}

    cover.log(">> Tests:", len(tests))
    for idx, test in enumerate(tests):
        do_test(test, interps, dests, stats, "%d / %d" % (idx + 1, len(tests)))
    cover.log()

    cover.log(">> Statistics:")

    def stat_str(stat):
        keys = list(stat.keys())
        keys.sort()
        st = "total - %d" % stat["_"]
        for key in keys:
            if key == "_":
                continue
            st += (", %s - %d" % (key, stat[key]))

        return st

    for interp in interps:
        cover.log(interp[1] + ":", stat_str(stats[interp[1]]))
    cover.log("-" * 10)
    cover.log("All:", stat_str(stats["_"]))

    # check if no FPDF at all
    total = stats["_"]["_"]
    fpdf = stats["_"].get("nofpdf", 0)
    skip = stats["_"].get("skip", 0)
    if skip == total:
        cover.log(
            "All tests skipped. Install some modules (PIL, PyBIDI, Gluon etc)")
    elif fpdf + skip == total:
        hint_prepare()
예제 #25
0
def hasher(path, args):
    tags = []
    while len(args):
        arg = args[0]
        args = args[1:]
        if arg == "--tag":
            if len(args) == 0:
                cover.log("Param without value")
                return
            value = args[0]
            args = args[1:]
            if value not in tags:
                tags.append(value)
        else:
            cover.log("Unknown param")
            return

    lst = []
    if os.path.isdir(path):
        files = [(x.lower(), x) for x in os.listdir(path)]
        files.sort()
        for s, item in files:
            fp = os.path.join(path, item)
            # clear path
            bp = fp
            if sys.platform.startswith("win"):
                bp = fp.replace("\\", "/")
            lst += [[bp, cover.file_hash(fp)]]
    else:
        lst = [[path, cover.file_hash(path)]]
    for item, hs in lst:
        cover.log("res=" + item)
        cover.log("hash=" + hs)
        cover.log("tags=" + ",".join(tags))
        cover.log()
예제 #26
0
파일: runtest.py 프로젝트: reingart/pyfpdf
def download_pack(packname):
    if packname[:1] == "-":
        packname = packname[1:]
    packs = cover.load_res_packs()
    if packname == "_all":
        dnpacks = packs.keys()
    else:
        dnpacks = [packname]
        if packname not in packs:
            cover.err("Unknown pack \"%s\"" % packname)
            return
    for pidx, packname in enumerate(dnpacks):
        name, url, filename, dest, valid, strip = packs[packname]
        cover.log("Downloading: %d/%d %s" % (pidx + 1, len(dnpacks), name))
        destdir = os.path.join(cover.basepath, *dest)
        if not os.path.exists(destdir):
            os.makedirs(destdir)
        zippath = os.path.join(cover.basepath, filename)
        if not os.path.exists(zippath):
            u = urlopen(url)
            meta = u.info()
            try:
                file_size = int(meta.get("Content-Length"))
                cover.log("Downloading: %s bytes" % str(file_size))
            except Exception:
                file_size = None
                cover.log("Downloading:")
            with open(zippath, "wb") as f:
                file_size_dl = 0
                while True:
                    buff = u.read(64 * 1024)
                    if not buff:
                        break
                    file_size_dl += len(buff)
                    f.write(buff)
                    if file_size:
                        cover.log("  ", file_size_dl * 100. / file_size, "%")
                    else:
                        cover.log("  ", file_size_dl, "bytes")
        # unpack
        cover.log("Extracting")
        import zipfile, re
        newfiles = []
        with open(zippath, "rb") as fh:
            z = zipfile.ZipFile(fh)
            for name in z.namelist():
                if not re.match(valid, name):
                    cover.log("  skip " + name)
                    continue
                # strip slashes
                ename = name
                ns = strip
                while ns > 0:
                    ns -= 1
                    ps = ename.find("/")
                    if ps > 0:
                        ename = ename[ps + 1:]
                    else:
                        ename = ""
                        break
                if not ename:
                    cover.log("  strip " + name)
                    continue
                if name != ename:
                    cover.log("  ok " + name + " -> " + ename)
                else:
                    cover.log("  ok " + name)
                # extract
                fn = os.path.join(destdir, *ename.split("/"))
                if ename[-1:] == "/":
                    if not os.path.exists(fn):
                        os.makedirs(fn)
                else:
                    base = os.path.dirname(fn)
                    if not os.path.exists(base):
                        os.makedirs(base)
                    with open(fn, "wb") as outfile:
                        outfile.write(z.read(name))
                    newfn = "/".join(dest + ename.split("/"))
                    newfiles.append(newfn)
        # check extracted
        for res, (hs, tags, pack) in cover.load_res_list().items():
            if pack != packname: continue
            fp = os.path.join(cover.basepath, *res.split("/"))
            if not os.path.exists(fp):
                cover.err("Resource \"%s\" not found" % res)
                return
            if cover.file_hash(fp) != hs:
                if cover.common.RESHASH == "{IGNORE}":
                    cover.log("  ignore hash " + res)
                else:
                    cover.err("Resource \"%s\" damaged (hash mismatch)" % res)
                    return
            if res in newfiles:
                newfiles.remove(res)
        # check unchecked
        for fn in newfiles:
            print("  no hash for " + fn)
    cover.log("Done")
예제 #27
0
def main():
    cover.log("Test PyFPDF")

    testsn = []
    interpsn = []
    autodownloadres = False
    args = sys.argv[1:]
    while len(args):
        arg = args[0]
        args = args[1:]
        if arg == "--hash":
            if len(args) == 0:
                cover.log("Param without value")
                return usage()
            return hasher(args[0], args[1:])
        if arg == "--help":
            print(cover.PACKHASH)
            return usage()
        elif arg == "--test":
            if len(args) > 0:
                value = args[0]
                args = args[1:]
            else:
                cover.log("Param without value")
                return usage()
            if value[:1] == "@":
                # from file
                testsn += read_list(value[1:])
            else:
                testsn.append(value)
        elif arg == "--interp":
            if len(args) > 0:
                value = args[0]
                args = args[1:]
            else:
                cover.log("Param without value")
                return usage()
            if value[:1] == "@":
                # from file
                interpsn += read_list(value[1:])
            else:
                interpsn.append(value)
        elif arg == "--listtests":
            return list_tests()
        elif arg == "--listinterps":
            return print_interps(find_python_version(search_python()))
        elif arg.startswith("--download"):
            return download_pack(arg[10:])
        elif arg == "--ignore-res-hash":
            cover.common.RESHASH = "{IGNORE}"
        elif arg == "--ignore-pack-hash":
            cover.common.PACKHASH = "{IGNORE}"
        elif arg == "--autodownload":
            autodownloadres = True
        else:
            cover.log("Unknown param")
            return usage()

    if len(testsn) == 0:
        tests = search_tests()
    else:
        # cheack all tests
        tests = []
        for test in testsn:
            test = test.strip()
            fn = os.path.join(cover.basepath, "cover", "test_" + test + ".py")
            if os.path.exists(fn):
                tests.append(fn)
            else:
                cover.err("Test \"%s\" not found" % test)
                return

    if len(interpsn) == 0:
        interps = find_python_version(search_python())
    else:
        # cheack all tests
        interps = []
        for interp in interpsn:
            fn = os.path.abspath(interp)
            if os.path.exists(fn):
                interps.append(fn)
            else:
                cover.err("Interpreter \"%s\" not found" % test)
                return
        interps = find_python_version(interps)

    # check if need res
    if autodownloadres:
        usedres = []
        usedpacks = []
        for test in tests:
            settings = cover.read_cover_info(test)
            for res in settings.get("res", []):
                if res in usedres:
                    continue
                usedres.append(res)
        allres = cover.load_res_list()
        for ures in usedres:
            if ures in allres:
                hs, tags, pack = allres[ures]
                if pack and pack not in usedpacks:
                    usedpacks.append(pack)
        for pack in usedpacks:
            download_pack(pack)

    do_all_test(interps, tests)
예제 #28
0
def main():
    cover.log("Test PyFPDF")

    testsn = []
    interpsn = []
    args = sys.argv[1:]
    while len(args):
        arg = args[0]
        args = args[1:]
        if arg == "--hash":
            if len(args) == 0:
                cover.log("Param without value")
                return usage()
            return hasher(args[0], args[1:])
        if arg == "--help":
            return usage()
        elif arg == "--test":
            if len(args) > 0:
                value = args[0]
                args = args[1:]
            else:
                cover.log("Param without value")
                return usage()
            if value[:1] == "@":
                # from file
                testsn += read_list(value[1:])
            else:
                testsn.append(value)
        elif arg == "--interp":
            if len(args) > 0:
                value = args[0]
                args = args[1:]
            else:
                cover.log("Param without value")
                return usage()
            if value[:1] == "@":
                # from file
                interpsn += read_list(value[1:])
            else:
                interpsn.append(value)
        elif arg == "--listtests":
            return list_tests()
        elif arg == "--listinterps":
            return print_interps(find_python_version(search_python()))
        elif arg == "--downloadfonts":
            return download_fonts()
        else:
            cover.log("Unknown param")
            return usage()

    if len(testsn) == 0:
        tests = search_tests()
    else:
        # cheack all tests
        tests = []
        for test in testsn:
            test = test.strip()
            fn = os.path.join(cover.basepath, "cover", "test_" + test + ".py")
            if os.path.exists(fn):
                tests.append(fn)
            else:
                cover.err("Test \"%s\" not found" % test)
                return

    if len(interpsn) == 0:
        interps = find_python_version(search_python())
    else:
        # cheack all tests
        interps = []
        for interp in interpsn:
            fn = os.path.abspath(interp)
            if os.path.exists(fn):
                interps.append(fn)
            else:
                cover.err("Interpretor \"%s\" not found" % test)
                return
        interps = find_python_version(interps)

    do_all_test(interps, tests)