def testReferreedObjectSurvivalAfterContextEnd(self): '''Model-like object assigned to a view-like object must survive after get out of context.''' def createModelAndSetToView(view): model = ObjectModel() model.setObjectName('created model') view.setModel(model) view = ObjectView() createModelAndSetToView(view) model = view.model()
def testReferenceCountingWhenDeletingReferrer(self): '''Tests reference count of model-like object referred by deceased view-like object.''' model = ObjectModel() refcount1 = getrefcount(model) view = ObjectView() view.setModel(model) self.assertEqual(getrefcount(view.model()), refcount1 + 1) del view self.assertEqual(getrefcount(model), refcount1)
def testReferenceCountingWhenDeletingReferrer(self): """Tests reference count of model-like object referred by deceased view-like object.""" model = ObjectModel() refcount1 = getrefcount(model) view = ObjectView() view.setModel(model) self.assertEqual(getrefcount(view.model()), refcount1 + 1) del view self.assertEqual(getrefcount(model), refcount1)
def testReferenceCounting(self): '''Tests reference count of model-like object referred by view-like objects.''' model1 = ObjectModel() refcount1 = getrefcount(model1) view1 = ObjectView() view1.setModel(model1) self.assertEqual(getrefcount(view1.model()), refcount1 + 1) view2 = ObjectView() view2.setModel(model1) self.assertEqual(getrefcount(view2.model()), refcount1 + 2) model2 = ObjectModel() view2.setModel(model2) self.assertEqual(getrefcount(view1.model()), refcount1 + 1)
def testReferenceCounting(self): """Tests reference count of model-like object referred by view-like objects.""" model1 = ObjectModel() refcount1 = getrefcount(model1) view1 = ObjectView() view1.setModel(model1) self.assertEqual(getrefcount(view1.model()), refcount1 + 1) view2 = ObjectView() view2.setModel(model1) self.assertEqual(getrefcount(view2.model()), refcount1 + 2) model2 = ObjectModel() view2.setModel(model2) self.assertEqual(getrefcount(view1.model()), refcount1 + 1)
def testWrongTypeReturn(self): model = ListModelWrong() view = ObjectView(model) self.assertRaises(RuntimeWarning, view.getRawModelData) # calls model.data()
def testListModelKeepsReference(self): model = ListModelKeepsReference() view = ObjectView(model) obj = view.getRawModelData() self.assertEqual(type(obj), MyObject) self.assertEqual(obj.objectName(), object_name)