You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by rh...@apache.org on 2014/02/21 19:34:43 UTC

svn commit: r1570654 - in /subversion/trunk/subversion/tests/cmdline: depth_tests.py diff_tests.py log_tests.py svntest/verify.py

Author: rhuijben
Date: Fri Feb 21 18:34:43 2014
New Revision: 1570654

URL: http://svn.apache.org/r1570654
Log:
In the python tests: move common code to a library file, to avoid having test
files depending on each other (which sometimes causes completely unexected
side effects).

* subversion/tests/cmdline/depth_tests.py
  (diff_in_depthy_wc): Update reference.

* subversion/tests/cmdline/diff_tests.py
  (imports): Add svntest.verify import.
  (is_absolute_url,
   make_diff_header,
   make_no_diff_deleted_header,
   make_git_diff_header,
   make_diff_prop_header,
   make_diff_prop_val,
   make_diff_prop_deleted,
   make_diff_prop_added,
   make_diff_prop_modified): Move to svntest/verify.py

* subversion/tests/cmdline/log_tests.py
  Update import.

* subversion/tests/cmdline/svntest/verify.py
  (is_absolute_url,
   make_diff_header,
   make_no_diff_deleted_header,
   make_git_diff_header,
   make_diff_prop_header,
   make_diff_prop_val,
   make_diff_prop_deleted,
   make_diff_prop_added,
   make_diff_prop_modified): Moved here from ../diff_tests.py.

Modified:
    subversion/trunk/subversion/tests/cmdline/depth_tests.py
    subversion/trunk/subversion/tests/cmdline/diff_tests.py
    subversion/trunk/subversion/tests/cmdline/log_tests.py
    subversion/trunk/subversion/tests/cmdline/svntest/verify.py

Modified: subversion/trunk/subversion/tests/cmdline/depth_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/depth_tests.py?rev=1570654&r1=1570653&r2=1570654&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/depth_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/depth_tests.py Fri Feb 21 18:34:43 2014
@@ -1026,8 +1026,8 @@ def diff_in_depthy_wc(sbox):
   svntest.actions.run_and_verify_svn(None, None, [],
                                      'commit', '-m', '', wc)
 
-  from diff_tests import make_diff_header, make_diff_prop_header
-  from diff_tests import make_diff_prop_deleted, make_diff_prop_added
+  from svntest.verify import make_diff_header, make_diff_prop_header, \
+                             make_diff_prop_deleted, make_diff_prop_added
   diff_mu = make_diff_header('A/mu', 'revision 2', 'working copy') + [
     "@@ -1 +1 @@\n",
     "-new text\n",

Modified: subversion/trunk/subversion/tests/cmdline/diff_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/diff_tests.py?rev=1570654&r1=1570653&r2=1570654&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/diff_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/diff_tests.py Fri Feb 21 18:34:43 2014
@@ -35,6 +35,11 @@ import svntest
 from svntest import err, wc
 
 from prop_tests import binary_mime_type_on_text_file_warning
+from svntest.verify import make_diff_header, make_no_diff_deleted_header, \
+                           make_diff_header, make_no_diff_deleted_header, \
+                           make_git_diff_header, make_diff_prop_header, \
+                           make_diff_prop_val, make_diff_prop_deleted, \
+                           make_diff_prop_added, make_diff_prop_modified
 
 # (abbreviation)
 Skip = svntest.testcase.Skip_deco
@@ -49,183 +54,6 @@ Item = svntest.wc.StateItem
 ######################################################################
 # Generate expected output
 
-def is_absolute_url(target):
-  return (target.startswith('file://')
-          or target.startswith('http://')
-          or target.startswith('https://')
-          or target.startswith('svn://')
-          or target.startswith('svn+ssh://'))
-
-def make_diff_header(path, old_tag, new_tag, src_label=None, dst_label=None):
-  """Generate the expected diff header for file PATH, with its old and new
-  versions described in parentheses by OLD_TAG and NEW_TAG. SRC_LABEL and
-  DST_LABEL are paths or urls that are added to the diff labels if we're
-  diffing against the repository or diffing two arbitrary paths.
-  Return the header as an array of newline-terminated strings."""
-  if src_label:
-    src_label = src_label.replace('\\', '/')
-    if not is_absolute_url(src_label):
-      src_label = '.../' + src_label
-    src_label = '\t(' + src_label + ')'
-  else:
-    src_label = ''
-  if dst_label:
-    dst_label = dst_label.replace('\\', '/')
-    if not is_absolute_url(dst_label):
-      dst_label = '.../' + dst_label
-    dst_label = '\t(' + dst_label + ')'
-  else:
-    dst_label = ''
-  path_as_shown = path.replace('\\', '/')
-  return [
-    "Index: " + path_as_shown + "\n",
-    "===================================================================\n",
-    "--- " + path_as_shown + src_label + "\t(" + old_tag + ")\n",
-    "+++ " + path_as_shown + dst_label + "\t(" + new_tag + ")\n",
-    ]
-
-def make_no_diff_deleted_header(path, old_tag, new_tag):
-  """Generate the expected diff header for a deleted file PATH when in
-  'no-diff-deleted' mode. (In that mode, no further details appear after the
-  header.) Return the header as an array of newline-terminated strings."""
-  path_as_shown = path.replace('\\', '/')
-  return [
-    "Index: " + path_as_shown + " (deleted)\n",
-    "===================================================================\n",
-    ]
-
-def make_git_diff_header(target_path, repos_relpath,
-                         old_tag, new_tag, add=False, src_label=None,
-                         dst_label=None, delete=False, text_changes=True,
-                         cp=False, mv=False, copyfrom_path=None,
-                         copyfrom_rev=None):
-  """ Generate the expected 'git diff' header for file TARGET_PATH.
-  REPOS_RELPATH is the location of the path relative to the repository root.
-  The old and new versions ("revision X", or "working copy") must be
-  specified in OLD_TAG and NEW_TAG.
-  SRC_LABEL and DST_LABEL are paths or urls that are added to the diff
-  labels if we're diffing against the repository. ADD, DELETE, CP and MV
-  denotes the operations performed on the file. COPYFROM_PATH is the source
-  of a copy or move.  Return the header as an array of newline-terminated
-  strings."""
-
-  path_as_shown = target_path.replace('\\', '/')
-  if src_label:
-    src_label = src_label.replace('\\', '/')
-    src_label = '\t(.../' + src_label + ')'
-  else:
-    src_label = ''
-  if dst_label:
-    dst_label = dst_label.replace('\\', '/')
-    dst_label = '\t(.../' + dst_label + ')'
-  else:
-    dst_label = ''
-
-  output = [
-    "Index: " + path_as_shown + "\n",
-    "===================================================================\n"
-  ]
-  if add:
-    output.extend([
-      "diff --git a/" + repos_relpath + " b/" + repos_relpath + "\n",
-      "new file mode 10644\n",
-    ])
-    if text_changes:
-      output.extend([
-        "--- /dev/null\t(" + old_tag + ")\n",
-        "+++ b/" + repos_relpath + dst_label + "\t(" + new_tag + ")\n"
-      ])
-  elif delete:
-    output.extend([
-      "diff --git a/" + repos_relpath + " b/" + repos_relpath + "\n",
-      "deleted file mode 10644\n",
-    ])
-    if text_changes:
-      output.extend([
-        "--- a/" + repos_relpath + src_label + "\t(" + old_tag + ")\n",
-        "+++ /dev/null\t(" + new_tag + ")\n"
-      ])
-  elif cp:
-    if copyfrom_rev:
-      copyfrom_rev = '@' + copyfrom_rev
-    else:
-      copyfrom_rev = ''
-    output.extend([
-      "diff --git a/" + copyfrom_path + " b/" + repos_relpath + "\n",
-      "copy from " + copyfrom_path + copyfrom_rev + "\n",
-      "copy to " + repos_relpath + "\n",
-    ])
-    if text_changes:
-      output.extend([
-        "--- a/" + copyfrom_path + src_label + "\t(" + old_tag + ")\n",
-        "+++ b/" + repos_relpath + "\t(" + new_tag + ")\n"
-      ])
-  elif mv:
-    output.extend([
-      "diff --git a/" + copyfrom_path + " b/" + path_as_shown + "\n",
-      "rename from " + copyfrom_path + "\n",
-      "rename to " + repos_relpath + "\n",
-    ])
-    if text_changes:
-      output.extend([
-        "--- a/" + copyfrom_path + src_label + "\t(" + old_tag + ")\n",
-        "+++ b/" + repos_relpath + "\t(" + new_tag + ")\n"
-      ])
-  else:
-    output.extend([
-      "diff --git a/" + repos_relpath + " b/" + repos_relpath + "\n",
-      "--- a/" + repos_relpath + src_label + "\t(" + old_tag + ")\n",
-      "+++ b/" + repos_relpath + dst_label + "\t(" + new_tag + ")\n",
-    ])
-  return output
-
-def make_diff_prop_header(path):
-  """Return a property diff sub-header, as a list of newline-terminated
-     strings."""
-  return [
-    "\n",
-    "Property changes on: " + path.replace('\\', '/') + "\n",
-    "___________________________________________________________________\n"
-  ]
-
-def make_diff_prop_val(plus_minus, pval):
-  "Return diff for prop value PVAL, with leading PLUS_MINUS (+ or -)."
-  if len(pval) > 0 and pval[-1] != '\n':
-    return [plus_minus + pval + "\n","\\ No newline at end of property\n"]
-  return [plus_minus + pval]
-
-def make_diff_prop_deleted(pname, pval):
-  """Return a property diff for deletion of property PNAME, old value PVAL.
-     PVAL is a single string with no embedded newlines.  Return the result
-     as a list of newline-terminated strings."""
-  return [
-    "Deleted: " + pname + "\n",
-    "## -1 +0,0 ##\n"
-  ] + make_diff_prop_val("-", pval)
-
-def make_diff_prop_added(pname, pval):
-  """Return a property diff for addition of property PNAME, new value PVAL.
-     PVAL is a single string with no embedded newlines.  Return the result
-     as a list of newline-terminated strings."""
-  return [
-    "Added: " + pname + "\n",
-    "## -0,0 +1 ##\n",
-  ] + make_diff_prop_val("+", pval)
-
-def make_diff_prop_modified(pname, pval1, pval2):
-  """Return a property diff for modification of property PNAME, old value
-     PVAL1, new value PVAL2.
-
-     PVAL is a single string with no embedded newlines.  A newline at the
-     end is significant: without it, we add an extra line saying '\ No
-     newline at end of property'.
-
-     Return the result as a list of newline-terminated strings.
-  """
-  return [
-    "Modified: " + pname + "\n",
-    "## -1 +1 ##\n",
-  ] + make_diff_prop_val("-", pval1) + make_diff_prop_val("+", pval2)
 
 ######################################################################
 # Diff output checker

Modified: subversion/trunk/subversion/tests/cmdline/log_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/log_tests.py?rev=1570654&r1=1570653&r2=1570654&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/log_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/log_tests.py Fri Feb 21 18:34:43 2014
@@ -35,7 +35,7 @@ from svntest.main import server_has_merg
 from svntest.main import server_has_auto_move
 from svntest.main import SVN_PROP_MERGEINFO
 from svntest.mergetrees import set_up_branch
-from diff_tests import make_diff_header, make_no_diff_deleted_header
+from svntest.verify import make_diff_header, make_no_diff_deleted_header
 
 # (abbreviation)
 Skip = svntest.testcase.Skip_deco
@@ -718,6 +718,13 @@ def compare_diff_output(expected_diffs, 
   if diffs.issubset(expected_diffs) and diffs.issuperset(expected_diffs):
     return
 
+  print("=============== DIFFS NOT EQUAL ===================")
+  print("Expected")
+  for line in expected_diffs:
+    print(line)
+  print("Actual:")
+  for line in output:
+    print(line)
   raise svntest.Failure("Diffs not equal")
 
 

Modified: subversion/trunk/subversion/tests/cmdline/svntest/verify.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/svntest/verify.py?rev=1570654&r1=1570653&r2=1570654&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/svntest/verify.py (original)
+++ subversion/trunk/subversion/tests/cmdline/svntest/verify.py Fri Feb 21 18:34:43 2014
@@ -650,3 +650,184 @@ def compare_dump_files(message, label, e
     raise svntest.Failure('\n' + '\n'.join(ndiff(
           pprint.pformat(parsed_expected).splitlines(),
           pprint.pformat(parsed_actual).splitlines())))
+
+##########################################################################################
+## diff verifications
+def is_absolute_url(target):
+  return (target.startswith('file://')
+          or target.startswith('http://')
+          or target.startswith('https://')
+          or target.startswith('svn://')
+          or target.startswith('svn+ssh://'))
+
+def make_diff_header(path, old_tag, new_tag, src_label=None, dst_label=None):
+  """Generate the expected diff header for file PATH, with its old and new
+  versions described in parentheses by OLD_TAG and NEW_TAG. SRC_LABEL and
+  DST_LABEL are paths or urls that are added to the diff labels if we're
+  diffing against the repository or diffing two arbitrary paths.
+  Return the header as an array of newline-terminated strings."""
+  if src_label:
+    src_label = src_label.replace('\\', '/')
+    if not is_absolute_url(src_label):
+      src_label = '.../' + src_label
+    src_label = '\t(' + src_label + ')'
+  else:
+    src_label = ''
+  if dst_label:
+    dst_label = dst_label.replace('\\', '/')
+    if not is_absolute_url(dst_label):
+      dst_label = '.../' + dst_label
+    dst_label = '\t(' + dst_label + ')'
+  else:
+    dst_label = ''
+  path_as_shown = path.replace('\\', '/')
+  return [
+    "Index: " + path_as_shown + "\n",
+    "===================================================================\n",
+    "--- " + path_as_shown + src_label + "\t(" + old_tag + ")\n",
+    "+++ " + path_as_shown + dst_label + "\t(" + new_tag + ")\n",
+    ]
+
+def make_no_diff_deleted_header(path, old_tag, new_tag):
+  """Generate the expected diff header for a deleted file PATH when in
+  'no-diff-deleted' mode. (In that mode, no further details appear after the
+  header.) Return the header as an array of newline-terminated strings."""
+  path_as_shown = path.replace('\\', '/')
+  return [
+    "Index: " + path_as_shown + " (deleted)\n",
+    "===================================================================\n",
+    ]
+
+def make_git_diff_header(target_path, repos_relpath,
+                         old_tag, new_tag, add=False, src_label=None,
+                         dst_label=None, delete=False, text_changes=True,
+                         cp=False, mv=False, copyfrom_path=None,
+                         copyfrom_rev=None):
+  """ Generate the expected 'git diff' header for file TARGET_PATH.
+  REPOS_RELPATH is the location of the path relative to the repository root.
+  The old and new versions ("revision X", or "working copy") must be
+  specified in OLD_TAG and NEW_TAG.
+  SRC_LABEL and DST_LABEL are paths or urls that are added to the diff
+  labels if we're diffing against the repository. ADD, DELETE, CP and MV
+  denotes the operations performed on the file. COPYFROM_PATH is the source
+  of a copy or move.  Return the header as an array of newline-terminated
+  strings."""
+
+  path_as_shown = target_path.replace('\\', '/')
+  if src_label:
+    src_label = src_label.replace('\\', '/')
+    src_label = '\t(.../' + src_label + ')'
+  else:
+    src_label = ''
+  if dst_label:
+    dst_label = dst_label.replace('\\', '/')
+    dst_label = '\t(.../' + dst_label + ')'
+  else:
+    dst_label = ''
+
+  output = [
+    "Index: " + path_as_shown + "\n",
+    "===================================================================\n"
+  ]
+  if add:
+    output.extend([
+      "diff --git a/" + repos_relpath + " b/" + repos_relpath + "\n",
+      "new file mode 10644\n",
+    ])
+    if text_changes:
+      output.extend([
+        "--- /dev/null\t(" + old_tag + ")\n",
+        "+++ b/" + repos_relpath + dst_label + "\t(" + new_tag + ")\n"
+      ])
+  elif delete:
+    output.extend([
+      "diff --git a/" + repos_relpath + " b/" + repos_relpath + "\n",
+      "deleted file mode 10644\n",
+    ])
+    if text_changes:
+      output.extend([
+        "--- a/" + repos_relpath + src_label + "\t(" + old_tag + ")\n",
+        "+++ /dev/null\t(" + new_tag + ")\n"
+      ])
+  elif cp:
+    if copyfrom_rev:
+      copyfrom_rev = '@' + copyfrom_rev
+    else:
+      copyfrom_rev = ''
+    output.extend([
+      "diff --git a/" + copyfrom_path + " b/" + repos_relpath + "\n",
+      "copy from " + copyfrom_path + copyfrom_rev + "\n",
+      "copy to " + repos_relpath + "\n",
+    ])
+    if text_changes:
+      output.extend([
+        "--- a/" + copyfrom_path + src_label + "\t(" + old_tag + ")\n",
+        "+++ b/" + repos_relpath + "\t(" + new_tag + ")\n"
+      ])
+  elif mv:
+    output.extend([
+      "diff --git a/" + copyfrom_path + " b/" + path_as_shown + "\n",
+      "rename from " + copyfrom_path + "\n",
+      "rename to " + repos_relpath + "\n",
+    ])
+    if text_changes:
+      output.extend([
+        "--- a/" + copyfrom_path + src_label + "\t(" + old_tag + ")\n",
+        "+++ b/" + repos_relpath + "\t(" + new_tag + ")\n"
+      ])
+  else:
+    output.extend([
+      "diff --git a/" + repos_relpath + " b/" + repos_relpath + "\n",
+      "--- a/" + repos_relpath + src_label + "\t(" + old_tag + ")\n",
+      "+++ b/" + repos_relpath + dst_label + "\t(" + new_tag + ")\n",
+    ])
+  return output
+
+def make_diff_prop_header(path):
+  """Return a property diff sub-header, as a list of newline-terminated
+     strings."""
+  return [
+    "\n",
+    "Property changes on: " + path.replace('\\', '/') + "\n",
+    "___________________________________________________________________\n"
+  ]
+
+def make_diff_prop_val(plus_minus, pval):
+  "Return diff for prop value PVAL, with leading PLUS_MINUS (+ or -)."
+  if len(pval) > 0 and pval[-1] != '\n':
+    return [plus_minus + pval + "\n","\\ No newline at end of property\n"]
+  return [plus_minus + pval]
+
+def make_diff_prop_deleted(pname, pval):
+  """Return a property diff for deletion of property PNAME, old value PVAL.
+     PVAL is a single string with no embedded newlines.  Return the result
+     as a list of newline-terminated strings."""
+  return [
+    "Deleted: " + pname + "\n",
+    "## -1 +0,0 ##\n"
+  ] + make_diff_prop_val("-", pval)
+
+def make_diff_prop_added(pname, pval):
+  """Return a property diff for addition of property PNAME, new value PVAL.
+     PVAL is a single string with no embedded newlines.  Return the result
+     as a list of newline-terminated strings."""
+  return [
+    "Added: " + pname + "\n",
+    "## -0,0 +1 ##\n",
+  ] + make_diff_prop_val("+", pval)
+
+def make_diff_prop_modified(pname, pval1, pval2):
+  """Return a property diff for modification of property PNAME, old value
+     PVAL1, new value PVAL2.
+
+     PVAL is a single string with no embedded newlines.  A newline at the
+     end is significant: without it, we add an extra line saying '\ No
+     newline at end of property'.
+
+     Return the result as a list of newline-terminated strings.
+  """
+  return [
+    "Modified: " + pname + "\n",
+    "## -1 +1 ##\n",
+  ] + make_diff_prop_val("-", pval1) + make_diff_prop_val("+", pval2)
+