| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,9 +55,17 @@ jobs: | |||
| 55 | 55 | if: ${{ matrix.os == 'windows' }} | |
| 56 | 56 | run: | | |
| 57 | 57 | 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 | ||
| 61 | 69 | ||
| 62 | 70 | - name: Embedding tests | |
| 63 | 71 | run: dotnet test --runtime any-${{ matrix.platform }} src/embed_tests/ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,9 @@ | |||
| 1 | 1 | [build-system] | |
| 2 | 2 | requires = ["setuptools>=42", "wheel", "pycparser"] | |
| 3 | 3 | build-backend = "setuptools.build_meta" | |
| 4 | + | ||
| 5 | + [tool.pytest.ini_options] | ||
| 6 | + xfail_strict = true | ||
| 7 | + testpaths = [ | ||
| 8 | + "tests", | ||
| 9 | + ] | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,14 +1,11 @@ | |||
| 1 | 1 | <Project Sdk="Microsoft.NET.Sdk"> | |
| 2 | 2 | <PropertyGroup> | |
| 3 | - <TargetFrameworks>netstandard2.0</TargetFrameworks> | ||
| 3 | + <TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks> | ||
| 4 | 4 | <AllowUnsafeBlocks>true</AllowUnsafeBlocks> | |
| 5 | + <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> | ||
| 5 | 6 | </PropertyGroup> | |
| 6 | 7 | ||
| 7 | 8 | <ItemGroup> | |
| 8 | 9 | <ProjectReference Include="..\runtime\Python.Runtime.csproj" /> | |
| 9 | 10 | </ItemGroup> | |
| 10 | - | ||
| 11 | - <Target Name="AfterBuild"> | ||
| 12 | - <Copy SourceFiles="$(TargetAssembly)" DestinationFolder="$(MSBuildThisFileDirectory)..\tests\fixtures" /> | ||
| 13 | - </Target> | ||
| 14 | 11 | </Project> | |
| Original file line number | Diff line number | Diff 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 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments