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

Re: [PATCH] Factorise 'svn lock' validation code

From: Madan U Sreenivasan <madan_at_collab.net>
Date: 2006-05-24 13:37:30 CEST

On Wed, 24 May 2006 14:46:42 +0530, Peter N. Lundblad
<peter@famlundblad.se> wrote:

> Madan U Sreenivasan writes:
[snip]
> > + lock_info = output[-6:-1]
>
> While here, we could as well make this not break if we add more fields
> to the info output in the future. I think we should search for the
> specific
> fields, which is much easier with this refactorization.

Aye! Aye! captain!, pl. find the patch attached. :)

[[[
Factorize out code for locking a path and validating
the contents of the lock.

Suggested by: djames
Review by: lundblad

* subversion/tests/cmdline/svntest/actions.py
   (run_and_validate_lock): New function to lock a path, and
    validate the contents of the lock.

* subversion/tests/cmdline/lock_tests.py
   (examine_lock, examine_lock_via_url, examine_lock_encoded_recurse):
    Modified to use svntest.actions.run_and_validate_lock().
]]]

Regards,
Madan.

Index: subversion/tests/cmdline/lock_tests.py
===================================================================
--- subversion/tests/cmdline/lock_tests.py (revision 19800)
+++ subversion/tests/cmdline/lock_tests.py (working copy)
@@ -301,24 +301,10 @@
   file_path = os.path.join(sbox.wc_dir, fname)
 
   # lock a file as wc_author
- svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock',
- '--username', svntest.main.wc_author,
- '--password', svntest.main.wc_passwd,
- '-m', comment, file_path)
+ svntest.actions.run_and_validate_lock(file_path,
+ svntest.main.wc_author,
+ svntest.main.wc_passwd)
 
- output, err = svntest.actions.run_and_verify_svn(None, None, [],
- 'info', file_path)
-
- lock_info = output[-6:-1]
- if ((len(lock_info) != 5)
- or (not lock_info[0].startswith('Lock Token: opaquelocktoken:'))
- or (lock_info[1] != 'Lock Owner: %s\n' % svntest.main.wc_author)
- or (not lock_info[2].startswith('Lock Created:'))
- or (lock_info[4] != '%s\n' % comment)):
- raise svntest.Failure
-
-
-
 #----------------------------------------------------------------------
 # II.C.1: Lock a file in wc A. Check out wc B. Break the lock in wc
 # B. Verify that wc A gracefully cleans up the lock via update as
@@ -891,22 +877,11 @@
   file_path = os.path.join(sbox.wc_dir, fname)
   file_url = svntest.main.current_repo_url + '/' + fname
 
- # lock a file as wc_author
- svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock',
- '--username', svntest.main.wc_author2,
- '--password', svntest.main.wc_passwd,
- '--no-auth-cache',
- '-m', comment, file_path)
+ # lock the file url and check the contents of lock
+ svntest.actions.run_and_validate_lock(file_url,
+ svntest.main.wc_author2,
+ svntest.main.wc_passwd)
 
- output, err = svntest.actions.run_and_verify_svn(None, None, [], 'info',
- file_url)
-
- match_line = 'Lock Owner: ' + svntest.main.wc_author2 + '\n'
-
- if not match_line in output:
- print "Error: expected output '%s' not found in output." % match_line
- raise svntest.Failure
-
 #----------------------------------------------------------------------
 def lock_several_files(sbox):
   "lock/unlock several files in one go"
@@ -1520,7 +1495,6 @@
   wc_dir = sbox.wc_dir
 
   fname = 'A/B/F/one iota'
- comment = 'This is a lock test.'
   file_path = os.path.join(sbox.wc_dir, fname)
 
   svntest.main.file_append(file_path, "This represents a binary file\n")
@@ -1542,29 +1516,12 @@
                                         None, None,
                                         file_path)
 
- # lock the file
- svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock',
- '--username', svntest.main.wc_author,
- '--password', svntest.main.wc_passwd,
- '-m', comment, file_path)
+ # lock the file and validate the contents
+ svntest.actions.run_and_validate_lock(file_path,
+ svntest.main.wc_author,
+ svntest.main.wc_passwd)
 
- # Run info and check that we get the lock fields.
- output, err = \
- svntest.actions.run_and_verify_svn(None, None, [],
- 'info', '-R',
- svntest.main.current_repo_url +
- '/A/B/F')
 
- lock_info = output[-6:-1]
- if ((len(lock_info) != 5)
- or (not lock_info[0].startswith('Lock Token: opaquelocktoken:'))
- or (lock_info[1] != 'Lock Owner: %s\n' % svntest.main.wc_author)
- or (not lock_info[2].startswith('Lock Created:'))
- or (lock_info[4] != '%s\n' % comment)):
- raise svntest.Failure
-
-
-
 ########################################################################
 # Run the tests
 
Index: subversion/tests/cmdline/svntest/actions.py
===================================================================
--- subversion/tests/cmdline/svntest/actions.py (revision 19800)
+++ subversion/tests/cmdline/svntest/actions.py (working copy)
@@ -761,7 +761,38 @@
     display_trees(None, 'DIFF OUTPUT TREE', output_tree, mytree)
     raise
 
+def run_and_validate_lock(path, username, password):
+ """`svn lock' the given path and validate the contents of the lock.
+ Use the given username. This is important because locks are
+ user specific."""
 
+ comment = "Locking path:%s." % path
+
+ # lock the path
+ run_and_verify_svn(None, ".*locked by user", [], 'lock',
+ '--username', username,
+ '--password', password,
+ '-m', comment, path)
+
+ # Run info and check that we get the lock fields.
+ output, err = run_and_verify_svn(None, None, [],
+ 'info','-R',
+ path)
+
+ # prepare the regexs to compare against
+ token_re = re.compile (".*?Lock Token: opaquelocktoken:.*?", re.DOTALL)
+ author_re = re.compile (".*?Lock Owner: %s\n.*?" % username, re.DOTALL)
+ created_re = re.compile (".*?Lock Created:.*?", re.DOTALL)
+ comment_re = re.compile (".*?%s\n.*?" % comment, re.DOTALL)
+ # join all output lines into one
+ output = "".join(output)
+ # Fail even if one regex does not match
+ if ( not (token_re.match(output) and \
+ author_re.match(output) and \
+ created_re.match(output) and \
+ comment_re.match(output))):
+ raise Failure
+
 ######################################################################
 # Displaying expected and actual output
 

Factorize out code for locking a path and validating
the contents of the lock.

Suggested by: djames
Review by: lundblad

* subversion/tests/cmdline/svntest/actions.py
  (run_and_validate_lock): New function to lock a path, and
   validate the contents of the lock.

* subversion/tests/cmdline/lock_tests.py
  (examine_lock, examine_lock_via_url, examine_lock_encoded_recurse):
   Modified to use svntest.actions.run_and_validate_lock().

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed May 24 13:07:08 2006

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

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.