[Python-checkins] python/dist/src/Lib/test test_gc.py,1.12.10.3,1.12.10.4

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Tue, 08 Apr 2003 13:33:31 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv21203/Lib/test

Modified Files:
      Tag: release22-maint
	test_gc.py 
Log Message:
Fixed the gc-vs-__del__ bugs for new-style classes.  That's it for this one.


Index: test_gc.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_gc.py,v
retrieving revision 1.12.10.3
retrieving revision 1.12.10.4
diff -C2 -d -r1.12.10.3 -r1.12.10.4
*** test_gc.py	8 Apr 2003 19:32:53 -0000	1.12.10.3
--- test_gc.py	8 Apr 2003 20:32:57 -0000	1.12.10.4
***************
*** 258,261 ****
--- 258,303 ----
      expect(len(gc.garbage), garbagelen, "boom2")
  
+ # boom__new and boom2_new are exactly like boom and boom2, except use
+ # new-style classes.
+ 
+ class Boom_New(object):
+     def __getattr__(self, someattribute):
+         del self.attr
+         raise AttributeError
+ 
+ def test_boom_new():
+     a = Boom_New()
+     b = Boom_New()
+     a.attr = b
+     b.attr = a
+ 
+     gc.collect()
+     garbagelen = len(gc.garbage)
+     del a, b
+     expect(gc.collect(), 4, "boom_new")
+     expect(len(gc.garbage), garbagelen, "boom_new")
+ 
+ class Boom2_New(object):
+     def __init__(self):
+         self.x = 0
+ 
+     def __getattr__(self, someattribute):
+         self.x += 1
+         if self.x > 1:
+             del self.attr
+         raise AttributeError
+ 
+ def test_boom2_new():
+     a = Boom2_New()
+     b = Boom2_New()
+     a.attr = b
+     b.attr = a
+ 
+     gc.collect()
+     garbagelen = len(gc.garbage)
+     del a, b
+     expect(gc.collect(), 4, "boom2_new")
+     expect(len(gc.garbage), garbagelen, "boom2_new")
+ 
  def test_all():
      gc.collect() # Delete 2nd generation garbage
***************
*** 276,279 ****
--- 318,323 ----
      run_test("boom", test_boom)
      run_test("boom2", test_boom2)
+     run_test("boom_new", test_boom_new)
+     run_test("boom2_new", test_boom2_new)
  
  def test():