Example #1
0
        public void CallMethodCanBeInheritedFromPython()
        {
            var     callViaInheritance = new CallViaInheritance();
            dynamic applyObjectTo14    = PythonEngine.Eval("lambda o: o(14)");

            Assert.AreEqual(callViaInheritance.Call(14), (int)applyObjectTo14(callViaInheritance.ToPython()));
        }
Example #2
0
        public void CanOverwriteCall()
        {
            var callViaInheritance = new CallViaInheritance();

            using var scope = Py.CreateScope();
            scope.Set("o", callViaInheritance);
            scope.Exec("orig_call = o.Call");
            scope.Exec("o.Call = lambda a: orig_call(a*7)");
            int result = scope.Eval <int>("o.Call(5)");

            Assert.AreEqual(105, result);
        }