Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3cb2529

Browse files
authored
Merge pull request #1799 from pythonnet/SupportedVersions
`Min`/`MaxSupportedVersion` and `IsSupportedVersion` on `PythonEngine`
2 parents 987b2ee + 2e1652b commit 3cb2529

File tree

5 files changed

+17
-1
lines changed

5 files changed

+17
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ See [Mixins/collections.py](src/runtime/Mixins/collections.py).
2828
and other `PyObject` derived types when called from Python.
2929
- .NET classes, that have `__call__` method are callable from Python
3030
- `PyIterable` type, that wraps any iterable object in Python
31+
- `PythonEngine` properties for supported Python versions: `MinSupportedVersion`, `MaxSupportedVersion`, and `IsSupportedVersion`
3132

3233

3334
### Changed

src/runtime/PythonEngine.cs

+4
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ public static string PythonPath
127127
}
128128
}
129129

130+
public static Version MinSupportedVersion => new(3, 7);
131+
public static Version MaxSupportedVersion => new(3, 10, int.MaxValue, int.MaxValue);
132+
public static bool IsSupportedVersion(Version version) => version >= MinSupportedVersion && version <= MaxSupportedVersion;
133+
130134
public static string Version
131135
{
132136
get { return Marshal.PtrToStringAnsi(Runtime.Py_GetVersion()); }

tests/test_codec.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
@pytest.fixture(autouse=True)
1212
def reset():
13+
CodecResetter.Reset()
1314
yield
1415
CodecResetter.Reset()
1516

tests/test_conversion.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55

66
import System
7-
from Python.Test import ConversionTest, MethodResolutionInt, UnicodeString
7+
from Python.Test import ConversionTest, MethodResolutionInt, UnicodeString, CodecResetter
88
from Python.Runtime import PyObjectConversions
99
from Python.Runtime.Codecs import RawProxyEncoder
1010

@@ -659,6 +659,8 @@ def CanEncode(self, clr_type):
659659
l.Add(42)
660660
assert ob.ListField.Count == 1
661661

662+
CodecResetter.Reset()
663+
662664
def test_int_param_resolution_required():
663665
"""Test resolution of `int` parameters when resolution is needed"""
664666

tests/test_engine.py

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ def test_multiple_calls_to_initialize():
1919
assert False # Initialize() raise an exception.
2020

2121

22+
def test_supported_version():
23+
major, minor, build, *_ = sys.version_info
24+
ver = System.Version(major, minor, build)
25+
assert PythonEngine.IsSupportedVersion(ver)
26+
assert ver >= PythonEngine.MinSupportedVersion
27+
assert ver <= PythonEngine.MaxSupportedVersion
28+
29+
2230
@pytest.mark.skip(reason="FIXME: test crashes")
2331
def test_import_module():
2432
"""Test module import."""

0 commit comments

Comments
 (0)