예제 #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 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)
예제 #4
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)
예제 #5
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)
예제 #6
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)