Patchwork [hglib] context: raise same error when not found for all hg versions

login
register
mail settings
Submitter Alexander Plavin
Date April 25, 2013, 10:31 p.m.
Message ID <039faa0bddbbd2531c7c.1366929071@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/1483/
State Accepted
Headers show

Comments

Alexander Plavin - April 25, 2013, 10:31 p.m.
# HG changeset patch
# User Alexander Plavin <me@aplavin.ru>
# Date 1366926368 -14400
# Node ID 039faa0bddbbd2531c7c9fb4fc8e9e6cfd5ddf74
# Parent  9324a89dd84e1562b87556a3b2788fdf04ba8179
context: raise same error when not found for all hg versions

hg log behavior changed, so modify context constructor to account for this

\ No newline at end of file
Matt Mackall - April 26, 2013, 5:31 p.m.
On Fri, 2013-04-26 at 02:31 +0400, Alexander Plavin wrote:
> # HG changeset patch
> # User Alexander Plavin <me@aplavin.ru>
> # Date 1366926368 -14400
> # Node ID 039faa0bddbbd2531c7c9fb4fc8e9e6cfd5ddf74
> # Parent  9324a89dd84e1562b87556a3b2788fdf04ba8179
> context: raise same error when not found for all hg versions
> 
> hg log behavior changed, so modify context constructor to account for this

Queued for hglib, thanks.
Idan Kamara - April 30, 2013, 7:46 p.m.
On Fri, Apr 26, 2013 at 1:31 AM, Alexander Plavin <me@aplavin.ru> wrote:
>
> # HG changeset patch
> # User Alexander Plavin <me@aplavin.ru>
> # Date 1366926368 -14400
> # Node ID 039faa0bddbbd2531c7c9fb4fc8e9e6cfd5ddf74
> # Parent  9324a89dd84e1562b87556a3b2788fdf04ba8179
> context: raise same error when not found for all hg versions
>
> hg log behavior changed, so modify context constructor to account for this
>
> diff -r 9324a89dd84e -r 039faa0bddbb hglib/context.py
> --- a/hglib/context.py  Tue Apr 23 22:11:26 2013 +0200
> +++ b/hglib/context.py  Fri Apr 26 01:46:08 2013 +0400
> @@ -1,3 +1,4 @@
> +from hglib.error import CommandError
>  import client, util, templates
>
>  _nullcset = ['-1', '000000000000000000000000000000000000000', '', '',
'', '', '']
> @@ -18,8 +19,13 @@
>              if isinstance(changeid, (long, int)):
>                  changeid = 'rev(%d)' % changeid
>
> -            cset = self._repo.log(changeid)
> -            if not len(cset):
> +            notfound = False
> +            try:
> +                cset = self._repo.log(changeid)
> +            except CommandError:
> +                notfound = True
> +
> +            if notfound or not len(cset):
>                  raise ValueError('changeid %r not found in repo' %
changeid)
>              if len(cset) > 1:
>                  raise ValueError('changeid must yield a single
changeset')
> diff -r 9324a89dd84e -r 039faa0bddbb tests/test-context.py
> --- a/tests/test-context.py     Tue Apr 23 22:11:26 2013 +0200
> +++ b/tests/test-context.py     Fri Apr 26 01:46:08 2013 +0400
> @@ -1,9 +1,10 @@
> +from hglib.error import CommandError
>  import common, hglib
>  from hglib import context
>
>  class test_context(common.basetest):
>      def test_non_existent(self):
> -        self.assertRaises(ValueError, context.changectx, self.client,
'foo')
> +        self.assertRaisesRegexp(ValueError, 'not found',
context.changectx, self.client, 'foo')

assertRaisesRegexp was introduced in 2.7:
http://docs.python.org/2/library/unittest.html#unittest.TestCase.assertRaisesRegexp

You can track the build status of hglib here:
http://hgbuildbot.kublai.com/builders/python-hglib/

Patch

diff -r 9324a89dd84e -r 039faa0bddbb hglib/context.py
--- a/hglib/context.py	Tue Apr 23 22:11:26 2013 +0200
+++ b/hglib/context.py	Fri Apr 26 01:46:08 2013 +0400
@@ -1,3 +1,4 @@ 
+from hglib.error import CommandError
 import client, util, templates
 
 _nullcset = ['-1', '000000000000000000000000000000000000000', '', '', '', '', '']
@@ -18,8 +19,13 @@ 
             if isinstance(changeid, (long, int)):
                 changeid = 'rev(%d)' % changeid
 
-            cset = self._repo.log(changeid)
-            if not len(cset):
+            notfound = False
+            try:
+                cset = self._repo.log(changeid)
+            except CommandError:
+                notfound = True
+
+            if notfound or not len(cset):
                 raise ValueError('changeid %r not found in repo' % changeid)
             if len(cset) > 1:
                 raise ValueError('changeid must yield a single changeset')
diff -r 9324a89dd84e -r 039faa0bddbb tests/test-context.py
--- a/tests/test-context.py	Tue Apr 23 22:11:26 2013 +0200
+++ b/tests/test-context.py	Fri Apr 26 01:46:08 2013 +0400
@@ -1,9 +1,10 @@ 
+from hglib.error import CommandError
 import common, hglib
 from hglib import context
 
 class test_context(common.basetest):
     def test_non_existent(self):
-        self.assertRaises(ValueError, context.changectx, self.client, 'foo')
+        self.assertRaisesRegexp(ValueError, 'not found', context.changectx, self.client, 'foo')
 
     def test_basic(self):
         self.append('a', 'a')
diff -r 9324a89dd84e -r 039faa0bddbb tests/test-log.py
--- a/tests/test-log.py	Tue Apr 23 22:11:26 2013 +0200
+++ b/tests/test-log.py	Fri Apr 26 01:46:08 2013 +0400
@@ -16,3 +16,9 @@ 
 
         self.assertEquals(revs[0], self.client.log('0')[0])
         self.assertEquals(self.client.log(), self.client.log(files=['a']))
+
+    # def test_errors(self):
+    #     self.assertRaisesRegexp(CommandError, 'abort: unknown revision', self.client.log, 'foo')
+    #     self.append('a', 'a')
+    #     self.client.commit('first', addremove=True)
+    #     self.assertRaisesRegexp(CommandError, 'abort: unknown revision', self.client.log, 'bar')