Skip to content

Min/MaxSupportedVersion and IsSupportedVersion on PythonEngine #1799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ See [Mixins/collections.py](src/runtime/Mixins/collections.py).
and other `PyObject` derived types when called from Python.
- .NET classes, that have `__call__` method are callable from Python
- `PyIterable` type, that wraps any iterable object in Python
- `PythonEngine` properties for supported Python versions: `MinSupportedVersion`, `MaxSupportedVersion`, and `IsSupportedVersion`


### Changed
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/PythonEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ public static string PythonPath
}
}

public static Version MinSupportedVersion => new(3, 7);
public static Version MaxSupportedVersion => new(3, 10, int.MaxValue, int.MaxValue);
public static bool IsSupportedVersion(Version version) => version >= MinSupportedVersion && version <= MaxSupportedVersion;

public static string Version
{
get { return Marshal.PtrToStringAnsi(Runtime.Py_GetVersion()); }
Expand Down
1 change: 1 addition & 0 deletions tests/test_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

@pytest.fixture(autouse=True)
def reset():
CodecResetter.Reset()
yield
CodecResetter.Reset()

Expand Down
4 changes: 3 additions & 1 deletion tests/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

import System
from Python.Test import ConversionTest, MethodResolutionInt, UnicodeString
from Python.Test import ConversionTest, MethodResolutionInt, UnicodeString, CodecResetter
from Python.Runtime import PyObjectConversions
from Python.Runtime.Codecs import RawProxyEncoder

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

CodecResetter.Reset()

def test_int_param_resolution_required():
"""Test resolution of `int` parameters when resolution is needed"""

Expand Down
8 changes: 8 additions & 0 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ def test_multiple_calls_to_initialize():
assert False # Initialize() raise an exception.


def test_supported_version():
major, minor, build, *_ = sys.version_info
ver = System.Version(major, minor, build)
assert PythonEngine.IsSupportedVersion(ver)
assert ver >= PythonEngine.MinSupportedVersion
assert ver <= PythonEngine.MaxSupportedVersion


@pytest.mark.skip(reason="FIXME: test crashes")
def test_import_module():
"""Test module import."""
Expand Down