summaryrefslogtreecommitdiffstats
path: root/Doc/ext/test.py
diff options
context:
space:
mode:
authorJim Fulton <jim@zope.com>2003-06-28 13:29:16 (GMT)
committerJim Fulton <jim@zope.com>2003-06-28 13:29:16 (GMT)
commit6c71091fbe9698255ea67f4ea2f61a1b586ff827 (patch)
treed9372c9f552fb709b03b5c4f3e65c0dd1b6ba69c /Doc/ext/test.py
parent9c3e9572515f11ebec1321d2b683abb60da3fe9e (diff)
downloadcpython-6c71091fbe9698255ea67f4ea2f61a1b586ff827.zip
cpython-6c71091fbe9698255ea67f4ea2f61a1b586ff827.tar.gz
cpython-6c71091fbe9698255ea67f4ea2f61a1b586ff827.tar.bz2
Rewrote the docs for supporting cyclic garbage collection to reflect
the new way that once writes types. Deleted the old section and sample code and added a new section building on the Noddy example.
Diffstat (limited to 'Doc/ext/test.py')
-rw-r--r--Doc/ext/test.py93
1 files changed, 93 insertions, 0 deletions
diff --git a/Doc/ext/test.py b/Doc/ext/test.py
index 5e09e7c..10549d68 100644
--- a/Doc/ext/test.py
+++ b/Doc/ext/test.py
@@ -106,6 +106,99 @@ Traceback (most recent call last):
TypeError: an integer is required
>>> del n1
>>> del n2
+
+Noddy 4
+
+>>> import noddy4
+>>> n1 = noddy4.Noddy('jim', 'fulton', 42)
+>>> n1.first
+'jim'
+>>> n1.last
+'fulton'
+>>> n1.number
+42
+>>> n1.name()
+'jim fulton'
+>>> n1.first = 'will'
+>>> n1.name()
+'will fulton'
+>>> n1.last = 'tell'
+>>> n1.name()
+'will tell'
+>>> del n1.first
+>>> n1.name()
+Traceback (most recent call last):
+...
+AttributeError: first
+>>> n1.first
+Traceback (most recent call last):
+...
+AttributeError: first
+>>> n1.first = 'drew'
+>>> n1.first
+'drew'
+>>> del n1.number
+Traceback (most recent call last):
+...
+TypeError: can't delete numeric/char attribute
+>>> n1.number=2
+>>> n1.number
+2
+>>> n1.first = 42
+>>> n1.name()
+'42 tell'
+>>> n2 = noddy4.Noddy()
+>>> n2 = noddy4.Noddy()
+>>> n2 = noddy4.Noddy()
+>>> n2 = noddy4.Noddy()
+>>> n2.name()
+' '
+>>> n2.first
+''
+>>> n2.last
+''
+>>> del n2.first
+>>> n2.first
+Traceback (most recent call last):
+...
+AttributeError: first
+>>> n2.first
+Traceback (most recent call last):
+...
+AttributeError: first
+>>> n2.name()
+Traceback (most recent call last):
+ File "<stdin>", line 1, in ?
+AttributeError: first
+>>> n2.number
+0
+>>> n3 = noddy4.Noddy('jim', 'fulton', 'waaa')
+Traceback (most recent call last):
+ File "<stdin>", line 1, in ?
+TypeError: an integer is required
+
+
+Test cyclic gc(?)
+
+>>> import gc
+>>> gc.disable()
+
+>>> x = []
+>>> l = [x]
+>>> n2.first = l
+>>> n2.first
+[[]]
+>>> l.append(n2)
+>>> del l
+>>> del n1
+>>> del n2
+>>> sys.getrefcount(x)
+3
+>>> ignore = gc.collect()
+>>> sys.getrefcount(x)
+2
+
+>>> gc.enable()
"""
import os