diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2016-09-18 17:14:55 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2016-09-30 10:42:18 +0900 |
commit | 9358ea239b9c4625793c09cf7759047b2fda8ac4 (patch) | |
tree | c71a7d85acdd723eed08189a8f674114da3002bb /tests/util.py | |
parent | 0417a084dbe7c56ca8d6c4a4d50c7822f996c50a (diff) | |
download | sphinx-git-9358ea239b9c4625793c09cf7759047b2fda8ac4.tar.gz |
Add testcase for toctree
Diffstat (limited to 'tests/util.py')
-rw-r--r-- | tests/util.py | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/tests/util.py b/tests/util.py index 27b41bc15..a14bee838 100644 --- a/tests/util.py +++ b/tests/util.py @@ -13,7 +13,7 @@ import sys import tempfile from functools import wraps -from six import StringIO +from six import StringIO, string_types from nose import tools, SkipTest @@ -94,14 +94,33 @@ def assert_startswith(thing, prefix): assert False, '%r does not start with %r' % (thing, prefix) -def assert_node(node, cls=None, **kwargs): +def assert_node(node, cls=None, xpath="", **kwargs): if cls: - assert isinstance(node, cls), '%r is not subclass of %r' % (node, cls) + if isinstance(cls, list): + assert_node(node, cls[0], xpath=xpath, **kwargs) + if cls[1:]: + if isinstance(cls[1], tuple): + assert_node(node, cls[1], xpath=xpath, **kwargs) + else: + assert len(node) == 1, \ + 'The node%s has %d child nodes, not one' % (xpath, len(node)) + assert_node(node[0], cls[1:], xpath=xpath + "[0]", **kwargs) + elif isinstance(cls, tuple): + assert len(node) == len(cls), \ + 'The node%s has %d child nodes, not %r' % (xpath, len(node), len(cls)) + for i, nodecls in enumerate(cls): + path = xpath + "[%d]" % i + assert_node(node[i], nodecls, xpath=path, **kwargs) + elif isinstance(cls, string_types): + assert node == cls, 'The node %r is not %r: %r' % (xpath, cls, node) + else: + assert isinstance(node, cls), \ + 'The node%s is not subclass of %r: %r' % (xpath, cls, node) for key, value in kwargs.items(): - assert key in node, '%r does not have %r attribute' % (node, key) + assert key in node, 'The node%s does not have %r attribute: %r' % (xpath, key, node) assert node[key] == value, \ - '%r[%s]: %r does not equals %r' % (node, key, node[key], value) + 'The node%s[%s] is not %r: %r' % (xpath, key, value, node[key]) try: |