Author: hwright
Date: Thu Jan 12 21:41:23 2012
New Revision: 1230798
URL: http://svn.apache.org/viewvc?rev=1230798&view=rev
Log:
Parse diff output in 'svn log' in an ordering-independent manner. If needed,
this could probably be generalized in diff_tests.py.
* subversion/tests/cmdline/log_tests.py
(parse_diff, setify, compare_diff_output): New.
(log_diff): Tweak the expectation format, and use the new comparison method.
Modified:
subversion/trunk/subversion/tests/cmdline/log_tests.py
Modified: subversion/trunk/subversion/tests/cmdline/log_tests.py
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/log_tests.py?rev=1230798&r1=1230797&r2=1230798&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/log_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/log_tests.py Thu Jan 12 21:41:23
2012
@@ -697,6 +697,42 @@ def check_log_chain(chain, revlist, path
missing_revs, chain)
+def parse_diff(output):
+ """Return a set containing the various diff bits, broken up by file."""
+
+ diff_set = []
+ current_diff = []
+ for line in output:
+ if line.startswith('Index: ') and current_diff:
+ diff_set.append(current_diff)
+ current_diff = []
+ current_diff.append(line)
+ diff_set.append(current_diff)
+
+ return diff_set
+
+
+def setify(diff_list):
+ """Take a list of lists and make it a set of tuples."""
+ s = set()
+ for diff in diff_list:
+ s.add(tuple(diff))
+ return s
+
+
+def compare_diff_output(expected_diffs, output):
+ """Compare the diffs in EXPECTED_DIFFS (which is a Python set) with the
+ text in OUTPUT, remembering that there is no canonical ordering for diffs."""
+
+ diffs = parse_diff(output)
+ diffs = setify(diffs)
+ expected_diffs = setify(expected_diffs)
+
+ if diffs.issubset(expected_diffs) and diffs.issuperset(expected_diffs):
+ return
+
+ raise svntest.Failure("Diffs not equal")
+
######################################################################
# Tests
@@ -2146,25 +2182,25 @@ def log_diff(sbox):
'-r10:8', 'A2')
os.chdir(was_cwd)
- r9diff = make_no_diff_deleted_header('A2/B/E/alpha', 8, 9) \
- + make_diff_header('A2/B/E/beta', 'revision 8', 'revision 9') \
- + [ "@@ -1 +1,2 @@\n",
- " This is the file 'beta'.\n",
- "+9\n",
- "\ No newline at end of file\n",
- ]
- r8diff = make_diff_header('A2/D/G/rho', 'revision 0', 'revision 8') \
- + [ "@@ -0,0 +1 @@\n",
- "+88\n",
- "\ No newline at end of file\n",
- ]
+ r9diff = [ make_no_diff_deleted_header('A2/B/E/alpha', 8, 9),
+ make_diff_header('A2/B/E/beta', 'revision 8', 'revision 9')
+ + [ "@@ -1 +1,2 @@\n",
+ " This is the file 'beta'.\n",
+ "+9\n",
+ "\ No newline at end of file\n",
+ ]
+ ]
+ r8diff = [ make_diff_header('A2/D/G/rho', 'revision 0', 'revision 8')
+ + [ "@@ -0,0 +1 @@\n",
+ "+88\n",
+ "\ No newline at end of file\n",
+ ]
+ ]
log_chain = parse_log_output(output, with_diffs=True)
if len(log_chain) != 3:
raise SVNLogParseError("%d logs found, 3 expected" % len(log_chain))
- svntest.verify.compare_and_display_lines(None, "diff for r9",
- r9diff, log_chain[1]['diff_lines'])
- svntest.verify.compare_and_display_lines(None, "diff for r8",
- r8diff, log_chain[2]['diff_lines'])
+ compare_diff_output(r9diff, log_chain[1]['diff_lines'])
+ compare_diff_output(r8diff, log_chain[2]['diff_lines'])
########################################################################