add __iter__ method to schemas
This commit is contained in:
@@ -1179,6 +1179,10 @@ class SchemaNode(object):
|
|||||||
raise TypeError('Unknown keyword arguments: %s' % repr(kw))
|
raise TypeError('Unknown keyword arguments: %s' % repr(kw))
|
||||||
self.children = list(children)
|
self.children = list(children)
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
""" Iterate over the children nodes of this schema node """
|
||||||
|
return iter(self.children)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s.%s object at %d (named %s)>' % (
|
return '<%s.%s object at %d (named %s)>' % (
|
||||||
self.__module__,
|
self.__module__,
|
||||||
|
@@ -1395,6 +1395,12 @@ class TestSchemaNode(unittest.TestCase):
|
|||||||
node = self._makeOne(None)
|
node = self._makeOne(None)
|
||||||
self.assertRaises(KeyError, node.__getitem__, 'another')
|
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):
|
def test_clone(self):
|
||||||
inner_typ = DummyType()
|
inner_typ = DummyType()
|
||||||
outer_typ = DummyType()
|
outer_typ = DummyType()
|
||||||
|
Reference in New Issue
Block a user