From 6252c0bd7378e5de72ec44f55aabc294bb0d6ed8 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Wed, 21 Nov 2012 06:07:01 +0100
Subject: [PATCH] Add tests for __repr__ in locking classes
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

β€œlocking.PipeCondition” and β€œlocking.SharedLock” define β€œ__repr__”,
which until now was not tested at all.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 test/ganeti.locking_unittest.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/test/ganeti.locking_unittest.py b/test/ganeti.locking_unittest.py
index 098a654b8..45c8f6d46 100755
--- a/test/ganeti.locking_unittest.py
+++ b/test/ganeti.locking_unittest.py
@@ -187,6 +187,10 @@ class TestPipeCondition(_ConditionTestCase):
     self.cond.acquire()
     self.assertEqual(len(self.cond._waiters), 3)
     self.assertEqual(self.cond._waiters, set(threads))
+
+    self.assertTrue(repr(self.cond).startswith("<"))
+    self.assertTrue("waiters=" in repr(self.cond))
+
     # This new thread can't acquire the lock, and thus call wait, before we
     # release it
     self._addThread(target=fn)
@@ -268,6 +272,9 @@ class TestSharedLock(_ThreadedTestCase):
     _ThreadedTestCase.setUp(self)
     self.sl = locking.SharedLock("TestSharedLock")
 
+    self.assertTrue(repr(self.sl).startswith("<"))
+    self.assertTrue("name=TestSharedLock" in repr(self.sl))
+
   def testSequenceAndOwnership(self):
     self.assertFalse(self.sl.is_owned())
     self.sl.acquire(shared=1)
-- 
GitLab