subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stef...@apache.org
Subject svn commit: r1743034 - in /subversion/trunk: build/run_tests.py subversion/tests/cmdline/svntest/main.py subversion/tests/cmdline/svntest/testcase.py subversion/tests/cmdline/svntest/tree.py subversion/tests/cmdline/svntest/wc.py
Date Mon, 09 May 2016 19:14:52 GMT
Author: stefan2
Date: Mon May  9 19:14:52 2016
New Revision: 1743034

URL: http://svn.apache.org/viewvc?rev=1743034&view=rev
Log:
Get the build and test harness to execute the tests with Python 3.
Most tests are still failing, though, and the log summary fails.

* build/run_tests.py
  (TestHarness.run): We treat the test job output as binary to be able
                     to log it as-is.

* subversion/tests/cmdline/svntest/main.py
  (ensure_list): New utility function that allows us to automatically
                 convert iterators to list objects.
  (filter_dbg): Be sure to return a list despite getting an iterator
                from the Python 3 filter.
  (wait_on_pipe): Convert non-binary sub-process output into lists of
                  strings.
  (file_write): Move up and add string conversion logic for Python 3
                where we have to feed the file either byte arrays or
                unicode strings depending on the file open mode.
  (file_append,
   file_append_binary): Call file_write to handle the string conversion
                        issues.

* subversion/tests/cmdline/svntest/testcase.py
  (FunctionTestCase.__init__,
   FunctionTestCase.get_function_name,
   FunctionTestCase.get_sandbox_name): Use the Python 3 element names
                                       to access its internal data model.

* subversion/tests/cmdline/svntest/tree.py
  (_dump_tree): For correct sorting in py3, we would need to implement
                a handful of operators for SVNTreeNode.  Explicitly using
                the printable path here is the less intrusive portable
                solution.

* subversion/tests/cmdline/svntest/wc.py
  (State.rename): Lambda expressions take an unpacked tuple object in py3.

Modified:
    subversion/trunk/build/run_tests.py
    subversion/trunk/subversion/tests/cmdline/svntest/main.py
    subversion/trunk/subversion/tests/cmdline/svntest/testcase.py
    subversion/trunk/subversion/tests/cmdline/svntest/tree.py
    subversion/trunk/subversion/tests/cmdline/svntest/wc.py

Modified: subversion/trunk/build/run_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/build/run_tests.py?rev=1743034&r1=1743033&r2=1743034&view=diff
==============================================================================
--- subversion/trunk/build/run_tests.py (original)
+++ subversion/trunk/build/run_tests.py Mon May  9 19:14:52 2016
@@ -518,7 +518,7 @@ class TestHarness:
   def run(self, testlist):
     '''Run all test programs given in TESTLIST. Print a summary of results, if
        there is a log file. Return zero iff all test programs passed.'''
-    self._open_log('w')
+    self._open_log('wb')
     failed = 0
 
     # Filter tests into Python and native groups and prepare arguments

Modified: subversion/trunk/subversion/tests/cmdline/svntest/main.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/svntest/main.py?rev=1743034&r1=1743033&r2=1743034&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/svntest/main.py (original)
+++ subversion/trunk/subversion/tests/cmdline/svntest/main.py Mon May  9 19:14:52 2016
@@ -37,6 +37,7 @@ import urllib
 import logging
 import hashlib
 import zipfile
+import codecs
 
 try:
   # Python >=3.0
@@ -374,11 +375,18 @@ def get_fsfs_format_file_path(repo_dir):
 
   return os.path.join(repo_dir, "db", "format")
 
+def ensure_list(item):
+  "If ITEM is not already a list, convert it to a list."
+  if isinstance(item, list):
+    return item
+  else:
+    return list(item)
+
 def filter_dbg(lines):
   excluded = filter(lambda line: line.startswith('DBG:'), lines)
   included = filter(lambda line: not line.startswith('DBG:'), lines)
   sys.stdout.write(''.join(excluded))
-  return included
+  return ensure_list(included)
 
 # Run any binary, logging the command line and return code
 def run_command(command, error_expected, binary_mode=False, *varargs):
@@ -461,10 +469,17 @@ def wait_on_pipe(waiter, binary_mode, st
   stdout, stderr = kid.communicate(stdin)
   exit_code = kid.returncode
 
-  # Normalize Windows line endings if in text mode.
-  if windows and not binary_mode:
-    stdout = stdout.replace('\r\n', '\n')
-    stderr = stderr.replace('\r\n', '\n')
+  # We always expect STDERR to be strings, not byte-arrays.
+  if not isinstance(stderr, str):
+    stderr = stderr.decode("utf-8")
+  if not binary_mode:
+    if not isinstance(stdout, str):
+      stdout = stdout.decode("utf-8")
+
+    # Normalize Windows line endings if in text mode.
+    if windows:
+      stdout = stdout.replace('\r\n', '\n')
+      stderr = stderr.replace('\r\n', '\n')
 
   # Convert output strings to lists.
   stdout_lines = stdout.splitlines(True)
@@ -937,21 +952,37 @@ def safe_rmtree(dirname, retry=0):
   else:
     rmtree(dirname)
 
+# For creating new files, and making local mods to existing files.
+def file_write(path, contents, mode='w'):
+  """Write the CONTENTS to the file at PATH, opening file using MODE,
+  which is (w)rite by default."""
+
+  if sys.version_info < (3, 0):
+    open(path, mode).write(contents)
+  else:
+    # Python 3:  Write data in the format required by MODE, i.e. byte arrays
+    #            to 'b' files, utf-8 otherwise."""
+    if 'b' in mode:
+      if isinstance(contents, str):
+        contents = contents.encode()
+    else:
+      if not isinstance(contents, str):
+        contents = contents.decode("utf-8")
+
+    if isinstance(contents, str):
+      codecs.open(path, mode, "utf-8").write(contents)
+    else:
+      open(path, mode).write(contents)
+
 # For making local mods to files
 def file_append(path, new_text):
   "Append NEW_TEXT to file at PATH"
-  open(path, 'a').write(new_text)
+  file_write(path, new_text, 'a')
 
 # Append in binary mode
 def file_append_binary(path, new_text):
   "Append NEW_TEXT to file at PATH in binary mode"
-  open(path, 'ab').write(new_text)
-
-# For creating new files, and making local mods to existing files.
-def file_write(path, contents, mode='w'):
-  """Write the CONTENTS to the file at PATH, opening file using MODE,
-  which is (w)rite by default."""
-  open(path, mode).write(contents)
+  file_write(path, new_text, 'ab')
 
 # For replacing parts of contents in an existing file, with new content.
 def file_substitute(path, contents, new_contents):

Modified: subversion/trunk/subversion/tests/cmdline/svntest/testcase.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/svntest/testcase.py?rev=1743034&r1=1743033&r2=1743034&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/svntest/testcase.py (original)
+++ subversion/trunk/subversion/tests/cmdline/svntest/testcase.py Mon May  9 19:14:52 2016
@@ -141,9 +141,9 @@ class FunctionTestCase(TestCase):
     # docstring on it.
     assert isinstance(func, types.FunctionType)
 
-    name = func.func_name
+    name = func.__name__
 
-    assert func.func_code.co_argcount == 1, \
+    assert func.__code__.co_argcount == 1, \
         '%s must take an sbox argument' % name
 
     doc = func.__doc__.strip()
@@ -165,13 +165,13 @@ class FunctionTestCase(TestCase):
     self.skip_cross_check = skip_cross_check
 
   def get_function_name(self):
-    return self.func.func_name
+    return self.func.__name__
 
   def get_sandbox_name(self):
     """Base the sandbox's name on the name of the file in which the
     function was defined."""
 
-    filename = self.func.func_code.co_filename
+    filename = self.func.__code__.co_filename
     return os.path.splitext(os.path.basename(filename))[0]
 
   def run(self, sandbox):

Modified: subversion/trunk/subversion/tests/cmdline/svntest/tree.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/svntest/tree.py?rev=1743034&r1=1743033&r2=1743034&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/svntest/tree.py (original)
+++ subversion/trunk/subversion/tests/cmdline/svntest/tree.py Mon May  9 19:14:52 2016
@@ -715,7 +715,7 @@ def _dump_tree(n,indent="",stream=sys.st
   the SVNTreeNode N. Prefix each line with the string INDENT."""
 
   # Code partially stolen from Dave Beazley
-  tmp_children = sorted(n.children or [])
+  tmp_children = sorted(n.children or [], key=SVNTreeNode.get_printable_path)
 
   if n.name == root_node_name:
     stream.write("%s%s\n" % (indent, "ROOT"))

Modified: subversion/trunk/subversion/tests/cmdline/svntest/wc.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/svntest/wc.py?rev=1743034&r1=1743033&r2=1743034&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/svntest/wc.py (original)
+++ subversion/trunk/subversion/tests/cmdline/svntest/wc.py Mon May  9 19:14:52 2016
@@ -226,13 +226,13 @@ class State:
 
     """
     temp = {}
-    for src, dst in sorted(moves.items(), key=lambda (src, dst): src)[::-1]:
+    for src, dst in sorted(moves.items(), key=lambda pair: pair[0])[::-1]:
       temp[src] = {}
       for path, item in self.desc.items():
         if path == src or path[:len(src) + 1] == src + '/':
           temp[src][path] = item;
           del self.desc[path]
-    for src, dst in sorted(moves.items(), key=lambda (src, dst): dst):
+    for src, dst in sorted(moves.items(), key=lambda pair: pair[1]):
       for path, item in temp[src].items():
         if path == src:
           new_path = dst
@@ -274,7 +274,7 @@ class State:
           os.makedirs(dirpath)
 
         # write out the file contents now
-        open(fullpath, 'wb').write(item.contents)
+        svntest.main.file_write(fullpath, item.contents, 'wb')
 
   def normalize(self):
     """Return a "normalized" version of self.



Mime
View raw message