[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

more test suite code

From: Sam TH <sam_at_uchicago.edu>
Date: 2001-04-27 04:40:50 CEST

Here's lots more test suite code. It does the following things:

1. Adds build_tree_from_entries() and helper functions, as I
described.

2. Uses my version of build_tree_from_wc(), modified to store
properties and contents, and to handle the root node the way it was
decided we should.

3. Modifies compare_nodes() to ignore props or contents if one of the
props or contents is None. This allows meaningful comparisons between
trees which contain contents (from the wc) and trees that don't (from
the entries files). Since no normal node should ever have None as one
of those values in any other situation, this shouldn't affect any
comparisons in the apples to apples situation.

4. Fixes up xml_tests.py to actually work again. This required lots
of mundane changes, and changing build_tree_from_commit() to ignore
extraneous stuff.

5. Adds a bunch of helper functions which don't work currently. They
will soon (as in, my next patch)
           
The patch:

Index: svn_entry.py
===================================================================
RCS file: /cvs/subversion/subversion/tests/clients/cmdline/svn_entry.py,v
retrieving revision 1.4
diff -u -r1.4 svn_entry.py
--- svn_entry.py 2001/04/12 18:11:02 1.4
+++ svn_entry.py 2001/04/27 02:27:05
@@ -27,6 +27,8 @@
 # present, such as prop-time, text-time, add, delete, conflict.
 
 import xml.parsers.expat # you may need to install this package
+from svn_tree import *
+import os.path
 
 class svn_entry:
   "An object that represents an entry from an 'entries' file."
@@ -81,6 +83,53 @@
   entryparser.parser.ParseFile(fp)
   fp.close()
   return entryparser.entry_dict
+
+def handle_entries_file(path, current_parent):
+
+ # get a dictionary of all the entries in the entries file
+
+ if os.path.exists(os.path.join(path, "SVN/entries")):
+ entry_path = os.path.join(path, "SVN/entries")
+ else: # we screwed up
+ raise SVNTreeError
+
+ entry_dict = get_entries(entry_path)
+
+ files = []
+ dirs = []
+
+ # put dirs and files in their own lists
+
+ for k in entry_dict.keys():
+ if entry_dict[k].atts['kind'] == 'file':
+ files.append(k)
+ elif (entry_dict[k].atts['kind'] == 'dir') and (k != ""):
+ dirs.append(k)
+
+ # add each file as a child of CURRENT_PARENT
+
+ for f in files:
+ current_parent.add_child(SVNTreeNode(f))
+
+ # for each subdir, create a node, walk its tree, add it as a child
+
+ for d in dirs:
+ new_dir_node = SVNTreeNode(d)
+ handle_entries_file(os.path.join(path, d), new_dir_node)
+ current_parent.add_child(new_dir_node)
+
+def build_tree_from_entries(wc_path):
+
+ """Takes WC_PATH as the path to a working copy. Walks the tree below
+ that path, and creates the tree based on the actual found
+ files."""
+
+ root = SVNTreeNode(root_node_name, None)
+
+ # Walk the tree recursively
+ handle_entries_file(os.path.normpath(wc_path), root)
+
+ return root
 
 
 ### End of file.
Index: svn_test_main.py
===================================================================
RCS file: /cvs/subversion/subversion/tests/clients/cmdline/svn_test_main.py,v
retrieving revision 1.5
diff -u -r1.5 svn_test_main.py
--- svn_test_main.py 2001/04/25 21:23:15 1.5
+++ svn_test_main.py 2001/04/27 02:27:06
@@ -47,12 +47,29 @@
 svnadmin_binary = '../../../svnadmin/svnadmin'
 
 
-# The paths within our greek tree, used to assemble 'expected' trees.
-greek_paths = ['iota', 'A', 'A/mu', 'A/B', 'A/B/lambda', 'A/B/E',
- 'A/B/E/alpha', 'A/B/E/beta', 'A/B/F', 'A/C', 'A/D',
- 'A/D/gamma', 'A/D/G', 'A/D/G/pi', 'A/D/G/rho', 'A/D/G/tau',
- 'A/D/H', 'A/D/H/chi', 'A/D/H/psi', 'A/D/H/omega']
 
+greek_tree = [
+ ["iota", "This is the file 'iota'.", {}],
+ ["A", None, {}],
+ ["A/mu", "This is the file 'mu'.", {}],
+ ["A/B", None, {}],
+ ["A/B/lambda", "This is the file 'lambda'.", {}],
+ ["A/B/E", None, {}],
+ ["A/B/E/alpha", "This is the file 'alpha'.", {}],
+ ["A/B/E/beta", "This is the file 'beta'.", {}],
+ ["A/B/F", None, {}],
+ ["A/C", None, {}],
+ ["A/D", None, {}],
+ ["A/D/gamma", "This is the file 'gamma'.", {}],
+ ["A/D/G", None, {}],
+ ["A/D/G/pi", "This is the file 'pi'.", {}],
+ ["A/D/G/rho", "This is the file 'rho'.", {}],
+ ["A/D/G/tau", "This is the file 'tau'.", {}],
+ ["A/D/H", None, {}],
+ ["A/D/H/chi", "This is the file 'chi'.", {}],
+ ["A/D/H/psi", "This is the file 'psi'.", {}],
+ ["A/D/H/omega", "This is the file 'omega'.", {}]
+ ]
 
 
 ######################################################################
@@ -103,7 +120,42 @@
   run_svnadmin("create", path)
 
 # -- put more shared routines here --
+def create_greek_repos(repos_path, name="greek-tree"):
+ """Create a repository at REPOS_PATH, and import the greek tree into
+ it. The Greek Tree will be named NAME in the repository."""
+
+ create_repos(repos_path)
+ create_new_tree("tmp_greek_tree", greek_tree)
+ run_svn("import", "file://" + os.path.abspath(repos_path),
+ "tmp_greek_tree", name)
+
+def checkout_wc(repos_path, module, wc_name):
+
+ run_svn("checkout", "file://" +
+ os.path.join(os.path.abspath(repos_path), module),
+ "-d", wc_name)
+def create_new_tree(base_path, new_tree):
+ """Create a new directory structure rooted at BASE_PATH in the file
+ system, with the structure and contents as specified by NEW_TREE"""
+
+ for i in new_tree:
+ if i[0] == 'dir':
+ create_dir(os.path.join(base_path, i[1]))
+ elif i[0] == 'file':
+ create_file(os.path.join(base_path, i[1]), i[2])
+
+def create_file(path, text):
+ """Create a new file at PATH, with contents TEXT. If the intermediate
+ directories to PATH do not yet exist, create them"""
+
+ if not(os.path.exists(os.path.dirname(path))):
+ os.makedirs(os.path.dirname(path))
+
+ fp = open(path, 'w')
+ fp.write(text)
+ fp.close
 
+
 # Need a routine which creates a repository containing a greek tree
 
 # Need a routine which creates a working copy of a certain name,
@@ -144,9 +196,16 @@
   # or run all the tests if no arg.
   else:
     got_error = 0
+ passed = 0
+ failed = 0
     for n in range(len(test_list)):
       if n:
         got_error = run_test(n, test_list)
+ if got_error:
+ failed += 1
+ else:
+ passed += 1
+ print "%d Tests Passed, %d Tests Failed" % (passed, failed)
     return got_error
 
 
Index: svn_tree.py
===================================================================
RCS file: /cvs/subversion/subversion/tests/clients/cmdline/svn_tree.py,v
retrieving revision 1.2
diff -u -r1.2 svn_tree.py
--- svn_tree.py 2001/04/27 01:14:15 1.2
+++ svn_tree.py 2001/04/27 02:27:06
@@ -125,9 +125,11 @@
 
   if a.name != b.name:
     return 1
- if a.contents != b.contents:
+ if (a.contents != b.contents) and not((a.contents is None) or
+ (b.contents is None)):
     return 1
- if a.props != b.props: ## is it legal to compare hashes like this?!?
+ if (a.props != b.props) and not((a.props is None) or
+ (b.props is None)): ## is it legal to compare hashes like this?!?
     return 1
   
   # We don't need to compare lists of children, since that's being
@@ -168,7 +170,7 @@
 # a regexp machine for matching the name of the administrative dir.
 rm = re.compile("^SVN/|/SVN/|/SVN$|^/SVN/|^SVN$")
 
-# helper for visitfunc(), which is a helper for build_tree_from_wc()
+# helper for handle_dir(), which is a helper for build_tree_from_wc()
 def get_props(path):
   "Return a hash of props for PATH, using the svn client."
 
@@ -189,7 +191,7 @@
   return props
 
 
-# helper for visitfunc(), which helps build_tree_from_wc()
+# helper for handle_dir(), which helps build_tree_from_wc()
 def get_text(path):
   "Return a string with the textual contents of a file at PATH."
 
@@ -203,40 +205,46 @@
   return contents
 
 
-# helper for build_tree_from_wc() -- callback for os.walk()
-def visitfunc(baton, dirpath, entrynames):
- "Callback for os.walk(). Builds a tree of SVNTreeNodes."
-
- # if any element of DIRPATH is 'SVN', go home.
- if rm.search(dirpath):
- return
-
- # unpack the baton
- root = baton[0]
- load_props = baton[1]
-
- # Create a linked list of nodes from DIRPATH, and deposit
- # DIRPATH's properties in the tip.
- if load_props:
- dirpath_props = get_props(dirpath)
- else:
- dirpath_props = {}
- new_branch = create_from_path(dirpath, None, dirpath_props)
- root.add_child(new_branch)
-
- # Repeat the process for each file entry.
- for entry in entrynames:
- entrypath = os.path.join(dirpath, entry)
- if os.path.isfile(entrypath):
- if load_props:
- file_props = get_props(entrypath)
- else:
- file_props = {}
- file_contents = get_text(entrypath)
- new_branch = create_from_path(entrypath,
- file_contents, file_props)
- root.add_child(new_branch)
+# helper for build_tree_from_wc()
+def handle_dir(path, current_parent, load_props):
+ "Add all the children of directory PATH as children of CURRENT_PARENT"
+ # get a list of all the files
+
+ all_files = os.listdir(path)
+ files = []
+ dirs = []
+
+ # put dirs and files in their own lists, and remove SVN dirs
 
+ for f in all_files:
+ f = os.path.join(path, f)
+ if os.path.isdir(f) and os.path.basename(f) != 'SVN':
+ dirs.append(f)
+ elif os.path.isfile(f):
+ files.append(f)
+
+ # add each file as a child of CURRENT_PARENT
+
+ for f in files:
+ if load_props:
+ file_props = get_props(f)
+ else:
+ file_props = {}
+ file_contents = get_text(f)
+ current_parent.add_child(SVNTreeNode(os.path.basename(f), None,
+ file_contents, file_props))
+
+ # for each subdir, create a node, walk its tree, add it as a child
+
+ for d in dirs:
+ if load_props:
+ dir_props = get_props(d)
+ else:
+ dir_props = {}
+ new_dir_node = SVNTreeNode(os.path.basename(d), None, None, dir_props)
+ handle_dir(d, new_dir_node, load_props)
+ current_parent.add_child(new_dir_node)
+
 
 ###########################################################################
 ###########################################################################
@@ -297,8 +305,7 @@
   indent = indent.replace("+"," ")
   for i in range(len(tmp_children)):
     c = tmp_children[i]
- if i == len(tmp_children
- )-1:
+ if i == len(tmp_children)-1:
       dump_tree(c,indent + " +-- ")
     else:
       dump_tree(c,indent + " |-- ")
@@ -362,8 +369,11 @@
 
   root = SVNTreeNode(root_node_name)
   rm = re.compile ('^(\w+)\s+(.+)')
-
+ ignore_re = re.compile('^Commit.+')
+
   for line in lines:
+ if not((ignore_re.match(line)) is None):
+ continue
     match = rm.search(line)
     if match and match.groups():
       new_branch = create_from_path(match.group(2), None,
@@ -405,22 +415,22 @@
 # creates a drastic slowdown -- we spawn a new 'svn proplist'
 # process for every file and dir in the working copy!
 
+
+
 def build_tree_from_wc(wc_path, load_props=0):
   """Walk a subversion working copy starting at WC_PATH and return a
   tree structure containing file contents. If LOAD_PROPS is true,
   then all file and dir properties will be read into the tree as well."""
-
- root = SVNTreeNode(root_node_name)
 
- baton = (root, load_props)
- os.path.walk(wc_path, visitfunc, baton)
+ root = SVNTreeNode(root_node_name, None)
+
+ # Walk the tree recursively
+ handle_dir(os.path.normpath(wc_path), root, load_props)
 
   return root
-
-
-dump_tree(build_tree_from_wc('wc-t1'))
-
 
+if __name__ == '__main__':
+ dump_tree(build_tree_from_wc('wc-t1'))
 
 
 ### End of file.
Index: xml_tests.py
===================================================================
RCS file: /cvs/subversion/subversion/tests/clients/cmdline/xml_tests.py,v
retrieving revision 1.3
diff -u -r1.3 xml_tests.py
--- xml_tests.py 2001/04/25 21:23:15 1.3
+++ xml_tests.py 2001/04/27 02:27:06
@@ -18,10 +18,10 @@
 
 import svn_test_main
 import svn_tree
-import svn_output
 
 import shutil # for copytree()
 import string # for strip()
+import os
 
 ##### Globals
 
@@ -44,17 +44,17 @@
   output = svn_test_main.run_svn ('co', '-d', wc_dir, \
                                   '--xml-file', xml_path, \
                                   '-r 1', ANCESTOR_PATH)
- output_tree = svn_output.tree_from_checkout (output)
+ output_tree = svn_tree.build_tree_from_checkout (output)
 
   # Make a tree out of the expected lines
   expected_tree = svn_tree.build_generic_tree (expected_lines)
 
+ # svn_tree.dump_tree(expected_tree)
+ # svn_tree.dump_tree(output_tree)
+
   # Verify actual output against expected output.
   return svn_tree.compare_trees (output_tree, expected_tree)
 
- # TODO: someday inspect the entries file too??
-
-
 
 # A commit to xml, with output verification.
 # Note: don't include the line 'Commit succeeded' in your expected
@@ -68,17 +68,14 @@
   output = svn_test_main.run_svn("ci", "--xml-file", xml_path,
                                  "-r", revision, wc_dir)
 
- # Remove the final output line, return error if it's not 'Commit succeeded'.
- lastline = string.strip(output.pop())
- if lastline != 'Commit succeeded.':
- return 1
-
- # Now verify the actual vs. expected output.
- return svn_output.compare_sets(expected_lines, output,
- svn_output.line_matches_regexp)
+ output_tree = svn_tree.build_tree_from_commit (output)
 
- # TODO: someday inspect the entries file too??
+ # Make a tree out of the expected lines
+ expected_tree = svn_tree.build_generic_tree (expected_lines)
 
+ # Verify actual output against expected output.
+ return svn_tree.compare_trees (output_tree, expected_tree)
+
 
 ######################################################################
 # Tests
@@ -94,8 +91,8 @@
 
   # Generate the expected output lines from a checkout.
   expected_output = []
- for path in svn_test_main.greek_paths:
- item = [ wc_dir + '/' + path,
+ for elem in svn_test_main.greek_tree:
+ item = [ wc_dir + '/' + elem[0],
              None,
              {'status' : 'A '} ]
     expected_output.append(item)
@@ -110,11 +107,13 @@
   wc_dir = 'wc-t2'
   wc_dir2 = 'wc-t2-copy'
 
- # Generate the expected output lines from a checkout (as regexps)
+ # Generate the expected output lines from a checkout
   expected_output = []
- for path in greek_paths:
- line = 'A\s+' + wc_dir + '/' + path
- expected_output.append(line)
+ for elem in svn_test_main.greek_tree:
+ item = [ wc_dir + '/' + elem[0],
+ None,
+ {'status' : 'A '} ]
+ expected_output.append(item)
 
   # Checkout from co1-inline.xml and verify the results.
   result = xml_checkout(wc_dir, XML_DIR + '/co1-inline.xml', expected_output)
@@ -149,10 +148,14 @@
            ### TODO: verify that the output was "" (nothing)
 
   # Commit to xml file (bumping wc to rev. 2), and verify the output.
- commit_expected_output = ['Deleting\s+' + wc_dir + '/A/D/H/omega',
- 'Adding\s+' + wc_dir + '/newfile1',
- 'Changing\s+' + wc_dir + '/A/mu',
- 'Changing\s+' + wc_dir + '/A/D/G/pi']
+ commit_expected_output = [[os.path.join(wc_dir, 'A/D/H/omega'),
+ None, {'verb': 'Deleting'}],
+ [os.path.join(wc_dir, 'newfile1'),
+ None, {'verb': 'Adding'}],
+ [os.path.join(wc_dir, 'A/mu'),
+ None, {'verb': 'Changing'}],
+ [os.path.join(wc_dir, 'A/D/G/pi'),
+ None, {'verb': 'Changing'}]]
 
   result = xml_commit(wc_dir, 'xmltest2-commit.xml', 2, commit_expected_output)
   if result:
@@ -175,13 +178,10 @@
                                   '-r 1', ANCESTOR_PATH)
 
 
- exp_tree = svn_tree.build_tree_from_paths(greek_paths)
+ exp_tree = svn_tree.build_generic_tree(svn_test_main.greek_tree)
   result_tree = svn_tree.build_tree_from_wc(wc_dir)
 
- if svn_tree.compare_trees(exp_tree, result_tree):
- return 0
- else:
- return 1
+ return svn_tree.compare_trees(exp_tree, result_tree)
 
 #----------------------------------------------------------------------------
 
@@ -198,12 +198,9 @@
                                   '-r 1', ANCESTOR_PATH)
 
   exp_tree = svn_tree.build_tree_from_wc(wc_dir)
- result_tree = svn_tree.build_tree_from_entries(wc_dir)
+ result_tree = svn_entry.build_tree_from_entries(wc_dir)
 
- if svn_tree.compare_trees(exp_tree, result_tree):
- return 0
- else:
- return 1
+ return svn_tree.compare_trees(exp_tree, result_tree)
   
 ########################################################################
 ## List all tests here, starting with None:

sam th --- sam_at_uchicago.edu --- http://www.abisource.com/~sam/
OpenPGP Key: CABD33FC --- http://samth.dyndns.org/key
DeCSS: http://samth.dynds.org/decss

  • application/pgp-signature attachment: stored
Received on Sat Oct 21 14:36:29 2006

This is an archived mail posted to the Subversion Dev mailing list.