Add testcase for toctree

This commit is contained in:
Takeshi KOMIYA
2016-09-18 17:14:55 +09:00
parent 0417a084db
commit 9358ea239b
10 changed files with 439 additions and 5 deletions

View File

@@ -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: