namespace Python.EmbeddingTest {
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Python.Runtime;
using Python.Runtime.Codecs;
public class Codecs {
[SetUp]
public void SetUp() {
PythonEngine.Initialize();
}
[TearDown]
public void Dispose() {
PythonEngine.Shutdown();
}
[Test]
public void ConversionsGeneric() {
ConversionsGeneric, ValueTuple>();
}
static void ConversionsGeneric() {
TupleCodec.Register();
var tuple = Activator.CreateInstance(typeof(T), 42, "42", new object());
T restored = default;
using (Py.GIL())
using (var scope = Py.CreateScope()) {
void Accept(T value) => restored = value;
var accept = new Action(Accept).ToPython();
scope.Set(nameof(tuple), tuple);
scope.Set(nameof(accept), accept);
scope.Exec($"{nameof(accept)}({nameof(tuple)})");
Assert.AreEqual(expected: tuple, actual: restored);
}
}
[Test]
public void ConversionsObject() {
ConversionsObject, ValueTuple>();
}
static void ConversionsObject() {
TupleCodec.Register();
var tuple = Activator.CreateInstance(typeof(T), 42, "42", new object());
T restored = default;
using (Py.GIL())
using (var scope = Py.CreateScope()) {
void Accept(object value) => restored = (T)value;
var accept = new Action