summaryrefslogtreecommitdiff
path: root/docutils/test/test_nodes.py
diff options
context:
space:
mode:
authorwiemann <wiemann@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2005-03-05 15:53:45 +0000
committerwiemann <wiemann@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2005-03-05 15:53:45 +0000
commita4087c4a6e1ea5b8206252c07b50d362cb689c28 (patch)
treec3f424c78a7d7e3a0fc3a362be6779b48821d70f /docutils/test/test_nodes.py
parent16279b932b2d5ff05e97dff139966ff8279e9c0a (diff)
downloaddocutils-a4087c4a6e1ea5b8206252c07b50d362cb689c28.tar.gz
added Node.has_children() and Node.next_node()
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@3007 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils/test/test_nodes.py')
-rwxr-xr-xdocutils/test/test_nodes.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/docutils/test/test_nodes.py b/docutils/test/test_nodes.py
index fe8f0420f..fee03ffe2 100755
--- a/docutils/test/test_nodes.py
+++ b/docutils/test/test_nodes.py
@@ -10,6 +10,8 @@
Test module for nodes.py.
"""
+from __future__ import nested_scopes
+
import unittest
from types import ClassType
from DocutilsTestSupport import nodes, utils
@@ -108,6 +110,42 @@ class MiscTests(unittest.TestCase):
normed = nodes.make_id(input)
self.assertEquals(normed, output)
+ def test_has_children(self):
+ self.assert_(not nodes.Text('some text').has_children())
+ self.assert_(not nodes.Node().has_children())
+ e = nodes.TextElement()
+ self.assert_(not e.has_children())
+ e += nodes.Text('some text')
+ self.assert_(e.has_children())
+ self.assert_(not e[0].has_children())
+
+ def test_next_node(self):
+ def getlist(n, **kwargs):
+ r = []
+ while n is not None:
+ n = n.next_node(**kwargs)
+ r.append(n)
+ return r[:-1]
+ e = nodes.Element()
+ e += nodes.Element()
+ e[0] += nodes.Element()
+ e[0] += nodes.Element()
+ e[0][1] += nodes.Text('some text')
+ e += nodes.Element()
+ e += nodes.Element()
+ i = e
+ l = []
+ self.assertEquals(getlist(e),
+ [e[0], e[0][0], e[0][1], e[0][1][0], e[1], e[2]])
+ self.assertEquals(getlist(e, descend=0), [])
+ self.assertEquals(getlist(e[0], descend=0), [e[1], e[2]])
+ self.assertEquals(getlist(e[0][0], descend=0), [e[0][1], e[1], e[2]])
+ self.assertEquals(getlist(e, ascend=0),
+ [e[0], e[0][0], e[0][1], e[0][1][0]])
+ self.assertEquals(getlist(e[0][0], descend=0, ascend=0), [e[0][1]])
+ self.assertEquals(getlist(e, cond=lambda x: x not in e[0:2]),
+ [e[0][0], e[0][1], e[0][1][0], e[2]])
+
class TreeCopyVisitorTests(unittest.TestCase):