add __iter__ method to schemas

This commit is contained in:
Chris McDonough
2010-08-16 20:30:52 +00:00
parent 56f6f2ad14
commit 3abb1900bb
2 changed files with 10 additions and 0 deletions

View File

@@ -1179,6 +1179,10 @@ class SchemaNode(object):
raise TypeError('Unknown keyword arguments: %s' % repr(kw))
self.children = list(children)
def __iter__(self):
""" Iterate over the children nodes of this schema node """
return iter(self.children)
def __repr__(self):
return '<%s.%s object at %d (named %s)>' % (
self.__module__,

View File

@@ -1395,6 +1395,12 @@ class TestSchemaNode(unittest.TestCase):
node = self._makeOne(None)
self.assertRaises(KeyError, node.__getitem__, 'another')
def test___iter__(self):
node = self._makeOne(None)
node.children = ['a', 'b', 'c']
it = node.__iter__()
self.assertEqual(list(it), ['a', 'b', 'c'])
def test_clone(self):
inner_typ = DummyType()
outer_typ = DummyType()