using System.Runtime.InteropServices;
using System.Text;
using NUnit.Framework;
using Python.Runtime;
using Python.Runtime.Native;
namespace Python.EmbeddingTest
{
public class TestPyType
{
[Test]
public void CanCreateHeapType()
{
const string name = "nm";
const string docStr = "dc";
using var doc = new StrPtr(docStr);
var spec = new TypeSpec(
name: name,
basicSize: Util.ReadInt32(Runtime.Runtime.PyBaseObjectType, TypeOffset.tp_basicsize),
slots: new TypeSpec.Slot[] {
new (TypeSlotID.tp_doc, doc.RawPointer),
},
TypeFlags.Default | TypeFlags.HeapType
);
using var type = new PyType(spec);
Assert.That(type.GetAttr("__name__").As(), Is.EqualTo(name));
Assert.That(type.Name, Is.EqualTo(name));
Assert.That(type.GetAttr("__doc__").As(), Is.EqualTo(docStr));
}
}
}