[PATCH hglib] client: connect to repo if necessary when using "with" statement
Paul Tonelli
paul.tonelli at logilab.fr
Thu Jun 19 03:41:27 CDT 2014
# 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
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()
More information about the Mercurial-devel
mailing list