Beispiel #1
0
def test_mono(example_netstandard):
    from clr_loader import get_mono

    mono = get_mono()
    asm = mono.get_assembly(os.path.join(example_netstandard, "example.dll"))

    run_tests(asm)
Beispiel #2
0
def pytest_configure(config):
    global bin_path
    if "clr" in sys.modules:
        # Already loaded (e.g. by the C# test runner), skip build
        import clr
        clr.AddReference("Python.Test")
        return

    runtime_opt = config.getoption("runtime")

    test_proj_path = os.path.join(cwd, "..", "src", "testing")

    if runtime_opt not in ["netcore", "netfx", "mono", "default"]:
        raise RuntimeError(f"Invalid runtime: {runtime_opt}")

    bin_path = mkdtemp()

    # tmpdir_factory.mktemp(f"pythonnet-{runtime_opt}")

    fw = "net6.0" if runtime_opt == "netcore" else "netstandard2.0"

    check_call(["dotnet", "publish", "-f", fw, "-o", bin_path, test_proj_path])

    sys.path.append(bin_path)

    if runtime_opt == "default":
        pass
    elif runtime_opt == "netfx":
        from clr_loader import get_netfx
        runtime = get_netfx()
        set_runtime(runtime)
    elif runtime_opt == "mono":
        from clr_loader import get_mono
        runtime = get_mono()
        set_runtime(runtime)
    elif runtime_opt == "netcore":
        from clr_loader import get_coreclr
        rt_config_path = os.path.join(bin_path, "Python.Test.runtimeconfig.json")
        runtime = get_coreclr(rt_config_path)
        set_runtime(runtime)

    import clr
    clr.AddReference("Python.Test")

    soft_mode = False
    try:
        os.environ['PYTHONNET_SHUTDOWN_MODE'] == 'Soft'
    except: pass

    if config.getoption("--runtime") == "netcore" or soft_mode\
        :
        collect_ignore.append("domain_tests/test_domain_reload.py")
    else:
        domain_tests_dir = os.path.join(os.path.dirname(__file__), "domain_tests")
        bin_path = os.path.join(domain_tests_dir, "bin")
        build_cmd = ["dotnet", "build", domain_tests_dir, "-o", bin_path]
        is_64bits = sys.maxsize > 2**32
        if not is_64bits:
            build_cmd += ["/p:Prefer32Bit=True"]
        check_call(build_cmd)
Beispiel #3
0
def _create_runtime_from_spec(
        spec: str,
        params: Optional[Dict[str, str]] = None) -> clr_loader.Runtime:
    if spec == "default":
        if sys.platform == "win32":
            spec = "netfx"
        else:
            spec = "mono"

    params = params or _get_params_from_env(spec)

    if spec == "netfx":
        return clr_loader.get_netfx(**params)
    elif spec == "mono":
        return clr_loader.get_mono(**params)
    elif spec == "coreclr":
        return clr_loader.get_coreclr(**params)
    else:
        raise RuntimeError(f"Invalid runtime name: '{spec}'")
Beispiel #4
0
def set_default_runtime() -> None:
    if sys.platform == 'win32':
        set_runtime(clr_loader.get_netfx())
    else:
        set_runtime(clr_loader.get_mono())