def testParentFromCpp(self): o = ObjectType() self.assertEqual(sys.getrefcount(o), 2) o.getCppParent().setObjectName('parent') self.assertEqual(sys.getrefcount(o), 3) o.getCppParent().setObjectName('parent') self.assertEqual(sys.getrefcount(o), 3) o.getCppParent().setObjectName('parent') self.assertEqual(sys.getrefcount(o), 3) o.getCppParent().setObjectName('parent') self.assertEqual(sys.getrefcount(o), 3) o.getCppParent().setObjectName('parent') self.assertEqual(sys.getrefcount(o), 3) o.destroyCppParent() self.assertEqual(sys.getrefcount(o), 2)
def testInvalidateChild(self): '''Invalidating method call should remove child from the care of a parent if it has one.''' parent = ObjectType() child1 = ObjectType(parent) child1.setObjectName('child1') child2 = ObjectType.create() child2.setParent(parent) child2.setObjectName('child2') self.assertEqual(parent.children(), [child1, child2]) bbox = BlackBox() # This method steals ownership from Python to C++. bbox.keepObjectType(child1) self.assertEqual(parent.children(), [child2]) bbox.keepObjectType(child2) self.assertEqual(parent.children(), []) del parent self.assertEqual(child1.objectName(), 'child1') self.assertRaises(RuntimeError, child2.objectName)
def testAccessingObjectTypeField(self): '''Reads and writes a object type (in this case an 'ObjectType') field.''' d = Derived() # attribution old_value = d.objectTypeField new_value = ObjectType() d.objectTypeField = new_value self.assertEqual(d.objectTypeField, new_value) self.assertNotEqual(d.objectTypeField, old_value) # attribution with a convertible type value = None d.objectTypeField = value self.assertEqual(d.objectTypeField, value) # attribution with invalid type self.assertRaises(TypeError, lambda : setattr(d, 'objectTypeField', 123))
def testImplicitConversions(self): '''Test if overloaded function call decisor takes implicit conversions into account.''' ic = ImplicitConv.implicitConvCommon(ImplicitConv()) self.assertEqual(ic.ctorEnum(), ImplicitConv.CtorNone) ic = ImplicitConv.implicitConvCommon(3) self.assertEqual(ic.ctorEnum(), ImplicitConv.CtorOne) self.assertEqual(ic.objId(), 3) ic = ImplicitConv.implicitConvCommon(ImplicitConv.CtorThree) self.assertEqual(ic.ctorEnum(), ImplicitConv.CtorThree) obj = ObjectType() ic = ImplicitConv.implicitConvCommon(obj) self.assertEqual(ic.ctorEnum(), ImplicitConv.CtorObjectTypeReference) ic = ImplicitConv.implicitConvCommon(42.42) self.assertEqual(ic.value(), 42.42)
def testProtectedObjectTypeProperty(self): '''Writes and reads a protected object type property.''' obj = ObjectType() self.obj.protectedObjectTypeProperty = obj self.assertEqual(self.obj.protectedObjectTypeProperty, obj)
def testLShiftWithExpectedType(self): '''Collector << ObjectType # libsample << operator''' collector = Collector() obj = ObjectType() collector << obj self.assertEqual(collector.items()[0], obj.identifier())
def testWithInt(self): '''Overload with Enums and ints with default value''' o = ObjectType() self.assertEqual(o.callWithEnum('', Event.ANY_EVENT, 9), 81) self.assertEqual(o.callWithEnum('', 9), 9)
def testOneArgument(self): p = ObjectType() o = ObjectType(parent=p) self.assertEqual(o.parent(), p)
def testNextInFocusChainCycle(self): parent = ObjectType() child = ObjectType(parent) next_focus = child.nextInFocusChain() shiboken.invalidate(parent)
def testNullOverload(self): o = ObjectType() o.setObject(None) self.assertEqual(o.callId(), 0) o.setNullObject(None) self.assertEqual(o.callId(), 1)
def testObjectTypeSetObjectNameWithPythonString(self): '''ObjectType.setObjectName with Python string as argument.''' o = ObjectType() o.setObjectName('object name') self.assertEqual(str(o.objectName()), 'object name')
def testObjectTypeSetObjectNameWithStrInstantiation(self): '''ObjectType.setObjectName with Str instantiation as argument.''' s = 'object name' o = ObjectType() o.setObjectName(Str(s)) self.assertEqual(str(o.objectName()), s)
def testObjectTypeSetObjectNameWithStrVariable(self): '''ObjectType.setObjectName with Str variable as argument.''' s = Str('object name') o = ObjectType() o.setObjectName(s) self.assertEqual(str(o.objectName()), str(s))
def testBasic(self): '''ObjectType weakref''' obj = ObjectType() ref = weakref.ref(obj, self.cb) del obj self.assertTrue(self.called)
def testCallWithError(self): o = ObjectType() warnings.simplefilter("error") self.assertRaises(DeprecationWarning, o.deprecatedFunction)
def testBasic(self): '''Collector << ObjectType # greedy collector''' collector = Collector() obj = ObjectType() collector << obj self.assertEqual(collector.items()[0], obj.identifier())