[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8468 - trunk/gnue-common/src/utils
From: |
reinhard |
Subject: |
[gnue] r8468 - trunk/gnue-common/src/utils |
Date: |
Thu, 18 May 2006 07:16:06 -0500 (CDT) |
Author: reinhard
Date: 2006-05-18 07:16:06 -0500 (Thu, 18 May 2006)
New Revision: 8468
Modified:
trunk/gnue-common/src/utils/tree.py
Log:
Finished test code (and already found a few bugs).
Modified: trunk/gnue-common/src/utils/tree.py
===================================================================
--- trunk/gnue-common/src/utils/tree.py 2006-05-18 09:36:28 UTC (rev 8467)
+++ trunk/gnue-common/src/utils/tree.py 2006-05-18 12:16:06 UTC (rev 8468)
@@ -67,7 +67,7 @@
message = u_(
"Duplicate child name '%(child_name)s' for parent node "
"'%(parent_node)s'")
- errors.SystemError.__init(self, message % {
+ errors.SystemError.__init__(self, message % {
'child_name': child_name,
'parent_node': repr(parent_node)})
@@ -90,7 +90,7 @@
message = u_(
"Duplicate node name '%(descendant_name)s' in descendants of "
"node type %(descendant_type)s of node '%(ancestor_node)s'")
- errors.SystemError.__init(self, message % {
+ errors.SystemError.__init__(self, message % {
'descendant_name': descendant_name,
'descendant_type': descendant_type,
'ancestor_node': ancestor_node})
@@ -106,11 +106,11 @@
"""
def __init__(self, node_name, node_class, node_type):
message = u_(
- "Node '%(node_name)s' of class '%(node_class)s does not "
- "maintain a node dictionary for node type %(node_type)s")
- errors.SystemError.__init(self, message % {
+ "Node '%(node_name)s' of class '%(node_class)s' does not "
+ "maintain a node dictionary for node type '%(node_type)s'")
+ errors.SystemError.__init__(self, message % {
'node_name': node_name,
- 'node_class': node_class,
+ 'node_class': node_class.__module__ + '.' +
node_class.__name__,
'node_type': node_type})
@@ -654,6 +654,9 @@
the L{_node_dicts_} list of the class of this node.
"""
+ if node_type not in self.__node_dicts:
+ raise NodeDictNotAvailableError, (self.__node_name, self.__class__,
+ node_type)
return self.__node_dicts[node_type]
@@ -759,16 +762,14 @@
ManNode(star_trek, 'Leonard McCoy')
WomanNode(star_trek, 'Nyota Uhura')
ManNode(star_trek, None) # The nameless security officer
- woman = Node(james_kirk) # Kirk's spouse - unnamed node by intention
- peter_kirk = ManNode(woman, 'Peter Kirk') # Kirk's son
+ wife = Node(james_kirk) # Kirk's wife - unnamed node by intention
+ peter_kirk = ManNode(wife, 'Peter Kirk') # Kirk's son
# Test "node_type" property
print james_kirk, "is node type", james_kirk.node_type
# Test "node_name" property
print james_kirk, "is node name", james_kirk.node_name
- james_kirk.node_name = 'James Tiberius Kirk'
- print "Now his node name has changed to", james_kirk.node_name
# Test "get_child" method
print "Terry Jones can be found:", monty_python.get_child('Terry Jones')
@@ -794,12 +795,53 @@
for (key, value) in root.get_node_dict('man').items():
print " ", key, "=", value
- # Test changing node name: get_child, get_node_dict for old and new
+ # Test changing node name:
+ james_kirk.node_name = 'James Tiberius Kirk'
+ print "Now Kirk's node name has changed to", james_kirk.node_name
+ print "Now he can be found under the new name with get_child:", \
+ star_trek.get_child('James Tiberius Kirk')
+ print "Now he can be found under the new name with find_descendant:", \
+ root.find_descendant('James Tiberius Kirk')
+ print "He cannot be found under the old name any more:", \
+ star_trek.get_child('James T. Kirk'), "-", \
+ root.find_descendant('James T. Kirk')
+ print "He is in root's node_dict as 'James Tiberius Kirk':", \
+ 'James Tiberius Kirk' in root.get_node_dict('man')
+ print "He is in root's node_dict as 'James T. Kirk':", \
+ 'James T. Kirk' in root.get_node_dict('man')
# Test changing parent: get_child, get_node_dict for old and new
+ print "Making John Cleese a son of James Kirk's wife (ugh!)"
+ john_cleese.parent = wife
+ print "Now he can be found under Star Trek with find_descendant:", \
+ star_trek.find_descendant('John Cleese')
+ print "He cannot be found under Monty Python any more:", \
+ monty_python.get_child('John Cleese'), "-", \
+ monty_python.find_descendant('John Cleese')
+ print "He is in Star Trek's node_dict:", \
+ 'John Cleese' in star_trek.get_node_dict('man')
+ print "He is in Monty Python's node_dict:", \
+ 'John Cleese' in monty_python.get_node_dict('man')
# Test DuplicateChildNameError
+ try:
+ TextNode(star_trek, 'Nyota Uhura')
+ except DuplicateChildNameError, error:
+ print "Correctly got an exception:", error
+ new_uhura = WomanNode(wife, 'Nyota Uhura') # this may not fail...
+ try:
+ new_uhura.parent = star_trek # ...but this must fail
+ except DuplicateChildNameError, error:
+ print "Correctly got an exception:", error
# Test DuplicateDescendantNameError
+ try:
+ TextNode(peter_kirk, 'Terry Jones')
+ except DuplicateDescendantNameError, error:
+ print "Correctly got an exception:", error
# Test NodeDictNotAvailableError
+ try:
+ root.get_node_dict('woman')
+ except NodeDictNotAvailableError, error:
+ print "Correctly got an exception:", error
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8468 - trunk/gnue-common/src/utils,
reinhard <=