subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stef...@apache.org
Subject svn commit: r1743951 - /subversion/trunk/subversion/tests/cmdline/svntest/actions.py
Date Sun, 15 May 2016 18:51:41 GMT
Author: stefan2
Date: Sun May 15 18:51:41 2016
New Revision: 1743951

URL: http://svn.apache.org/viewvc?rev=1743951&view=rev
Log:
Make the test framework's propset utility work with Python 3 on Windows
and cover a few currently unused edge cases.

* subversion/tests/cmdline/svntest/actions.py
  (_make_temp_file): New utility function, factor out from ...  
  (set_prop): ... here.  Don't attempt to write unicode strings directly
              into the binary value file.  Be sure to always cleanup the
              temp file if one was used.

Patch by: kotkov

Modified:
    subversion/trunk/subversion/tests/cmdline/svntest/actions.py

Modified: subversion/trunk/subversion/tests/cmdline/svntest/actions.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/svntest/actions.py?rev=1743951&r1=1743950&r2=1743951&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/svntest/actions.py (original)
+++ subversion/trunk/subversion/tests/cmdline/svntest/actions.py Sun May 15 18:51:41 2016
@@ -2103,6 +2103,18 @@ def create_failing_post_commit_hook(repo
             '@echo Post-commit hook failed 1>&2\n'
             '@exit 1\n')
 
+def _make_temp_file(contents):
+  """ Create a unique temporary file with the specified CONTENTS
+  and return its path. """
+  from tempfile import mkstemp
+  (fd, path) = mkstemp()
+  os.close(fd)
+  file = open(path, 'wb')
+  file.write(contents)
+  file.flush()
+  file.close()
+  return path
+
 # set_prop can be used for properties with NULL characters which are not
 # handled correctly when passed to subprocess.Popen() and values like "*"
 # which are not handled correctly on Windows.
@@ -2112,21 +2124,29 @@ def set_prop(name, value, path, expected
     propset = ('propset',)
   else:
     propset = ('propset', '--force')
-  if value and (isinstance(value, bytes) or
-                (value[0] == '-' or '\x00' in value or sys.platform == 'win32')):
-    from tempfile import mkstemp
-    (fd, value_file_path) = mkstemp()
-    os.close(fd)
-    value_file = open(value_file_path, 'wb')
-    value_file.write(value)
-    value_file.flush()
-    value_file.close()
-    propset += ('-F', value_file_path, name, path)
-    exit_code, out, err = main.run_svn(expected_re_string, *propset)
-    os.remove(value_file_path)
+
+  if isinstance(value, bytes):
+    file = _make_temp_file(value)
+  elif isinstance(value, str):
+    if value and (value[0] == '-' or '\x00' in value or
+                  sys.platform == 'win32'):
+      file = _make_temp_file(value.encode())
+    else:
+      file = None
   else:
+    raise TypeError(value)
+ 
+  if file is None:
     propset += (name, value, path)
+  else:
+    propset += ('-F', file, name, path)
+
+  try:
     exit_code, out, err = main.run_svn(expected_re_string, *propset)
+  finally:
+    if file is not None:
+      os.remove(file)
+
   if expected_re_string:
     if not expected_re_string.startswith(".*"):
       expected_re_string = ".*(" + expected_re_string + ")"



Mime
View raw message