Patchwork D9377: tests: make test-worker.t pass on py2

login
register
mail settings
Submitter phabricator
Date Nov. 23, 2020, 8:18 p.m.
Message ID <differential-rev-PHID-DREV-2vyxpqakxcwlfuzjbkpv-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47656/
State Superseded
Headers show

Comments

phabricator - Nov. 23, 2020, 8:18 p.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  I broke the py2 version in https://phab.mercurial-scm.org/D9287
  because the `WorkerError.__bytes__()` (or `.__str__()`?) output was
  different in py2 compared to py3. Part of the problem was that I
  didn't propagate the status code that was passed in to the superclass
  so it could get printed. This patch fixes that. I don't know how it
  worked on py3 before this patch...
  
  I also added the usual `__bytes__ = _tobytes` override for good
  measure. It doesn't seem to be needed for tests to pass, though.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9377

AFFECTED FILES
  mercurial/error.py
  tests/test-worker.t

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-worker.t b/tests/test-worker.t
--- a/tests/test-worker.t
+++ b/tests/test-worker.t
@@ -90,7 +90,8 @@ 
   mercurial.error.Abort: known exception (py3 !)
   Abort: known exception (no-py3 !)
       raise error.WorkerError(status)
-  mercurial.error.WorkerError: 255
+  WorkerError: 255 (no-py3 !)
+  mercurial.error.WorkerError: 255 (py3 !)
 
 Traceback must be printed for unknown exceptions
 
diff --git a/mercurial/error.py b/mercurial/error.py
--- a/mercurial/error.py
+++ b/mercurial/error.py
@@ -137,6 +137,10 @@ 
 
     def __init__(self, status_code):
         self.status_code = status_code
+        # Pass status code to superclass just so it becomes part of __bytes__
+        super(WorkerError, self).__init__(status_code)
+
+    __bytes__ = _tobytes
 
 
 class InterventionRequired(Hint, Exception):