Patchwork [1,of,5] client: implement the 'in' keyword for a client object

login
register
mail settings
Submitter Paul Tonelli
Date May 22, 2014, 1:50 p.m.
Message ID <bbb9a6fdfa6c45084f91.1400766619@crater1.logilab.fr>
Download mbox | patch
Permalink /patch/4850/
State Superseded
Headers show

Comments

Paul Tonelli - May 22, 2014, 1:50 p.m.
# HG changeset patch
# User Paul Tonelli <paul.tonelli@logilab.fr>
# Date 1398869099 -7200
#      Wed Apr 30 16:44:59 2014 +0200
# Node ID bbb9a6fdfa6c45084f912a351b9732979bf21fed
# Parent  cc905ee184499f9d05e845d4ba043eca0d974329
client: implement the 'in' keyword for a client object

Check if a revision number or a changeset hex matches a changeset in the client
repository. The internal tries to create a ctx object. Returns False If the ctx
creation fails.

This patch also adds the corresponding tests.
Idan Kamara - May 26, 2014, 3:13 a.m.
On Thu, May 22, 2014 at 6:50 AM, Paul Tonelli <paul.tonelli@logilab.fr> wrote:
>
> # HG changeset patch
> # User Paul Tonelli <paul.tonelli@logilab.fr>
> # Date 1398869099 -7200
> #      Wed Apr 30 16:44:59 2014 +0200
> # Node ID bbb9a6fdfa6c45084f912a351b9732979bf21fed
> # Parent  cc905ee184499f9d05e845d4ba043eca0d974329
> client: implement the 'in' keyword for a client object
>
> Check if a revision number or a changeset hex matches a changeset in the client
> repository. The internal tries to create a ctx object. Returns False If the ctx
> creation fails.
>
> This patch also adds the corresponding tests.
>
> diff -r cc905ee18449 -r bbb9a6fdfa6c hglib/client.py
> --- a/hglib/client.py   Sat Feb 01 15:30:18 2014 -0600
> +++ b/hglib/client.py   Wed Apr 30 16:44:59 2014 +0200
> @@ -1531,3 +1531,14 @@
>
>      def __getitem__(self, changeid):
>          return context.changectx(self, changeid)
> +
> +    def __contains__(self, changeid):
> +        """
> +        check if changeid, which can be either a local revision number or a
> +        changeset id, matches a changeset in the client.
> +        """
> +        try:
> +            context.changectx(self, changeid)
> +            return True
> +        except ValueError:
> +            return False
> diff -r cc905ee18449 -r bbb9a6fdfa6c tests/test-in.py
> --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
> +++ b/tests/test-in.py  Wed Apr 30 16:44:59 2014 +0200
> @@ -0,0 +1,23 @@
> +import common
> +import hglib
> +
> +class test_in(common.basetest):
> +    """
> +    test the 'in' keyword using both revision numbers or changeset ids.
> +    """
> +    def test_in_keyword(self):
> +        self.append('a', 'a')
> +        rev0, node0 = self.client.commit('first', addremove=True)
> +        self.append('a', 'a')
> +        rev1, node1 = self.client.commit('second')
> +
> +        self.assertIn(1, self.client)
> +        hash_1 = self.client.log(0)[0][1]
> +        self.assertIn(hash_1, self.client)
> +        self.assertNotIn(2, self.client)
> +        hash_2 = self.client.log(1)[0][1]
> +        self.assertIn(hash_2,self.client)
> +        hash_2 = 'deadbeef'
> +        self.assertNotIn(hash_2, self.client)

A new file for this test seems like a waste, you should probably
add it to test-context.py.

Patch

diff -r cc905ee18449 -r bbb9a6fdfa6c hglib/client.py
--- a/hglib/client.py	Sat Feb 01 15:30:18 2014 -0600
+++ b/hglib/client.py	Wed Apr 30 16:44:59 2014 +0200
@@ -1531,3 +1531,14 @@ 
 
     def __getitem__(self, changeid):
         return context.changectx(self, changeid)
+
+    def __contains__(self, changeid):
+        """
+        check if changeid, which can be either a local revision number or a
+        changeset id, matches a changeset in the client.
+        """
+        try:
+            context.changectx(self, changeid)
+            return True
+        except ValueError:
+            return False
diff -r cc905ee18449 -r bbb9a6fdfa6c tests/test-in.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-in.py	Wed Apr 30 16:44:59 2014 +0200
@@ -0,0 +1,23 @@ 
+import common
+import hglib
+
+class test_in(common.basetest):
+    """
+    test the 'in' keyword using both revision numbers or changeset ids.
+    """
+    def test_in_keyword(self):
+        self.append('a', 'a')
+        rev0, node0 = self.client.commit('first', addremove=True)
+        self.append('a', 'a')
+        rev1, node1 = self.client.commit('second')
+
+        self.assertIn(1, self.client)
+        hash_1 = self.client.log(0)[0][1]
+        self.assertIn(hash_1, self.client)
+        self.assertNotIn(2, self.client)
+        hash_2 = self.client.log(1)[0][1]
+        self.assertIn(hash_2,self.client)
+        hash_2 = 'deadbeef'
+        self.assertNotIn(hash_2, self.client)
+
+