Example #1
0
        public void CallInheritedClrMethod_WithExtraPythonBase()
        {
            var    instance = new Inherited().ToPython();
            string result   = instance.InvokeMethod(nameof(PythonWrapperBase.WrapperBaseMethod)).As <string>();

            Assert.AreEqual(result, nameof(PythonWrapperBase.WrapperBaseMethod));
        }
Example #2
0
        public void ExtraBase_PassesInstanceCheck()
        {
            var  inherited         = new Inherited();
            bool properlyInherited = PyIsInstance(inherited, ExtraBaseTypeProvider.ExtraBase);

            Assert.IsTrue(properlyInherited);
        }
Example #3
0
        public void InheritingWithExtraBase_CreatesNewClass()
        {
            PyObject a              = ExtraBaseTypeProvider.ExtraBase;
            var      inherited      = new Inherited();
            PyObject inheritedClass = inherited.ToPython().GetAttr("__class__");

            Assert.IsFalse(PythonReferenceComparer.Instance.Equals(a, inheritedClass));
        }
Example #4
0
        public void CallExtraBaseMethod()
        {
            var instance = new Inherited();

            using var scope = Py.CreateScope();
            scope.Set(nameof(instance), instance);
            int actual = instance.ToPython().InvokeMethod("callVirt").As <int>();

            Assert.AreEqual(expected: Inherited.OverridenVirtValue, actual);
        }
Example #5
0
        public void SetAdHocAttributes_WhenExtraBasePresent()
        {
            var instance = new Inherited();

            using var scope = Py.CreateScope();
            scope.Set(nameof(instance), instance);
            scope.Exec($"super({nameof(instance)}.__class__, {nameof(instance)}).set_x_to_42()");
            int actual = scope.Eval <int>($"{nameof(instance)}.{nameof(Inherited.XProp)}");

            Assert.AreEqual(expected: Inherited.X, actual);
        }