Example #1
0
        private Proc MakeProc(OldInstance instance, string methodName)
        {
            var nakedProc =
                _engine.CreateMethod <Proc <object> >(string.Format("instance.{0}()", methodName), Params("instance"));

            Proc testCase = () => nakedProc(instance);

            return(testCase);
        }
Example #2
0
            public object NoThrowTarget(CallSite site, object instance, CodeContext context)
            {
                OldInstance oi = instance as OldInstance;

                if (oi != null)
                {
                    object res;
                    if (oi.TryGetBoundCustomMember(context, _name, out res))
                    {
                        return(res);
                    }
                    return(OperationFailed.Value);
                }

                return(((CallSite <Func <CallSite, object, CodeContext, object> >)site).Update(site, instance, context));
            }
Example #3
0
            public object LightThrowTarget(CallSite site, object instance, CodeContext context)
            {
                OldInstance oi = instance as OldInstance;

                if (oi != null)
                {
                    object res;
                    if (oi.TryGetBoundCustomMember(context, _name, out res))
                    {
                        return(res);
                    }
                    return(LightExceptions.Throw(PythonOps.AttributeError("{0} instance has no attribute '{1}'", oi._class.Name, _name)));
                }

                return(((CallSite <Func <CallSite, object, CodeContext, object> >)site).Update(site, instance, context));
            }
Example #4
0
 internal static bool IsInstance(object o, object typeinfo)
 {
     if (typeinfo is OldClass)
     {
         // old instances are strange - they all share a common type
         // of instance but they can "be subclasses" of other
         // OldClass's.  To check their types we need the actual
         // instance.
         OldInstance oi = o as OldInstance;
         if (oi != null)
         {
             return(oi.__class__.IsSubclassOf(typeinfo));
         }
     }
     return(IsSubClass(Ops.GetDynamicType(o), typeinfo));
 }
Example #5
0
        StoreTyped(OldInstance inst)
        {
            uint   size = (uint)Marshal.SizeOf(typeof(PyInstanceObject));
            IntPtr ptr  = this.allocator.Alloc(size);

            CPyMarshal.Zero(ptr, size);

            CPyMarshal.WriteIntField(ptr, typeof(PyObject), "ob_refcnt", 1);
            CPyMarshal.WritePtrField(ptr, typeof(PyObject), "ob_type", this.PyInstance_Type);

            CPyMarshal.WritePtrField(ptr, typeof(PyInstanceObject), "in_class",
                                     this.Store(Builtin.getattr(this.scratchContext, inst, "__class__")));
            CPyMarshal.WritePtrField(ptr, typeof(PyInstanceObject), "in_dict",
                                     this.Store(Builtin.getattr(this.scratchContext, inst, "__dict__")));

            this.map.Associate(ptr, inst);
            return(ptr);
        }
        private PythonFixture BuildFixture(OldClass pythonClass)
        {
            PythonFixture fixture = new PythonFixture((string)pythonClass.__name__);

            OldInstance instance = _createInstance(pythonClass);

            // assing the test methods

            foreach (string methodName in FindTestMethods(pythonClass, TestMethodPrefix))
            {
                fixture.Add(new PythonTestCase(methodName, MakeProc(instance, methodName)));
            }

            // assign the setup and tear down methods

            fixture.SetFixtureSetup(MakeProc(instance, "setUpFixture"));
            fixture.SetFixtureTeardown(MakeProc(instance, "tearDownFixture"));
            fixture.SetSetup(MakeProc(instance, "setUp"));
            fixture.SetTeardown(MakeProc(instance, "tearDown"));

            // all done

            return(fixture);
        }
Example #7
0
 public OldInstanceDebugView(OldInstance userObject)
 {
     _userObject = userObject;
 }
Example #8
0
 public MetaOldInstance(Expression /*!*/ expression, BindingRestrictions /*!*/ restrictions, OldInstance /*!*/ value)
     : base(expression, BindingRestrictions.Empty, value)
 {
     Assert.NotNull(value);
 }
Example #9
0
 public OldInstanceDebugView(OldInstance userObject) {
     _userObject = userObject;
 }
Example #10
0
 public OldInstanceException(OldInstance instance)
 {
     _instance = instance;
 }
Example #11
0
 // a version of GetName that also works on old-style classes
 internal static string GetOldName(OldInstance instance)
 {
     return(instance._class.Name);
 }