本文整理汇总了Python中sample.ObjectType类的典型用法代码示例。如果您正苦于以下问题:Python ObjectType类的具体用法?Python ObjectType怎么用?Python ObjectType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testReparentWithTheSameParent
def testReparentWithTheSameParent(self):
'''Set the same parent twice to check if the ref continue the same'''
obj = ObjectType()
parent = ObjectType()
self.assertEqual(sys.getrefcount(obj), 2)
obj.setParent(parent)
self.assertEqual(sys.getrefcount(obj), 3)
obj.setParent(parent)
self.assertEqual(sys.getrefcount(obj), 3)
示例2: testDeleteChild
def testDeleteChild(self):
'''Delete child in python should not invalidate child'''
parent = ObjectType()
child = ObjectType(parent)
name = ''.join(random.sample(string.letters, 5))
child.setObjectName(name)
del child
new_child = parent.children()[0]
self.assertEqual(new_child.objectName(), name)
示例3: testObjectTypeReferenceAndPointer
def testObjectTypeReferenceAndPointer(self):
'''In C++ we have "function(const ObjectType&, int)",
in Python we add "function(ValueType)".'''
obj = ObjectType()
obj.setObjectName('sbrubbles')
multiplier = 3.0
control = len(obj.objectName()) * multiplier
self.assertEqual(SampleNamespace.passReferenceToObjectType(obj, multiplier), control)
control = len(obj.objectName())
self.assertEqual(SampleNamespace.passReferenceToObjectType(obj), control)
示例4: testParentDestructor
def testParentDestructor(self):
'''Delete parent object should invalidate child'''
parent = ObjectType()
child = ObjectType()
child.setParent(parent)
refcount_before = sys.getrefcount(child)
del parent
self.assertRaises(RuntimeError, child.objectName)
self.assertEqual(sys.getrefcount(child), refcount_before-1)
示例5: testReparentedObjectTypeIdentityWithChildrenCreatedInCpp
def testReparentedObjectTypeIdentityWithChildrenCreatedInCpp(self):
'''Reparent children created in C++ from one parent to another.'''
object_list = []
old_parent = ObjectType()
new_parent = ObjectType()
for i in range(3):
obj = ObjectType.create()
object_list.append(obj)
obj.setParent(old_parent)
for obj in object_list:
obj.setParent(new_parent)
for child in new_parent.children():
self.assert_(child in object_list)
示例6: testDeleteChild
def testDeleteChild(self):
'''Delete child in C++ should invalidate child - using C++ wrapper'''
parent = ObjectType()
parent.setObjectName('parent')
child = ObjectType(parent)
child.setObjectName('child')
parent.killChild('child')
self.assertRaises(RuntimeError, child.objectName)
self.assertEqual(parent.objectName(), 'parent')
示例7: testNextInFocusChainCycleList
def testNextInFocusChainCycleList(self):
'''As above but in for a list of objects'''
parents = []
children = []
focus_chains = []
for i in range(10):
parent = ObjectType()
child = ObjectType(parent)
next_focus = child.nextInFocusChain()
parents.append(parent)
children.append(child)
focus_chains.append(next_focus)
shiboken.invalidate(parents)
示例8: testCpp
def testCpp(self):
'''C++ calling C++ virtual method in multiple inheritance scenario'''
obj = ImplementsNone()
self.assert_(ObjectType.processEvent([obj], Event(Event.BASIC_EVENT)))
self.assertRaises(AttributeError, getattr, obj, 'event_processed')
self.assertEqual(obj.callSum0(1, 2, 3), 6)
示例9: testEvent
def testEvent(self):
'''C++ calling Python reimplementation of virtual in multiple inheritance'''
obj = ImplementsBoth()
self.assert_(ObjectType.processEvent([obj], Event(Event.BASIC_EVENT)))
self.assert_(obj.event_processed)
self.assertEqual(obj.callSum1(1, 2, 3), 12)
示例10: testOwnershipTransferenceCppCreated
def testOwnershipTransferenceCppCreated(self):
'''Ownership transference using a C++ created object.'''
o1 = ObjectType.create()
o1.setObjectName('object1')
o1_refcnt = sys.getrefcount(o1)
bb = BlackBox()
o1_ticket = bb.keepObjectType(o1)
self.assertRaises(RuntimeError, o1.objectName)
示例11: testEventLoop
def testEventLoop(self):
'''Calling virtuals in a event loop'''
objs = [ObjectType(), NoOverride(), Override()]
evaluated = ObjectType.processEvent(objs,
Event(Event.BASIC_EVENT))
self.assertEqual(evaluated, 3)
self.assert_(objs[2].called)
示例12: testUseDefaultValues
def testUseDefaultValues(self):
o = ObjectType()
o.setObjectNameWithSize(size=3)
self.assertEqual(o.objectName(), "<un") # use name='unknown' default argument
o.setObjectSplittedName("")
self.assertEqual(o.objectName(), "<unknown>") # user prefix='<unk' and suffix='nown>'
示例13: testBasic
def testBasic(self):
'''Allowing threads and calling virtuals from C++'''
number = 10
objs = [Producer() for x in range(number)]
thread = Collector(objs)
thread.start()
evaluated = ObjectType.processEvent(objs,
Event(Event.BASIC_EVENT))
thread.join()
producer_data = [x.data for x in objs]
self.assertEqual(evaluated, number)
self.assertEqual(producer_data, thread.data)
示例14: testOwnershipTransference
def testOwnershipTransference(self):
'''Ownership transference from Python to C++ and back again.'''
o1 = ObjectType()
o1.setObjectName('object1')
o1_refcnt = sys.getrefcount(o1)
o2 = ObjectType()
o2.setObjectName('object2')
o2_refcnt = sys.getrefcount(o2)
bb = BlackBox()
o1_ticket = bb.keepObjectType(o1)
o2_ticket = bb.keepObjectType(o2)
self.assertEqual(set(bb.objects()), set([o1, o2]))
self.assertEqual(str(o1.objectName()), 'object1')
self.assertEqual(str(o2.objectName()), 'object2')
self.assertEqual(sys.getrefcount(o1), o1_refcnt + 1) # PySide give +1 ref to object with c++ ownership
self.assertEqual(sys.getrefcount(o2), o2_refcnt + 1)
o2 = bb.retrieveObjectType(o2_ticket)
self.assertEqual(sys.getrefcount(o2), o2_refcnt)
del bb
self.assertRaises(RuntimeError, o1.objectName)
self.assertEqual(str(o2.objectName()), 'object2')
self.assertEqual(sys.getrefcount(o2), o2_refcnt)
示例15: testInvalidateChild
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)