You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by fu...@apache.org on 2021/01/06 14:05:06 UTC

svn commit: r1885199 - in /subversion/trunk/subversion/bindings/swig/python/tests: client.py core.py typemap.py utils.py

Author: futatuki
Date: Wed Jan  6 14:05:06 2021
New Revision: 1885199

URL: http://svn.apache.org/viewvc?rev=1885199&view=rev
Log:
swig-py: Skip some tests on Python 2 if default encoding is 'utf-8'.

There are some tests checking str(unicode) to bytes conversion on input
argments of Python wrapper functions raise UnicodeEncodeError when
those argments contains "invalid" Unicode characters.  On Python 2, those
conversions are done by using "default encoding" codec.  However
'utf-8' codec on Python 2 does not raise UnicodeEncodeError even
the source unicode object contains characters of surrogate code points
which are considered invalid on Python 3 unless using 'surrogateescape'
handler.  Those tests depends on it, so we need to skip them if the
test run on Python 2 and default encoding is 'utf-8'.

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

* utils.py
  (IS_PY3): New variable, moved from core.py.
  (codecs_eq, is_defaultencoding_utf8): New functions.

* client.py
  (SubversionClientTestCase.test_get_commit_log3_callback_unicode_error):
    Check another Exception on Python 2 if default encoding is 'utf-8'.
  (SubversionClientTestCase.test_log5_revprops):
    Skip the check of UnicodeEncodeError on Python 2 with default encoding
    'utf-8'.

* core.py
  (SubversionCoreTestCase.test_stream_write_exception):
    Skip it on Python 2 if default encoding is 'utf-8'.
  (SubversionCoreTestCase.test_stream_write_str):
    Don't skip it on Python 2 if default encoding is 'utf-8'. This test
    depends on using 'utf-8' codec as default encoding when it runs on
    Python 2.

* typemap.py
  (): Import utils, for IS_PY3 and is_defaultencoding_utf8().
  (SubversionTypemapTestCase.test_char_ptr_in_unicode_exception,
   SubversionTypemapTestCase.test_char_ptr_may_be_null_unicode_exception,
   SubversionTypemapTestCase.test_make_string_from_ob_unicode_exception,
   SubversionTypemapTestCase.test_make_svn_string_from_ob_unicode_exception):
    Skip them on Python 2 if default encoding is 'utf-8'.

Modified:
    subversion/trunk/subversion/bindings/swig/python/tests/client.py
    subversion/trunk/subversion/bindings/swig/python/tests/core.py
    subversion/trunk/subversion/bindings/swig/python/tests/typemap.py
    subversion/trunk/subversion/bindings/swig/python/tests/utils.py

Modified: subversion/trunk/subversion/bindings/swig/python/tests/client.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/python/tests/client.py?rev=1885199&r1=1885198&r2=1885199&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/python/tests/client.py (original)
+++ subversion/trunk/subversion/bindings/swig/python/tests/client.py Wed Jan  6 14:05:06 2021
@@ -233,9 +233,17 @@ class SubversionClientTestCase(unittest.
                                                         u" message")
     self.client_ctx.log_msg_baton3 = bogus_log_message_func
 
-    with self.assertRaises(UnicodeEncodeError):
-      commit_info = client.mkdir3((directory,), 1, {b'customprop':b'value'},
-                                  self.client_ctx)
+    if not utils.IS_PY3 and utils.is_defaultencoding_utf8():
+      # 'utf-8' codecs on Python 2 does not raise UnicodeEncodeError
+      # on surrogate code point U+dc00 - U+dcff, however it causes
+      # Subversion error on property validation of svn:log
+      with self.assertRaises(core.SubversionException):
+        commit_info = client.mkdir3((directory,), 1, {b'customprop':b'value'},
+                                    self.client_ctx)
+    else:
+      with self.assertRaises(UnicodeEncodeError):
+        commit_info = client.mkdir3((directory,), 1, {b'customprop':b'value'},
+                                    self.client_ctx)
 
   def test_log3_url(self):
     """Test svn_client_log3 on a file:// URL"""
@@ -302,10 +310,14 @@ class SubversionClientTestCase(unittest.
     self.assertEqual(revprops[b'svn:author'], b"john")
     with self.assertRaises(KeyError):
       commit_date = revprops['svn:date']
-    with self.assertRaises(UnicodeEncodeError):
-      client.log5((directory,), start, (rev_range,), 1, True, False, False,
-                  (u'svn:\udc61uthor', b'svn:log'),
-                  log_entry_receiver_whole, self.client_ctx)
+    if utils.IS_PY3 or not utils.is_defaultencoding_utf8():
+      # 'utf-8' codecs on Python 2 does not raise UnicodeEncodeError
+      # on surrogate code point U+dc00 - U+dcff. So we need to skip
+      # below in such a case.
+      with self.assertRaises(UnicodeEncodeError):
+        client.log5((directory,), start, (rev_range,), 1, True, False, False,
+                    (u'svn:\udc61uthor', b'svn:log'),
+                    log_entry_receiver_whole, self.client_ctx)
 
   def test_uuid_from_url(self):
     """Test svn_client_uuid_from_url on a file:// URL"""

Modified: subversion/trunk/subversion/bindings/swig/python/tests/core.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/python/tests/core.py?rev=1885199&r1=1885198&r2=1885199&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/python/tests/core.py (original)
+++ subversion/trunk/subversion/bindings/swig/python/tests/core.py Wed Jan  6 14:05:06 2021
@@ -23,8 +23,6 @@ import os
 import tempfile
 import sys
 
-IS_PY3 = sys.version_info[0] >= 3
-
 import svn.core, svn.client
 import utils
 
@@ -222,6 +220,8 @@ class SubversionCoreTestCase(unittest.Te
     self.assertEqual(svn.core.svn_stream_read2(stream, 4096), b'')
     svn.core.svn_stream_close(stream)
 
+  @unittest.skipIf(not utils.IS_PY3 and utils.is_defaultencoding_utf8(),
+                   "'utf-8' codecs of Python 2 accepts any unicode strings")
   def test_stream_write_exception(self):
     stream = svn.core.svn_stream_empty()
     with self.assertRaises(TypeError):
@@ -238,7 +238,8 @@ class SubversionCoreTestCase(unittest.Te
   # As default codec of Python 2 is 'ascii', conversion from unicode to bytes
   # will be success only if all characters of target strings are in the range
   # of \u0000 ~ \u007f.
-  @unittest.skipUnless(IS_PY3, "test for Python 3 only")
+  @unittest.skipUnless(utils.IS_PY3 or utils.is_defaultencoding_utf8(),
+                       "test ony for Python 3 or Python 2 'utf-8' codecs")
   def test_stream_write_str(self):
     o1_str = u'Python\x00\u3071\u3044\u305d\u3093\r\n'
     o2_str = u'subVersioN\x00\u3055\u3076\u3070\u30fc\u3058\u3087\u3093'

Modified: subversion/trunk/subversion/bindings/swig/python/tests/typemap.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/python/tests/typemap.py?rev=1885199&r1=1885198&r2=1885199&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/python/tests/typemap.py (original)
+++ subversion/trunk/subversion/bindings/swig/python/tests/typemap.py Wed Jan  6 14:05:06 2021
@@ -23,6 +23,7 @@ import os
 import tempfile
 
 import svn.core
+import utils
 
 class SubversionTypemapTestCase(unittest.TestCase):
   """Test cases for the SWIG typemaps arguments and return values translation"""
@@ -47,6 +48,8 @@ class SubversionTypemapTestCase(unittest
                      "svn_dirent_join() argument component must be"
                      " bytes or str, not int")
 
+  @unittest.skipIf(not utils.IS_PY3 and utils.is_defaultencoding_utf8(),
+                   "'utf-8' codecs of Python 2 accepts any unicode strings")
   def test_char_ptr_in_unicode_exception(self):
     """Check %typemap(in) IN_STRING handles unicode encode error correctly"""
     with self.assertRaises(UnicodeEncodeError):
@@ -67,6 +70,8 @@ class SubversionTypemapTestCase(unittest
                      " must be bytes or str or None, not %s"
                      % self.__class__.__name__)
 
+  @unittest.skipIf(not utils.IS_PY3 and utils.is_defaultencoding_utf8(),
+                   "'utf-8' codecs of Python 2 accepts any unicode strings")
   def test_char_ptr_may_be_null_unicode_exception(self):
     """Check %typemap(in) char *MAY_BE_NULL handles unicode encode error correctly"""
     cfg = svn.core.svn_config_create2(False, False)
@@ -101,6 +106,8 @@ class SubversionTypemapTestCase(unittest
     self.assertEqual(svn.core.svn_prop_diffs(target_props, source_props),
                      expected)
 
+  @unittest.skipIf(not utils.IS_PY3 and utils.is_defaultencoding_utf8(),
+                   "'utf-8' codecs of Python 2 accepts any unicode strings")
   def test_make_string_from_ob_unicode_exception(self):
     """Check make_string_from_ob  handles unicode encode error correctly"""
     source_props = { b'a'      : b'foo',
@@ -112,6 +119,8 @@ class SubversionTypemapTestCase(unittest
     with self.assertRaises(UnicodeEncodeError):
       svn.core.svn_prop_diffs(target_props, source_props)
 
+  @unittest.skipIf(not utils.IS_PY3 and utils.is_defaultencoding_utf8(),
+                   "'utf-8' codecs of Python 2 accepts any unicode strings")
   def test_make_svn_string_from_ob_unicode_exception(self):
     """Check make_string_from_ob handles unicode encode error correctly"""
     source_props = { b'a' : b'foo',

Modified: subversion/trunk/subversion/bindings/swig/python/tests/utils.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/python/tests/utils.py?rev=1885199&r1=1885198&r2=1885199&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/python/tests/utils.py (original)
+++ subversion/trunk/subversion/bindings/swig/python/tests/utils.py Wed Jan  6 14:05:06 2021
@@ -18,7 +18,7 @@
 # under the License.
 #
 #
-import os.path, sys, tempfile
+import os.path, sys, tempfile, codecs
 from svn import core, repos
 from io import BytesIO
 try:
@@ -28,6 +28,8 @@ except ImportError:
   # Python <3.0
   from urllib import pathname2url
 
+IS_PY3 = sys.hexversion >= 0x3000000
+
 class Temper(object):
   """Class to simplify allocation and cleanup of dummy Subversion
      structures, such as repositories and working copies."""
@@ -87,3 +89,9 @@ def file_uri_for_path(path):
   # it returns both the authority and path parts for no reason, which
   # means we have to trim the leading slashes to "normalize" the result.
   return b'file:///' + uri_path.lstrip(b'/')
+
+def codecs_eq(a, b):
+  return codecs.lookup(a) == codecs.lookup(b)
+
+def is_defaultencoding_utf8():
+  return codecs_eq(sys.getdefaultencoding(), 'utf-8')