On 12/27/18 1:01 PM, Troy Curtis wrote:
 > The only real functionality changes I'm concerned with on the changes are dropping 
str() conversion on a couple of the API inputs since previously providing any object with a 
suitable __str__ method would work, but would now be broken. But a simple way of supporting 
Py2 and Py3 isn't a "gimme", so didn't want to block this patch on that.

I see. So I've revise it and str/bytes conversion in unit tests as a first
step of followup to r1849784.

[in subversion/bindings/swig/python/tests]

* client.py (SubversionClientTestCase.test_update4): not to encode
 os.path.sep if it is already bytes object

* core.py (SubversionCoreTestCase.test_stream_write): not to encode
 fname if it is already bytes object

* delta.py (DeltaTestCase.testTxWindowHandler_stream_IF,
 DeltaTestCase.testTxWindowHandler_Stream_IF): not to encode fname if it
 is already bytes object

* fs.py (SubversionFSTestCase.setUp): not to encode self.tmpfile if it
 is already bytes object

* trac/versioncontrol/main.py (Node.__init__): revise change to strip
 str() on r1849784; if path is already bytes, use it for self.path.
 othewise ensure self.path is str, and if it is not bytes (i.e. in case
 of py3), encode it to bytes

* trac/versioncontrol/svn_fs.py (SubversionNode.__init__): don't use
 IS_PY3 condition, just store a unicode string in the exception object.
 - remove unnecessary variable IS_PY3 and therefore unnecessary import
  of sys module
 - (SubversionNode.getproperties): revise change to strip str() on
  r1849784; if value is already bytes, use it for prop[name].  othewise
  ensure value is str, and if it is not bytes (i.e. in case of py3),
  encode it to bytes for consistency of the type of prop[name]

* utils.py (Temper.alloc_empty_dir, Temper.alloc_empty_repo): ensure
 suffix arg for tempfile.mkdtemp() is unicode (for py3 < 3.5)

Cheers,
--
Yasuhito FUTATSUKI
commit fd0908a0c0b58f63a8133809ea70d46d38d600a6
Author: FUTATSUKI Yasuhito <futat...@yf.bsdclub.org>
Date:   Fri Dec 28 00:42:55 2018 +0900

    On branch swig-py3: revise encode/decode usage in swig-py unit test
    
    [in subversion/bindings/swig/python/tests]
    
    * client.py (SubversionClientTestCase.test_update4): not to encode 
os.path.sep
      if it is already bytes object
    
    * core.py (SubversionCoreTestCase.test_stream_write): not to encode fname
      if it is already bytes object
    
    * delta.py (DeltaTestCase.testTxWindowHandler_stream_IF,
      DeltaTestCase.testTxWindowHandler_Stream_IF): not to encode fname if it
      is already bytes object
    
    * fs.py (SubversionFSTestCase.setUp): not to encode self.tmpfile if it is
      already bytes object
    
    * trac/versioncontrol/main.py (Node.__init__): revise change to strip str()
      on r1849784; if path is already bytes, use it for self.path. othewise 
ensure
      self.path is str, and if it is not bytes (i.e. in case of py3), encode it
      to bytes
    
    * trac/versioncontrol/svn_fs.py (SubversionNode.__init__): don't use
      IS_PY3 condition, just store a unicode string in the exception object.
     - remove unnecessary variable IS_PY3 and therefore unnecessary import of
       sys module
     - (SubversionNode.getproperties): revise change to strip str() on r1849784;
       if value is already bytes, use it for prop[name].  othewise ensure value
       is str, and if it is not bytes (i.e. in case of py3), encode it to bytes
       for consistency of the type of prop[name]
    
    * utils.py (Temper.alloc_empty_dir, Temper.alloc_empty_repo): ensure suffix
      arg for tempfile.mkdtemp() is unicode (for py3 < 3.5)

diff --git a/subversion/bindings/swig/python/tests/client.py 
b/subversion/bindings/swig/python/tests/client.py
index 9d21704429..88f7fcf5e4 100644
--- a/subversion/bindings/swig/python/tests/client.py
+++ b/subversion/bindings/swig/python/tests/client.py
@@ -459,6 +459,9 @@ class SubversionClientTestCase(unittest.TestCase):
     def notify_func(path, action, kind, mime_type, content_state, prop_state, 
rev):
         self.notified_paths.append(path)
 
+    PATH_SEPARATOR = os.path.sep
+    if not isinstance(PATH_SEPARATOR, bytes):
+        PATH_SEPARATOR = PATH_SEPARATOR.encode('UTF-8')
     self.client_ctx.notify_func = client.svn_swig_py_notify_func
     self.client_ctx.notify_baton = notify_func
     rev.value.number = 1
@@ -475,7 +478,7 @@ class SubversionClientTestCase(unittest.TestCase):
     ]
     # All normal subversion apis process paths in Subversion's canonical 
format,
     # which isn't the platform specific format
-    expected_paths = [x.replace(os.path.sep.encode('UTF-8'), b'/') for x in 
expected_paths]
+    expected_paths = [x.replace(PATH_SEPARATOR, b'/') for x in expected_paths]
     self.notified_paths.sort()
     expected_paths.sort()
 
@@ -495,7 +498,7 @@ class SubversionClientTestCase(unittest.TestCase):
         path,
         path
     ]
-    expected_paths = [x.replace(os.path.sep.encode('UTF-8'), b'/') for x in 
expected_paths]
+    expected_paths = [x.replace(PATH_SEPARATOR, b'/') for x in expected_paths]
     client.update4((path,), rev, core.svn_depth_unknown, True, False, False,
                    False, False, self.client_ctx)
     self.notified_paths.sort()
diff --git a/subversion/bindings/swig/python/tests/core.py 
b/subversion/bindings/swig/python/tests/core.py
index f7e4eff26f..6370fa5e1e 100644
--- a/subversion/bindings/swig/python/tests/core.py
+++ b/subversion/bindings/swig/python/tests/core.py
@@ -234,9 +234,10 @@ class SubversionCoreTestCase(unittest.TestCase):
     out_str = o1_str + o2_str + o3_str
     rewrite_str = b'Subversion'
     fd, fname = tempfile.mkstemp()
+    fname_bytes = fname if isinstance(fname, bytes) else fname.encode('UTF-8')
     os.close(fd)
     try:
-      stream = svn.core.svn_stream_from_aprfile2(fname.encode('UTF-8'), False)
+      stream = svn.core.svn_stream_from_aprfile2(fname_bytes, False)
       self.assertEqual(svn.core.svn_stream_write(stream, out_str),
                        len(out_str))
       svn.core.svn_stream_seek(stream, None)
diff --git a/subversion/bindings/swig/python/tests/delta.py 
b/subversion/bindings/swig/python/tests/delta.py
index 690ade5da5..f668c32488 100644
--- a/subversion/bindings/swig/python/tests/delta.py
+++ b/subversion/bindings/swig/python/tests/delta.py
@@ -52,10 +52,10 @@ class DeltaTestCase(unittest.TestCase):
     content_str = b"bye world"
     content_stream = svn.core.svn_stream_from_stringbuf(content_str)
     fd, fname = tempfile.mkstemp()
+    fname_bytes = fname if isinstance(fname, bytes) else fname.encode('UTF-8')
     os.close(fd)
     try:
-      target_stream = svn.core.svn_stream_from_aprfile2(fname.encode('UTF-8'),
-                                                        False)
+      target_stream = svn.core.svn_stream_from_aprfile2(fname_bytes, False)
       window_handler, baton = \
           svn.delta.tx_apply(src_stream, target_stream, None)
       svn.delta.tx_send_stream(content_stream, window_handler, baton, pool)
@@ -80,11 +80,11 @@ class DeltaTestCase(unittest.TestCase):
     content_stream = svn.core.Stream(
                     svn.core.svn_stream_from_stringbuf(content_str))
     fd, fname = tempfile.mkstemp()
+    fname_bytes = fname if isinstance(fname, bytes) else fname.encode('UTF-8')
     os.close(fd)
     try:
       target_stream = svn.core.Stream(
-                    svn.core.svn_stream_from_aprfile2(fname.encode('UTF-8'),
-                                                      False))
+                    svn.core.svn_stream_from_aprfile2(fname_bytes, False))
       window_handler, baton = \
           svn.delta.tx_apply(src_stream, target_stream, None)
       svn.delta.tx_send_stream(content_stream, window_handler, baton, None)
diff --git a/subversion/bindings/swig/python/tests/fs.py 
b/subversion/bindings/swig/python/tests/fs.py
index 8cadce6c63..18ec8ce9ef 100644
--- a/subversion/bindings/swig/python/tests/fs.py
+++ b/subversion/bindings/swig/python/tests/fs.py
@@ -68,8 +68,12 @@ class SubversionFSTestCase(unittest.TestCase):
 
     clientctx.auth_baton = core.svn_auth_open(providers)
 
-    commitinfo = client.import2(self.tmpfile.encode('UTF-8'),
-                                urljoin(self.repos_uri + b"/", 
b"trunk/UniTest.txt"),
+    if isinstance(self.tmpfile, bytes):
+        tmpfile_bytes = self.tmpfile
+    else:
+        tmpfile_bytes = self.tmpfile.encode('UTF-8')
+    commitinfo = client.import2(tmpfile_bytes,
+                                urljoin(self.repos_uri + 
b"/",b"trunk/UniTest.txt"),
                                 True, True,
                                 clientctx)
 
diff --git a/subversion/bindings/swig/python/tests/trac/versioncontrol/main.py 
b/subversion/bindings/swig/python/tests/trac/versioncontrol/main.py
index 0d5d0618de..37faf55962 100644
--- a/subversion/bindings/swig/python/tests/trac/versioncontrol/main.py
+++ b/subversion/bindings/swig/python/tests/trac/versioncontrol/main.py
@@ -159,7 +159,16 @@ class Node(object):
 
     def __init__(self, path, rev, kind):
         assert kind in (Node.DIRECTORY, Node.FILE), "Unknown node kind %s" % 
kind
-        self.path = path
+        if isinstance(path, bytes):
+            self.path = path
+        else:
+            self.path = str(path)
+            # we want a bytes object for self.path, however str(path) might
+            # already be UTF-8 encoded bytes object on py2. In those case,
+            # encoding them with 'UTF-8' codecs causes UnicodeDecodeError.
+            # So we exclude such cases.
+            if not isinsntance(self.path, bytes):
+                self.path = self.path.encode('UTF-8')
         self.rev = rev
         self.kind = kind
 
diff --git 
a/subversion/bindings/swig/python/tests/trac/versioncontrol/svn_fs.py 
b/subversion/bindings/swig/python/tests/trac/versioncontrol/svn_fs.py
index fe92bb70b7..698958a03c 100644
--- a/subversion/bindings/swig/python/tests/trac/versioncontrol/svn_fs.py
+++ b/subversion/bindings/swig/python/tests/trac/versioncontrol/svn_fs.py
@@ -55,12 +55,9 @@ import os.path
 import time
 import weakref
 import posixpath
-import sys
 
 from svn import fs, repos, core, delta
 
-IS_PY3 = sys.version_info[0] >= 3
-
 _kindmap = {core.svn_node_dir: Node.DIRECTORY,
             core.svn_node_file: Node.FILE}
 
@@ -303,11 +300,8 @@ class SubversionNode(Node):
         self.root = fs.revision_root(fs_ptr, rev)
         node_type = fs.check_path(self.root, self.scoped_path)
         if not node_type in _kindmap:
-            if IS_PY3:
-                raise TracError("No node at %s in revision %s"
-                                % (path.decode('UTF-8'), rev))
-            else:
-                raise TracError("No node at %s in revision %s" % (path, rev))
+            raise TracError("No node at %s in revision %s"
+                            % (path.decode('UTF-8'), rev))
         self.created_rev = fs.node_created_rev(self.root, self.scoped_path)
         self.created_path = fs.node_created_path(self.root, self.scoped_path)
         # Note: 'created_path' differs from 'path' if the last change was a 
copy,
@@ -357,7 +351,11 @@ class SubversionNode(Node):
     def get_properties(self):
         props = fs.node_proplist(self.root, self.scoped_path)
         for name,value in core._as_list(props.items()):
-            props[name] = value
+            if isinstance(value, bytes):
+                props[name] = value
+            else:
+                # Make sure the value is a proper string
+                props[name] = str(value).encode('UTF-8')
         return props
 
     def get_content_length(self):
diff --git a/subversion/bindings/swig/python/tests/utils.py 
b/subversion/bindings/swig/python/tests/utils.py
index 01cacc4fc6..fdb243a94b 100644
--- a/subversion/bindings/swig/python/tests/utils.py
+++ b/subversion/bindings/swig/python/tests/utils.py
@@ -47,13 +47,18 @@ class Temper(object):
   def alloc_empty_dir(self, suffix = ""):
     """Create an empty temporary directory. Returns its full path
        in canonical internal form."""
-    temp_dir_name = 
core.svn_dirent_internal_style(tempfile.mkdtemp(suffix).encode('UTF-8'))
+    if isinstance(suffix, bytes):
+      suffix = suffix.decode('UTF-8')
+    temp_dir_name = tempfile.mkdtemp(suffix).encode('UTF-8')
+    temp_dir_name = core.svn_dirent_internal_style(temp_dir_name)
     self._cleanup_list.append((temp_dir_name, core.svn_io_remove_dir))
     return temp_dir_name
 
   def alloc_empty_repo(self, suffix = ""):
     """Create an empty repository. Returns a tuple of its handle, path and
        file: URI in canonical internal form."""
+    if isinstance(suffix, bytes):
+      suffix = suffix.decode('UTF-8')
     temp_path = tempfile.mkdtemp(suffix).encode('UTF-8')
     repo_path = core.svn_dirent_internal_style(temp_path)
     repo_uri = core.svn_uri_canonicalize(file_uri_for_path(temp_path))

Reply via email to