Esempio n. 1
0
def find_python_version(pylst):
    lst = []
    ids = []
    for interp in pylst:
        try:
            std, err = cover.exec_cmd([interp, "-V"])
            version = err.strip()
            if not version:
                # python 3.4+
                version = std.strip()
            if version[:6] == "Python":
                shver = version[6:].strip().replace(" ", "-")
                nid = shver
                nidn = 0
                while nid in ids:
                    nidn += 1
                    nid = shver + "-%d" % nidn
                ids.append(nid)
                lst.append((interp, nid, version))
            else:
                cover.err("Not a python", version)
                # no python found
                continue
        except:
            traceback.print_exc()
    return lst
Esempio n. 2
0
def find_python_version(pylst):
    lst = []
    ids = []
    for interp in pylst:
        try:
            std, err = cover.exec_cmd([interp, "-V"])
            version = err.strip()
            if not version:
                # python 3.4+
                version = std.strip()
            if version[:6] == "Python":
                shver = version[6:].strip().replace(" ", "-")
                nid = shver
                nidn = 0
                while nid in ids:
                    nidn += 1
                    nid = shver + "-%d" % nidn
                ids.append(nid)
                lst.append((interp, nid, version))
            else:
                cover.err("Not a python", version)
                # no python found
                continue
        except:
            traceback.print_exc()
    return lst
Esempio n. 3
0
def prepare_dest(interp):
    destpath = os.path.join(cover.basepath, "out-" + interp[1])
    if not os.path.exists(destpath):
        os.makedirs(destpath)
    # copy common set
    src = os.path.join(cover.basepath, "cover")
    shutil.copy(os.path.join(src, "common.py"), destpath)
    shutil.copy(os.path.join(src, "checkenv.py"), destpath)
    with open(os.path.join(destpath, "testlog.txt"), "w") as f:
        f.write("Version: " + interp[1] + "\n")
        f.write("Path: " + interp[0] + "\n")
        f.write(str(interp[2:]) + "\n")

        # run checkenv
        std, err = cover.exec_cmd([interp[0], "-B", os.path.join(destpath, "checkenv.py")])
        env = {}
        if len(err.strip()) == 0:
            # OK
            f.write("Check environment - ok:\n")
            f.write(std)
            lineno = 0
            for line in std.split("\n"):
                lineno += 1
                line = line.strip()
                if lineno == 1:
                    if line != "CHECK":
                        break
                line = line.strip()
                kv = line.split("=", 1)
                if len(kv) == 2:
                    env[kv[0].lower().strip()] = kv[1].strip()
        else:
            f.write("ERROR:\n")
            f.write(err)
    return (destpath, env)
Esempio n. 4
0
def prepare_dest(interp):
    destpath = os.path.join(cover.basepath, "out-" + interp[1])
    if not os.path.exists(destpath):
        os.makedirs(destpath)
    # copy common set
    src = os.path.join(cover.basepath, "cover")
    shutil.copy(os.path.join(src, "common.py"), destpath)
    shutil.copy(os.path.join(src, "checkenv.py"), destpath)
    with open(os.path.join(destpath, "testlog.txt"), "w") as f:
        f.write("Version: " + interp[1] + "\n")
        f.write("Path: " + interp[0] + "\n")
        f.write(str(interp[2:]) + "\n")

        # run checkenv
        std, err = cover.exec_cmd([interp[0], "-B", os.path.join(destpath, "checkenv.py")])
        env = {}
        if len(err.strip()) == 0:
            # OK
            f.write("Check environment - ok:\n")
            f.write(std)
            lineno = 0
            for line in std.split("\n"):
                lineno += 1
                line = line.strip()
                if lineno == 1:
                    if line != "CHECK":
                        break
                line = line.strip()
                kv = line.split("=", 1)
                if len(kv) == 2:
                    env[kv[0].lower().strip()] = kv[1].strip()
        else:
            f.write("ERROR:\n")
            f.write(err)
    return (destpath, env)
Esempio n. 5
0
def do_test_one(testfile, interp, info, dest):
    path = interp[0]
    nid = interp[1]
    destpath = dest[0]
    destenv = dest[1]
    tool2to3 = (info.get("2to3", "no") == "yes")
    py2 = (info.get("python2", "yes") == "yes")
    py3 = (info.get("python3", "yes") == "yes")
    copy = False
    if nid[:2] == "3.":
        if not py3:
            return ("skip", "not for python 3")
        if not tool2to3:
            copy = True
        else:
            return ("unimplemented", "todo")
    if nid[:2] == "2.":
        if not py2:
            return ("skip", "not for python 2")
        copy = True

    # check if fpdf installed
    if destenv.get("ver", "None") == "None":
        return ("nofpdf", "")

    # copy files
    testname = os.path.basename(testfile)
    testfmt = info.get("format", "raw")
    newfile = os.path.join(destpath, testname)
    newres = os.path.join(destpath,
                          info.get("fn", testname + "." + testfmt.lower()))
    if copy:
        shutil.copy(testfile, destpath)
    # start execution
    std, err = cover.exec_cmd(
        [path, "-B", newfile, "--check", "--auto", newres])
    f = open(os.path.join(destpath, "testlog.txt"), "a")
    f.write("#" * 40 + "\n")
    f.write(testname + "\n")
    f.write("=" * 40 + "\n")
    f.write(std)
    f.write("-" * 40 + "\n")
    f.write(err)
    f.close()

    answ = std.strip()
    if answ.find("\n") >= 0 or len(answ) == 0:
        return ("fail", "bad output")
    else:
        if answ == "HASHERROR":
            # get new hash
            nh = ""
            for line in err.split("\n"):
                line = line.strip()
                if line[:5] == "new =":
                    nh = line[5:].strip()
            return ("hasherror", nh)
        return (answ.lower(), "")
Esempio n. 6
0
def do_test_one(testfile, interp, info, dest):
    path = interp[0]
    nid = interp[1]
    destpath = dest[0]
    destenv = dest[1]
    tool2to3 = (info.get("2to3", "no") == "yes")
    py2 = (info.get("python2", "yes") == "yes")
    py3 = (info.get("python3", "yes") == "yes")
    copy = False
    if nid[:2] == "3.":
        if not py3:
            return ("skip", "not for python 3")
        if not tool2to3:
            copy = True
        else:
            return ("unimplemented", "todo")
    if nid[:2] == "2.":
        if not py2:
            return ("skip", "not for python 2")
        copy = True

    # check if fpdf installed
    if destenv.get("ver", "None") == "None":
        return ("nofpdf", "")

    # copy files
    testname = os.path.basename(testfile)
    testfmt = info.get("format", "raw")
    newfile = os.path.join(destpath, testname)
    newres = os.path.join(destpath, info.get("fn", testname + "." + testfmt.lower()))
    if copy:
        shutil.copy(testfile, destpath)
    # start execution
    std, err = cover.exec_cmd([path, "-B", newfile, "--check", "--auto", newres])
    f = open(os.path.join(destpath, "testlog.txt"), "a")
    f.write("#" * 40 + "\n")
    f.write(testname + "\n")
    f.write("=" * 40 + "\n")
    f.write(std)
    f.write("-" * 40 + "\n")
    f.write(err)
    f.close()

    answ = std.strip()
    if answ.find("\n") >= 0 or len(answ) == 0:
        return ("fail", "bad output")
    else:
        if answ == "HASHERROR":
            # get new hash
            nh = ""
            for line in err.split("\n"):
                line = line.strip()
                if line[:5] == "new =":
                    nh = line[5:].strip()
            return ("hasherror", nh)
        return (answ.lower(), "")