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

Idan Kamara idankk86 at gmail.com
Tue Apr 30 14:46:27 CDT 2013


On Fri, Apr 26, 2013 at 1:31 AM, Alexander Plavin <me at aplavin.ru> wrote:
>
> # HG changeset patch
> # User Alexander Plavin <me at 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/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20130430/7695f478/attachment.html>


More information about the Mercurial-devel mailing list