8000 Run tests on .NET Core · pythonnet/pythonnet@0d7e43a · GitHub
[go: up one dir, main page]

Skip to content

Commit 0d7e43a

Browse files
committed
Run tests on .NET Core
1 parent f01a78c commit 0d7e43a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+120
-68
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,17 @@ jobs:
5555
if: ${{ matrix.os == 'windows' }}
5656
run: |
5757
python -m pythonnet.find_libpython --export | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
58-
59-
- name: Python Tests
60-
run: pytest
58+
59+
- name: Python Tests (Mono)
60+
if: ${{ matrix.os != 'windows' }}
61+
run: pytest --runtime mono
62+
63+
- name: Python Tests (.NET Core)
64+
run: pytest --runtime netcore
65+
66+
- name: Python Tests (.NET Framework)
67+
if: ${{ matrix.os == 'windows' }}
68+
run: pytest --runtime netfx
6169

6270
- name: Embedding tests
6371
run: dotnet test --runtime any-${{ matrix.platform }} src/embed_tests/

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
[build-system]
22
requires = ["setuptools>=42", "wheel", "pycparser"]
33
build-backend = "setuptools.build_meta"
4+
5+
[tool.pytest.ini_options]
6+
xfail_strict = true
7+
testpaths = [
8+
"tests",
9+
]

setup.cfg

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/testing/Python.Test.csproj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>netstandard2.0</TargetFrameworks>
3+
<TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks>
44
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
5+
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
56
</PropertyGroup>
67

78
<ItemGroup>
89
<ProjectReference Include="..\runtime\Python.Runtime.csproj" />
910
</ItemGroup>
10-
11-
<Target Name="AfterBuild">
12-
<Copy SourceFiles="$(TargetAssembly)" DestinationFolder="$(MSBuildThisFileDirectory)..\tests\fixtures" />
13-
</Target>
1411
</Project>

src/tests/conftest.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/tests/fixtures/netstandard2.0/.gitkeep

Whitespace-only changes.
File renamed without changes.
File renamed without changes.

tests/conftest.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# -*- coding: utf-8 -*-
2+
# TODO: move tests one out of src to project root.
3+
# TODO: travis has numpy on their workers. Maybe add tests?
4+
5+
"""Helpers for testing."""
6+
7+
import ctypes
8+
import os
9+
import sys
10+
import sysconfig
11+
from subprocess import check_call
12+
from tempfile import mkdtemp
13+
import shutil
14+
15+
import pytest
16+
17+
from pythonnet import set_runtime
18+
19+
# Add path for `Python.Test`
20+
cwd = os.path.dirname(__file__)
21+
fixtures_path = os.path.join(cwd, "fixtures")
22+
sys.path.append(fixtures_path)
23+
24+
def pytest_addoption(parser):
25+
parser.addoption(
26+
"--runtime",
27+
action="store",
28+
default="default",
29+
help="Must be one of default, netcore, netfx and mono"
30+
)
31+
32+
def pytest_configure(config):
33+
global bin_path
34+
runtime_opt = config.getoption("runtime")
35+
36+
test_proj_path = os.path.join(cwd, "..", "src", "testing")
37+
38+
if runtime_opt not in ["netcore", "netfx", "mono", "default"]:
39+
raise RuntimeError(f"Invalid runtime: {runtime_opt}")
40+
41+
bin_path = mkdtemp()
42+
43+
# tmpdir_factory.mktemp(f"pythonnet-{runtime_opt}")
44+
45+
fw = "net5.0" if runtime_opt == "netcore" else "netstandard2.0"
46+
47+
check_call(["dotnet", "publish", "-f", fw, "-o", bin_path, test_proj_path])
48+
49+
sys.path.append(bin_path)
50+
51+
if runtime_opt == "default":
52+
pass
53+
elif runtime_opt == "netfx":
54+
from clr_loader import get_netfx
55+
runtime = get_netfx()
56+
set_runtime(runtime)
57+
elif runtime_opt == "mono":
58+
from clr_loader import get_mono
59+
runtime = get_mono()
60+
set_runtime(runtime)
61+
elif runtime_opt == "netcore":
62+
from clr_loader import get_coreclr
63+
rt_config_path = os.path.join(bin_path, "Python.Test.runtimeconfig.json")
64+
runtime = get_coreclr(rt_config_path)
65+
set_runtime(runtime)
66+
67+
import clr
68+
clr.AddReference("Python.Test")
69+
clr.AddReference("System")
70+
clr.AddReference("System.Collections")
71+
clr.AddReference("System.Data")
72+
clr.AddReference("System.Xml")
73+
74+
75+
def pytest_unconfigure(config):
76+
global bin_path
77+
shutil.rmtree(bin_path)
78+
79+
def pytest_report_header(config):
80+
"""Generate extra report headers"""
81+
# FIXME: https://github.com/pytest-dev/pytest/issues/2257
82+
is_64bits = sys.maxsize > 2**32
83+
arch = "x64" if is_64bits else "x86"
84+
ucs = ctypes.sizeof(ctypes.c_wchar)
85+
libdir = sysconfig.get_config_var("LIBDIR")
86+
shared = bool(sysconfig.get_config_var("Py_ENABLE_SHARED"))
87+
88+
header = ("Arch: {arch}, UCS: {ucs}, LIBDIR: {libdir}, "
89+
"Py_ENABLE_SHARED: {shared}".format(**locals()))
90+
return header
91+
92+
93+
@pytest.fixture()
94+
def filepath():
95+
"""Returns full filepath for file in `fixtures` directory."""
96+
97+
def make_filepath(filename):
98+
# http://stackoverflow.com/questions/18011902/parameter-to-a-fixture
99+
return os.path.join(fixtures_path, filename)
100+
101+
return make_filepath
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)
0