Ejemplo n.º 1
0
 def testPrivateCtorInstanceMethod(self):
     '''Test if PrivateCtor.instance() method return the proper singleton.'''
     pd1 = PrivateCtor.instance()
     calls = pd1.instanceCalls()
     self.assertEqual(type(pd1), PrivateCtor)
     pd2 = PrivateCtor.instance()
     self.assertEqual(pd2, pd1)
     self.assertEqual(pd2.instanceCalls(), calls + 1)
Ejemplo n.º 2
0
 def testPrivateCtorInstanceMethod(self):
     """Test if PrivateCtor.instance() method return the proper singleton."""
     pd1 = PrivateCtor.instance()
     calls = pd1.instanceCalls()
     self.assertEqual(type(pd1), PrivateCtor)
     pd2 = PrivateCtor.instance()
     self.assertEqual(pd2, pd1)
     self.assertEqual(pd2.instanceCalls(), calls + 1)
Ejemplo n.º 3
0
 def testPrivateCtorRefCounting(self):
     '''Test refcounting of the singleton returned by PrivateCtor.instance().'''
     pd1 = PrivateCtor.instance()
     calls = pd1.instanceCalls()
     refcnt = sys.getrefcount(pd1)
     pd2 = PrivateCtor.instance()
     self.assertEqual(pd2.instanceCalls(), calls + 1)
     self.assertEqual(sys.getrefcount(pd2), sys.getrefcount(pd1))
     self.assertEqual(sys.getrefcount(pd2), refcnt + 1)
     del pd1
     self.assertEqual(sys.getrefcount(pd2), refcnt)
     del pd2
     gc.collect()
     pd3 = PrivateCtor.instance()
     self.assertEqual(type(pd3), PrivateCtor)
     self.assertEqual(pd3.instanceCalls(), calls + 2)
     self.assertEqual(sys.getrefcount(pd3), refcnt)
Ejemplo n.º 4
0
 def testPrivateCtorRefCounting(self):
     """Test refcounting of the singleton returned by PrivateCtor.instance()."""
     pd1 = PrivateCtor.instance()
     calls = pd1.instanceCalls()
     refcnt = sys.getrefcount(pd1)
     pd2 = PrivateCtor.instance()
     self.assertEqual(pd2.instanceCalls(), calls + 1)
     self.assertEqual(sys.getrefcount(pd2), sys.getrefcount(pd1))
     self.assertEqual(sys.getrefcount(pd2), refcnt + 1)
     del pd1
     self.assertEqual(sys.getrefcount(pd2), refcnt)
     del pd2
     gc.collect()
     pd3 = PrivateCtor.instance()
     self.assertEqual(type(pd3), PrivateCtor)
     self.assertEqual(pd3.instanceCalls(), calls + 2)
     self.assertEqual(sys.getrefcount(pd3), refcnt)