<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">"""Test module for the noddy examples

Noddy 1:

&gt;&gt;&gt; import noddy
&gt;&gt;&gt; n1 = noddy.Noddy()
&gt;&gt;&gt; n2 = noddy.Noddy()
&gt;&gt;&gt; del n1
&gt;&gt;&gt; del n2


Noddy 2

&gt;&gt;&gt; import noddy2
&gt;&gt;&gt; n1 = noddy2.Noddy('jim', 'fulton', 42)
&gt;&gt;&gt; n1.first
'jim'
&gt;&gt;&gt; n1.last
'fulton'
&gt;&gt;&gt; n1.number
42
&gt;&gt;&gt; n1.name()
'jim fulton'
&gt;&gt;&gt; n1.first = 'will'
&gt;&gt;&gt; n1.name()
'will fulton'
&gt;&gt;&gt; n1.last = 'tell'
&gt;&gt;&gt; n1.name()
'will tell'
&gt;&gt;&gt; del n1.first
&gt;&gt;&gt; n1.name()
Traceback (most recent call last):
...
AttributeError: first
&gt;&gt;&gt; n1.first
Traceback (most recent call last):
...
AttributeError: first
&gt;&gt;&gt; n1.first = 'drew'
&gt;&gt;&gt; n1.first
'drew'
&gt;&gt;&gt; del n1.number
Traceback (most recent call last):
...
TypeError: can't delete numeric/char attribute
&gt;&gt;&gt; n1.number=2
&gt;&gt;&gt; n1.number
2
&gt;&gt;&gt; n1.first = 42
&gt;&gt;&gt; n1.name()
'42 tell'
&gt;&gt;&gt; n2 = noddy2.Noddy()
&gt;&gt;&gt; n2.name()
' '
&gt;&gt;&gt; n2.first
''
&gt;&gt;&gt; n2.last
''
&gt;&gt;&gt; del n2.first
&gt;&gt;&gt; n2.first
Traceback (most recent call last):
...
AttributeError: first
&gt;&gt;&gt; n2.first
Traceback (most recent call last):
...
AttributeError: first
&gt;&gt;&gt; n2.name()
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in ?
AttributeError: first
&gt;&gt;&gt; n2.number
0
&gt;&gt;&gt; n3 = noddy2.Noddy('jim', 'fulton', 'waaa')
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in ?
TypeError: an integer is required
&gt;&gt;&gt; del n1
&gt;&gt;&gt; del n2


Noddy 3

&gt;&gt;&gt; import noddy3
&gt;&gt;&gt; n1 = noddy3.Noddy('jim', 'fulton', 42)
&gt;&gt;&gt; n1 = noddy3.Noddy('jim', 'fulton', 42)
&gt;&gt;&gt; n1.name()
'jim fulton'
&gt;&gt;&gt; del n1.first
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in ?
TypeError: Cannot delete the first attribute
&gt;&gt;&gt; n1.first = 42
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in ?
TypeError: The first attribute value must be a string
&gt;&gt;&gt; n1.first = 'will'
&gt;&gt;&gt; n1.name()
'will fulton'
&gt;&gt;&gt; n2 = noddy3.Noddy()
&gt;&gt;&gt; n2 = noddy3.Noddy()
&gt;&gt;&gt; n2 = noddy3.Noddy()
&gt;&gt;&gt; n3 = noddy3.Noddy('jim', 'fulton', 'waaa')
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in ?
TypeError: an integer is required
&gt;&gt;&gt; del n1
&gt;&gt;&gt; del n2

Noddy 4

&gt;&gt;&gt; import noddy4
&gt;&gt;&gt; n1 = noddy4.Noddy('jim', 'fulton', 42)
&gt;&gt;&gt; n1.first
'jim'
&gt;&gt;&gt; n1.last
'fulton'
&gt;&gt;&gt; n1.number
42
&gt;&gt;&gt; n1.name()
'jim fulton'
&gt;&gt;&gt; n1.first = 'will'
&gt;&gt;&gt; n1.name()
'will fulton'
&gt;&gt;&gt; n1.last = 'tell'
&gt;&gt;&gt; n1.name()
'will tell'
&gt;&gt;&gt; del n1.first
&gt;&gt;&gt; n1.name()
Traceback (most recent call last):
...
AttributeError: first
&gt;&gt;&gt; n1.first
Traceback (most recent call last):
...
AttributeError: first
&gt;&gt;&gt; n1.first = 'drew'
&gt;&gt;&gt; n1.first
'drew'
&gt;&gt;&gt; del n1.number
Traceback (most recent call last):
...
TypeError: can't delete numeric/char attribute
&gt;&gt;&gt; n1.number=2
&gt;&gt;&gt; n1.number
2
&gt;&gt;&gt; n1.first = 42
&gt;&gt;&gt; n1.name()
'42 tell'
&gt;&gt;&gt; n2 = noddy4.Noddy()
&gt;&gt;&gt; n2 = noddy4.Noddy()
&gt;&gt;&gt; n2 = noddy4.Noddy()
&gt;&gt;&gt; n2 = noddy4.Noddy()
&gt;&gt;&gt; n2.name()
' '
&gt;&gt;&gt; n2.first
''
&gt;&gt;&gt; n2.last
''
&gt;&gt;&gt; del n2.first
&gt;&gt;&gt; n2.first
Traceback (most recent call last):
...
AttributeError: first
&gt;&gt;&gt; n2.first
Traceback (most recent call last):
...
AttributeError: first
&gt;&gt;&gt; n2.name()
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in ?
AttributeError: first
&gt;&gt;&gt; n2.number
0
&gt;&gt;&gt; n3 = noddy4.Noddy('jim', 'fulton', 'waaa')
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in ?
TypeError: an integer is required


Test cyclic gc(?)

&gt;&gt;&gt; import gc
&gt;&gt;&gt; gc.disable()

&gt;&gt;&gt; x = []
&gt;&gt;&gt; l = [x]
&gt;&gt;&gt; n2.first = l
&gt;&gt;&gt; n2.first
[[]]
&gt;&gt;&gt; l.append(n2)
&gt;&gt;&gt; del l
&gt;&gt;&gt; del n1
&gt;&gt;&gt; del n2
&gt;&gt;&gt; sys.getrefcount(x)
3
&gt;&gt;&gt; ignore = gc.collect()
&gt;&gt;&gt; sys.getrefcount(x)
2

&gt;&gt;&gt; gc.enable()
"""

import os
import sys
from distutils.util import get_platform
PLAT_SPEC = "%s-%s" % (get_platform(), sys.version[0:3])
src = os.path.join("build", "lib.%s" % PLAT_SPEC)
sys.path.append(src)

if __name__ == "__main__":
    import doctest, __main__
    doctest.testmod(__main__)
</pre></body></html>