Rev 4806: (jam, Martin gz) More win32 fixes. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Nov 17 23:53:21 GMT 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4806 [merge]
revision-id: pqm at pqm.ubuntu.com-20091117235319-z03oifdp0cybnhjm
parent: pqm at pqm.ubuntu.com-20091117092107-8ag9sr4hd0cubo6r
parent: john at arbash-meinel.com-20091117230504-p05mbkihim789aq7
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2009-11-17 23:53:19 +0000
message:
  (jam, Martin gz) More win32 fixes.
modified:
  bzrlib/msgeditor.py            msgeditor.py-20050901111708-ef6d8de98f5d8f2f
  bzrlib/tests/test__dirstate_helpers.py test_dirstate_helper-20070504035751-jsbn00xodv0y1eve-2
  bzrlib/tests/test_msgeditor.py test_msgeditor.py-20051202041359-920315ec6011ee51
  bzrlib/tests/test_trace.py     testtrace.py-20051110225523-a21117fc7a07eeff
=== modified file 'bzrlib/msgeditor.py'
--- a/bzrlib/msgeditor.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/msgeditor.py	2009-11-17 23:05:04 +0000
@@ -64,7 +64,13 @@
             x = call(edargs + [filename])
         except OSError, e:
             # We're searching for an editor, so catch safe errors and continue
-            if e.errno in (errno.ENOENT, errno.EACCES):
+            # errno 193 is ERROR_BAD_EXE_FORMAT on Windows. Python2.4 uses the
+            # winerror for errno. Python2.5+ use errno ENOEXEC and set winerror
+            # to 193. However, catching 193 here should be fine. Other
+            # platforms aren't likely to have that high of an error. And even
+            # if they do, it is still reasonable to fall back to the next
+            # editor.
+            if e.errno in (errno.ENOENT, errno.EACCES, errno.ENOEXEC, 193):
                 if candidate_source is not None:
                     # We tried this editor because some user configuration (an
                     # environment variable or config file) said to try it.  Let

=== modified file 'bzrlib/tests/test__dirstate_helpers.py'
--- a/bzrlib/tests/test__dirstate_helpers.py	2009-06-22 15:39:42 +0000
+++ b/bzrlib/tests/test__dirstate_helpers.py	2009-11-08 05:00:24 +0000
@@ -743,13 +743,17 @@
 
     def test_trailing_garbage(self):
         tree, state, expected = self.create_basic_dirstate()
-        # We can modify the file as long as it hasn't been read yet.
+        # On Linux, we can write extra data as long as we haven't read yet, but
+        # on Win32, if you've opened the file with FILE_SHARE_READ, trying to
+        # open it in append mode will fail.
+        state.unlock()
         f = open('dirstate', 'ab')
         try:
             # Add bogus trailing garbage
             f.write('bogus\n')
         finally:
             f.close()
+            state.lock_read()
         e = self.assertRaises(errors.DirstateCorrupt,
                               state._read_dirblocks_if_needed)
         # Make sure we mention the bogus characters in the error

=== modified file 'bzrlib/tests/test_msgeditor.py'
--- a/bzrlib/tests/test_msgeditor.py	2009-10-06 14:40:37 +0000
+++ b/bzrlib/tests/test_msgeditor.py	2009-11-17 23:05:04 +0000
@@ -35,6 +35,7 @@
     edit_commit_message_encoded
 )
 from bzrlib.tests import (
+    TestCaseInTempDir,
     TestCaseWithTransport,
     TestNotApplicable,
     TestSkipped,
@@ -290,7 +291,10 @@
         # Call _run_editor, capturing mutter.warning calls.
         warnings = []
         def warning(*args):
-            warnings.append(args[0] % args[1:])
+            if len(args) > 1:
+                warnings.append(args[0] % args[1:])
+            else:
+                warnings.append(args[0])
         _warning = trace.warning
         trace.warning = warning
         try:
@@ -364,3 +368,24 @@
         commit_obj = commit.Commit()
         self.assertEquals("save me some typing\n",
             msgeditor.generate_commit_message_template(commit_obj))
+
+
+# GZ 2009-11-17: This wants moving to osutils when the errno checking code is
+class TestPlatformErrnoWorkarounds(TestCaseInTempDir):
+    """Ensuring workarounds enshrined in code actually serve a purpose"""
+
+    def test_subprocess_call_bad_file(self):
+        if sys.platform != "win32":
+            raise TestNotApplicable("Workarounds for windows only")
+        import subprocess, errno
+        ERROR_BAD_EXE_FORMAT = 193
+        file("textfile.txt", "w").close()
+        e = self.assertRaises(WindowsError, subprocess.call, "textfile.txt")
+        # Python2.4 used the 'winerror' as the errno, which confuses a lot of
+        # our error trapping code. Make sure that we understand the mapping
+        # correctly.
+        if sys.version_info >= (2, 5):
+            self.assertEqual(e.errno, errno.ENOEXEC)
+            self.assertEqual(e.winerror, ERROR_BAD_EXE_FORMAT)
+        else:
+            self.assertEqual(e.errno, ERROR_BAD_EXE_FORMAT)

=== modified file 'bzrlib/tests/test_trace.py'
--- a/bzrlib/tests/test_trace.py	2009-09-03 02:59:56 +0000
+++ b/bzrlib/tests/test_trace.py	2009-11-08 19:07:00 +0000
@@ -84,11 +84,12 @@
     def test_format_os_error(self):
         try:
             os.rmdir('nosuchfile22222')
-        except OSError:
-            pass
+        except OSError, e:
+            e_str = str(e)
         msg = _format_exception()
-        self.assertContainsRe(msg,
-            r'^bzr: ERROR: \[Errno .*\] No such file.*nosuchfile22222')
+        # Linux seems to give "No such file" but Windows gives "The system
+        # cannot find the file specified".
+        self.assertEqual('bzr: ERROR: %s\n' % (e_str,), msg)
 
     def test_format_io_error(self):
         try:
@@ -96,7 +97,10 @@
         except IOError:
             pass
         msg = _format_exception()
-        self.assertContainsRe(msg, r'^bzr: ERROR: \[Errno .*\] No such file.*nosuchfile')
+        # Even though Windows and Linux differ for 'os.rmdir', they both give
+        # 'No such file' for open()
+        self.assertContainsRe(msg,
+            r'^bzr: ERROR: \[Errno .*\] No such file.*nosuchfile')
 
     def test_format_unicode_error(self):
         try:
@@ -268,7 +272,7 @@
     def test_log_rollover(self):
         temp_log_name = 'test-log'
         trace_file = open(temp_log_name, 'at')
-        trace_file.write('test_log_rollover padding\n' * 1000000)
+        trace_file.writelines(['test_log_rollover padding\n'] * 200000)
         trace_file.close()
         _rollover_trace_maybe(temp_log_name)
         # should have been rolled over




More information about the bazaar-commits mailing list