subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From troycurti...@apache.org
Subject svn commit: r1823802 - in /subversion/trunk/subversion/bindings/swig/python: svn/fs.py tests/fs.py tests/run_all.py
Date Sun, 11 Feb 2018 02:19:42 GMT
Author: troycurtisjr
Date: Sun Feb 11 02:19:42 2018
New Revision: 1823802

URL: http://svn.apache.org/viewvc?rev=1823802&view=rev
Log:
Ensure Python bindings for fs.FileDiff behaves correctly when the python-future
package is installed.

* subversion/bindings/swig/python/svn/fs.py
  Try the Python 2 '__builtin__' import before the Python 3 'builtins'.
  (FileDiff._dump_contents): Open temporary file in binary mode.
  
* subversion/bindings/swig/python/tests/fs.py
  Add test for fs.FileDiff.

* subversion/bindings/swig/python/tests/run_all.py
  (suite): Add fs test suite.

Found By: Kenneth Porter <shiva@sewingwitch.com>

Added:
    subversion/trunk/subversion/bindings/swig/python/tests/fs.py   (with props)
Modified:
    subversion/trunk/subversion/bindings/swig/python/svn/fs.py
    subversion/trunk/subversion/bindings/swig/python/tests/run_all.py

Modified: subversion/trunk/subversion/bindings/swig/python/svn/fs.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/python/svn/fs.py?rev=1823802&r1=1823801&r2=1823802&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/python/svn/fs.py (original)
+++ subversion/trunk/subversion/bindings/swig/python/svn/fs.py Sun Feb 11 02:19:42 2018
@@ -34,11 +34,13 @@ del _unprefix_names
 # Names that are not to be exported
 import sys as _sys, os as _os, tempfile as _tempfile, subprocess as _subprocess
 try:
-  # Python >=3.0
-  import builtins
-except ImportError:
   # Python <3.0
+  # Check for Python <3.0 first to prevent the presence of the python2-future
+  # package from incorrectly importing Python 3 behavior when it isn't intended.
   import __builtin__ as builtins
+except ImportError:
+  # Python >=3.0
+  import builtins
 import svn.core as _svncore
 
 
@@ -76,7 +78,7 @@ class FileDiff:
     return 0
 
   def _dump_contents(self, file, root, path, pool=None):
-    fp = builtins.open(file, 'w+') # avoid namespace clash with
+    fp = builtins.open(file, 'wb') # avoid namespace clash with
                                    # trimmed-down svn_fs_open()
     if path is not None:
       stream = file_contents(root, path, pool)

Added: subversion/trunk/subversion/bindings/swig/python/tests/fs.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/python/tests/fs.py?rev=1823802&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/swig/python/tests/fs.py (added)
+++ subversion/trunk/subversion/bindings/swig/python/tests/fs.py Sun Feb 11 02:19:42 2018
@@ -0,0 +1,100 @@
+#
+# -*- coding: utf-8 -*-
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+import os, unittest
+from tempfile import mkstemp
+try:
+  # Python >=3.0
+  from urllib.parse import urljoin
+except ImportError:
+  # Python <3.0
+  from urlparse import urljoin
+
+from svn import core, repos, fs, client
+import utils
+
+class SubversionFSTestCase(unittest.TestCase):
+  """Test cases for the Subversion FS layer"""
+
+  def log_message_func(self, items, pool):
+    """ Simple log message provider for unit tests. """
+    return "Test unicode log message"
+
+  def setUp(self):
+    """Load a Subversion repository"""
+    self.temper = utils.Temper()
+    (self.repos, self.repos_path, self.repos_uri) = self.temper.alloc_known_repo(
+      'trac/versioncontrol/tests/svnrepos.dump', suffix='-repository')
+    self.fs = repos.fs(self.repos)
+    self.rev = fs.youngest_rev(self.fs)
+    self.tmpfile = None
+
+  def tearDown(self):
+    self.fs = None
+    self.repos = None
+    self.temper.cleanup()
+
+    if self.tmpfile is not None:
+      os.remove(self.tmpfile)
+
+  def test_diff_repos_paths(self):
+    """Test diffing of a repository path."""
+    tmpfd, self.tmpfile = mkstemp()
+
+    tmpfp = os.fdopen(tmpfd, "w")
+
+    # Use a unicode file to ensure proper non-ascii handling.
+    tmpfp.write(u'⊙_ʘ'.encode('utf8'))
+
+    tmpfp.close()
+
+    clientctx = client.svn_client_create_context()
+    clientctx.log_msg_func3 = client.svn_swig_py_get_commit_log_func
+    clientctx.log_msg_baton3 = self.log_message_func
+
+    providers = [
+       client.svn_client_get_simple_provider(),
+       client.svn_client_get_username_provider(),
+    ]
+
+    clientctx.auth_baton = core.svn_auth_open(providers)
+
+    commitinfo = client.import2(self.tmpfile,
+                                urljoin(self.repos_uri +"/", "trunk/UniTest.txt"),
+                                True, True,
+                                clientctx)
+    self.assertEqual(commitinfo.revision, self.rev + 1)
+
+    fdiff = fs.FileDiff(fs.revision_root(self.fs, commitinfo.revision), "/trunk/UniTest.txt",
+                        None, None)
+
+    diffp = fdiff.get_pipe()
+    diffoutput = diffp.read().decode('utf8')
+
+    self.assertTrue(diffoutput.find(u'< ⊙_ʘ') > 0)
+
+def suite():
+    return unittest.defaultTestLoader.loadTestsFromTestCase(
+      SubversionFSTestCase)
+
+if __name__ == '__main__':
+    runner = unittest.TextTestRunner()
+    runner.run(suite())

Propchange: subversion/trunk/subversion/bindings/swig/python/tests/fs.py
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: subversion/trunk/subversion/bindings/swig/python/tests/run_all.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/python/tests/run_all.py?rev=1823802&r1=1823801&r2=1823802&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/python/tests/run_all.py (original)
+++ subversion/trunk/subversion/bindings/swig/python/tests/run_all.py Sun Feb 11 02:19:42
2018
@@ -19,7 +19,7 @@
 #
 #
 import unittest, setup_path
-import mergeinfo, core, client, delta, checksum, pool, ra, wc, repository, \
+import mergeinfo, core, client, delta, checksum, pool, fs, ra, wc, repository, \
        auth, trac.versioncontrol.tests
 from svn.core import svn_cache_config_get, svn_cache_config_set
 
@@ -37,6 +37,7 @@ def suite():
   s.addTest(client.suite())
   s.addTest(delta.suite())
   s.addTest(pool.suite())
+  s.addTest(fs.suite())
   s.addTest(ra.suite())
   s.addTest(wc.suite())
   s.addTest(repository.suite())



Mime
View raw message