changeset 110:c635e6e7054f 0.9

context: raise same error when not found for all hg versions hg log behavior changed, so modify context constructor to account for this
author Alexander Plavin <me@aplavin.ru>
date Fri, 26 Apr 2013 01:46:08 +0400
parents 9324a89dd84e
children 63b92316623e
files hglib/context.py tests/test-context.py tests/test-log.py
diffstat 3 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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')
--- 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')
--- 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')
\ No newline at end of file