Exemplo n.º 1
0
def get_cpython_results(name, level=0, temp_mod=None):
    '''
    Recursively gets all attributes of a CPython module up to a depth of
    MAX_DEPTH.
    '''
    #from the name determine the module
    if "." in name:
        mod_name, rest_of_name = name.split(".", 1)
        rest_of_name += "."
    else:
        #we're looking at the module for the first time...import it
        mod_name, rest_of_name = name, ""

        try:
            temp_mod = __import__(mod_name)
        except ImportError as e:
            ip_missing(mod_name)
            return

    #Get the results of:
    #   python.exe -c 'import abc;print dir(abc.xyz)'
    proc = Process()
    proc.StartInfo.FileName = CPY_DIR + "\\python.exe"
    proc.StartInfo.Arguments = "-c \"import " + mod_name + ";print dir(" + name + ")\""
    proc.StartInfo.UseShellExecute = False
    proc.StartInfo.RedirectStandardOutput = True
    if (not proc.Start()):
        raise "CPython process failed to start"
    else:
        cpymod_dir = proc.StandardOutput.ReadToEnd()

    #Convert "['a', 'b']" to a real (sorted) list
    cpymod_dir = eval(cpymod_dir)
    cpymod_dir.sort()

    #Determine what IronPython implements
    if level == 0:
        ipymod_dir_str = "dir(temp_mod)"
    else:
        ipymod_dir_str = "dir(temp_mod." + name.split(".", 1)[1] + ")"

    try:
        ipymod_dir = eval(ipymod_dir_str)
        #Ensure this is also present CPython
        for x in [y for y in ipymod_dir if cpymod_dir.count(y) == 0]:
            ip_extra(name + "." + x)
    except TypeError as e:
        #CodePlex 15715
        if not ipymod_dir_str.endswith(".fromkeys)"):
            print("ERROR:", ipymod_dir_str)
            raise e

    #Look through all attributes the CPython version of the
    #module implements
    for x in cpymod_dir:
        if name + "." + x in IGNORE_LIST:
            print("Will not reflect on", name + "." + x)
            return

        #Check if IronPython is missing the CPython attribute
        try:
            temp = eval("temp_mod." + rest_of_name + x)
        except AttributeError as e:
            ip_missing(name + "." + x)
            continue

        #Skip these as they will recurse forever
        if x.startswith("__") and x.endswith("__"):
            continue
        #Skip these as they overload the log files
        elif x in [
                "_Printer__setup", "im_class", "_Printer__name", "func_code",
                "func_dict", "func_globals"
        ]:
            continue
        #Each of these functions has many __*__ methods
        elif x in recursive_functions and level > 2:
            continue
        #Skip these as they recurse forever
        elif name.startswith("datetime") and x in ["min", "max", "resolution"]:
            continue
        elif level >= MAX_DEPTH:
            print("Recursion too deep:", name, x)
            continue
        get_cpython_results(name + "." + x, level + 1, temp_mod)

    return
Exemplo n.º 2
0
def ip_passes(mod_name):
    print mod_name
    IPY_PASSES.write(mod_name + "\n")
    IPY_PASSES.flush()


def ip_fails(mod_name):
    IPY_FAILS.write(mod_name + "\n")
    IPY_FAILS.flush()


#--MAIN-----------------------------------------------------------------------
nt.chdir(CPY_DIR + r"\Lib")

for mod_name in TEST_LIST:
    proc = Process()
    proc.StartInfo.FileName = sys.executable
    proc.StartInfo.Arguments = "test\\" + mod_name
    proc.StartInfo.UseShellExecute = False
    proc.StartInfo.RedirectStandardOutput = True
    if (not proc.Start()):
        raise Exception("Python process failed to start: " + mod_name)
    else:
        cpymod_dir = proc.StandardOutput.ReadToEnd()

    if not proc.HasExited:
        raise Exception("Python process should have exited by now: " +
                        mod_name)

    if proc.ExitCode == 0:
        ip_passes(mod_name)