diff options
Diffstat (limited to 'subversion/tests/cmdline/svntest/tree.py')
-rw-r--r-- | subversion/tests/cmdline/svntest/tree.py | 67 |
1 files changed, 42 insertions, 25 deletions
diff --git a/subversion/tests/cmdline/svntest/tree.py b/subversion/tests/cmdline/svntest/tree.py index 1604f49..b8dd03e 100644 --- a/subversion/tests/cmdline/svntest/tree.py +++ b/subversion/tests/cmdline/svntest/tree.py @@ -31,12 +31,15 @@ if sys.version_info[0] >= 3: from io import StringIO else: # Python <3.0 - from StringIO import StringIO + from cStringIO import StringIO from xml.dom.minidom import parseString import base64 +import logging import svntest +logger = logging.getLogger() + # Tree Exceptions. # All tree exceptions should inherit from SVNTreeError @@ -250,6 +253,10 @@ class SVNTreeNode: # remove the subtree path, skip this node if necessary. if path.startswith(subtree): path = path[len(subtree):] + elif path + os.sep == subtree: + # Many callers set subtree to 'some-path' + os.sep. Don't skip the + # root node in that case. + path = '' else: return 0 @@ -569,7 +576,7 @@ def get_child(node, name): """If SVNTreeNode NODE contains a child named NAME, return child; else, return None. If SVNTreeNode is not a directory, exit completely.""" if node.children == None: - print("Error: Foolish call to get_child.") + logger.error("Foolish call to get_child.") sys.exit(1) for n in node.children: if name == n.name: @@ -581,8 +588,8 @@ def get_child(node, name): def default_singleton_handler(node, description): """Print SVNTreeNode NODE's name, describing it with the string DESCRIPTION, then raise SVNTreeUnequal.""" - print("Couldn't find node '%s' in %s tree" % (node.name, description)) - node.pprint() + logger.warn("Couldn't find node '%s' in %s tree" % (node.name, description)) + logger.warn(str(node)) raise SVNTreeUnequal # A test helper function implementing the singleton_handler_a API. @@ -599,8 +606,8 @@ def detect_conflict_files(node, extra_files): break else: msg = "Encountered unexpected disk path '" + node.name + "'" - print(msg) - node.pprint() + logger.warn(msg) + logger.warn(str(node)) raise SVNTreeUnequal(msg) ########################################################################### @@ -634,17 +641,20 @@ def compare_trees(label, def display_nodes(a, b): 'Display two nodes, expected and actual.' - print("=============================================================") - print("Expected '%s' and actual '%s' in %s tree are different!" - % (b.name, a.name, label)) - print("=============================================================") - print("EXPECTED NODE TO BE:") - print("=============================================================") - b.pprint() - print("=============================================================") - print("ACTUAL NODE FOUND:") - print("=============================================================") - a.pprint() + o = StringIO() + o.write("=============================================================\n") + o.write("Expected '%s' and actual '%s' in %s tree are different!\n" + % (b.name, a.name, label)) + o.write("=============================================================\n") + o.write("EXPECTED NODE TO BE:\n") + o.write("=============================================================\n") + b.pprint(o) + o.write("=============================================================\n") + o.write("ACTUAL NODE FOUND:\n") + o.write("=============================================================\n") + a.pprint(o) + logger.warn(o.getvalue()) + o.close() # Setup singleton handlers if singleton_handler_a is None: @@ -690,21 +700,21 @@ def compare_trees(label, if b_child not in accounted_for: singleton_handler_b(b_child, b_baton) except SVNTypeMismatch: - print('Unequal Types: one Node is a file, the other is a directory') + logger.warn('Unequal Types: one Node is a file, the other is a directory') raise SVNTreeUnequal except IndexError: - print("Error: unequal number of children") + logger.warn("Error: unequal number of children") raise SVNTreeUnequal except SVNTreeUnequal: if a.name != root_node_name: - print("Unequal at node %s" % a.name) + logger.warn("Unequal at node %s" % a.name) raise # Visually show a tree's structure -def dump_tree(n,indent=""): +def _dump_tree(n,indent="",stream=sys.stdout): """Print out a nice representation of the structure of the tree in the SVNTreeNode N. Prefix each line with the string INDENT.""" @@ -712,18 +722,25 @@ def dump_tree(n,indent=""): tmp_children = sorted(n.children or []) if n.name == root_node_name: - print("%s%s" % (indent, "ROOT")) + stream.write("%s%s\n" % (indent, "ROOT")) else: - print("%s%s" % (indent, n.name)) + stream.write("%s%s\n" % (indent, n.name)) indent = indent.replace("-", " ") indent = indent.replace("+", " ") for i in range(len(tmp_children)): c = tmp_children[i] if i == len(tmp_children)-1: - dump_tree(c,indent + " +-- ") + _dump_tree(c,indent + " +-- ",stream) else: - dump_tree(c,indent + " |-- ") + _dump_tree(c,indent + " |-- ",stream) + + +def dump_tree(n): + output = StringIO() + _dump_tree(n,stream=output) + logger.warn(output.getvalue()) + output.close() def dump_tree_script__crawler(n, subtree="", stream=sys.stdout): |