[PATCH hglib] client: connect to repo if necessary when using "with" statement

Augie Fackler raf at durin42.com
Wed Jul 2 15:26:46 CDT 2014


On Thu, Jun 19, 2014 at 10:41:27AM +0200, Paul Tonelli wrote:
> # HG changeset patch
> # User Paul Tonelli <paul.tonelli at logilab.fr>
> # Date 1402936146 -7200
> #      Mon Jun 16 18:29:06 2014 +0200
> # Node ID 3fb0aacdad91f7546c09384bc80158e64384ba9e
> # Parent  861583ceca0bea2a4f692b1e247af7a21c176dcc
> client: connect to repo if necessary when using "with" statement

patch LGTM, but I can't push to hglib. mpm?

>
> While the '__exit__' closes the connection to the server, the __enter__ method
> does not open it. Without this patch, a disconnected repo cannot be used with a
> context managed unless you explicitely call the "open" method.
>
> diff -r 861583ceca0b -r 3fb0aacdad91 hglib/client.py
> --- a/hglib/client.py	Wed May 21 15:19:19 2014 +0200
> +++ b/hglib/client.py	Mon Jun 16 18:29:06 2014 +0200
> @@ -61,6 +61,8 @@
>              self.open()
>
>      def __enter__(self):
> +        if self.server is None:
> +            self.open()
>          return self
>
>      def __exit__(self, exc_type, exc_val, exc_tb):
> diff -r 861583ceca0b -r 3fb0aacdad91 tests/test-hglib.py
> --- a/tests/test-hglib.py	Wed May 21 15:19:19 2014 +0200
> +++ b/tests/test-hglib.py	Mon Jun 16 18:29:06 2014 +0200
> @@ -12,3 +12,14 @@
>          common.basetest.setUp(self)
>          client2 = hglib.open()
>          self.client.close()
> +
> +    def test_context_manager_open(self):
> +        """
> +        make sure the "with" statement opens the connection when the client object
> +        is not already connected.
> +        """
> +        common.basetest.setUp(self)
> +        self.client.close()
> +        self.assertRaises(ValueError, self.client.log)
> +        with self.client:
> +            self.client.log()
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list